elastix
Information
Community
Developers
What We Sell
Forums
Addons
Download
Information
Community
Social Networks
For Developers
Manufacturer Support
Appliances
Training & Certification

Change call recording names and sort into folders

Share your tips and tricks with the community

Change call recording names and sort into folders

Postby jhansen858 » Fri Jul 23, 2010 5:06 pm

This post is to address one problem we have been having with elastix for a while now.

We get clients who do lots of call recording and they are constantly complaining that they cant find the recordings..Here is my solution to that problem...

After reading http://www.elastix.org/en/component/kun ... oblem.html I have come up with the following "dummy proof" procedure for this

1) make a symlink log into the console as root

ln -s /var/spool/asterisk/monitor /var/www/html/rec

2) make a script to do the sorting of the file names

nano /root/sortcalls.sh

#============PASTE THE BELOW CODE INTO THAT FILE===============
#!/bin/bash

TODAY=`date +'%Y-%m-%d'`

mkdir /var/spool/asterisk/monitor/$TODAY
mv /var/spool/asterisk/monitor/$TODAY* /var/spool/asterisk/monitor/$TODAY



#=============END OF THE FILE===================

3) make the file executable

chmod +x /root/sortcalls.sh

4) install the file into the crontab

crontab -e

*/5 * * * * /root/sortcalls.sh

5) log into the elastix admin page and goto "PBX -> PBX CONFIG -> General Settings

set the "Recording Location:" to "/var/spool/asterisk/monitor/"
set the "Run after record:" to ...

** the below is all one line... **

mv ^{MIXMON_DIR}/^{CALLFILENAME}.^{MIXMON_FORMAT} ^{MIXMON_DIR}/`/usr/bin/mysql -u root -peLaStIx.2oo7 -N -B -D asteriskcdrdb -e "SELECT calldate,'From:',src,'To:',dst,'' FROM cdr WHERE uniqueid = ^{UNIQUEID}"|sed -s s'/\s/_/ g'`.^{MIXMON_FORMAT}

** the above is all one line make sure it pastes in that way.... **

6) apply the settings and try recording some calls the calls in http://serverip/rec should look like

Index of /monitor
[ICO] Name Last modified Size Description
[DIR] Parent Directory -
[DIR] 2010-07-23/ 23-Jul-2010 14:47 -
[DIR] 2010-07-25/ 25-Jul-2010 13:00 -

and the recordings should be sorted into the folder name with the current date

7) if you need more help contact me http://www.ztelco.com and I would be happy to help...
jhansen858
Fresh Boarder
Fresh Boarder
 
Posts: 11
Joined: Fri Jul 23, 2010 3:47 pm
Karma: 1

Re:Change call recording names and sort into folders

Postby dicko » Sat Jul 24, 2010 4:30 pm

Welcome here jhansen858:

I think you might find the thread that ends with

http://www.elastix.org/component/kunena ... g=en#56095

will help you improve the "dummy proof" level of your solution, your cron job will as written, run as root and will thus create the directories with that ownership, perhaps a problem, also the job will break around midnight if there any new calls, your mkdir should really be mkdir -p or you will get an error after 00:10 each time it is called, I suggest that doing everything at the end of the call is a more elegant solution. Getting the date of the monitor file to set the directory something like
RECORDEDON=`date -r $FILENAME +'%Y-%m-%d'`
will allow you to rename all your existing recordings retro-actively if you extract the UNIQUEID from the file name , (perhaps something like sed "s/.*\-\([.0-9]*\)\.[a-zA-Z]*$/\1/" )

You should consider using hardlinks (ln) not mv because if you change the original file's name some common interfaces will not work as expected.

as a suggestion (I cared to deconstruct your post, which wasn't too hard as I recognize most of it, seeing as I wrote it ;) , I added a few "value added" suggestions of my own ) I offer a rough and ready "one size fits all" alternative, be careful almost no error checking:

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
#!/bin/sh
# the next two lines will make the directories, it preempts the need for your cron job,season to suit, it also puts the recordings where they belong temporally
DATE=`date -r $2$1 +'%Y/%m-%b/%d-%a'`
mkdir -p $2$DATE
# the next line  extract and stores the UNIQUEID, it is only used once so for efficiency you can put it inline
UNIQUEID=`echo $1 |sed "s/.*\-\([.0-9]*\)\.[a-zA-Z]*$/\1/"`
# the next line  extracts the format and is left here so any changes one made previously to the format will still be covered when run retrospecively. it also is only used once.
FILETYPE=`echo $1 |sed "s/.*\-[.0-9]*\(\.[a-zA-Z]*$\)/\1/"`
# the next line does the grunt work
NEWFILE=`/usr/bin/mysql -u root -peLaStIx.2oo7 -N -B -D asteriskcdrdb -e "SELECT calldate,'From:',clid,'To:',dst,'' FROM cdr WHERE uniqueid = $UNIQUEID LIMIT 1"|sed -e 's/\s/_/g' -e "s/_$/$FILETYPE/" -e "s/["<>]//g"`
# the next line saves you duplicating effort and overwriting good shit
if [ ! -f $2$DATE/$NEWFILE ] ;then ln $2$1 $2$DATE/$NEWFILE ;fi
# there is no nextline until you add it or insert previous lines perhaps to
# use sox to  normalize levels if you use dahdi and haven't bothered to set it up right
# use sox to strip off the ringing tone , subtract calltime from answertime and start with that offset,and then the silence at either end, (watch out for the wink at the end of dahdi calls and remove the last 500 milliseconds)
# use lame to convert to mp3 to save space,and id2tag appropriately with extension datetime etc.
# use mail and mutt to email to the users email or cellphone, parse /etc/asterisk/voicemail.conf to get the address
# the world is your oyster . . .
GeSHi ©


You can call it either from the general settings page with

/var/lib/asterisk/bin/scriptname.sh ^${CALLFILENAME}.^{MIXMON_FORMAT} ^{MIXMON_DIR}

or from a cron script if that floats your boat, or from bash perhaps to process/reprocess all the existing files, something like:

for i in `ls /var/spool/asterisk/monitor/*.wav` ; do /path/to/script $i /var/spool/asterisk/monitor/;done

A couple of caveats here, it will create the directories with the ownership of the user so do a quick

chown -r asterisk:asterisk /var/spool/asterisk/monitor if run as root from bash

it rightly belongs in /var/lib/asterisk/bin.

regards

dicko

p.s.

I believe that unless you have changed the default http configuration , directory listings in Elastix will be disallowed, for very good reasons, you will need to add a wrapper index. in the sym linked directory you use that will hopefully render the files visible/usable/downloadable, there are examples both here in these fora and out on the tubes that will help you there. Possibly grab a copy of "enCode eXplorer" from:

http://encode-explorer.siineiolekala.net/

and stick the index.php file (after editing it to suit) in /var/www/html/monitor and/or /var/www/html/monitor/2010 depending on what you care to soft link.
There are other solutions!!
dicko
Platinum Boarder
Platinum Boarder
 
Posts: 4099
Joined: Fri Oct 24, 2008 12:39 pm
Location: Not available
Karma: 156

Re:Change call recording names and sort into folders

Postby jhansen858 » Mon Jul 26, 2010 12:38 pm

Ahh some nice points to consider..

I would like to point out now that I have your ear... the difficulty in finding recordings is in my opinion the biggest shortcoming of the entire elastix distro... I have had every single client that we have installed it on complain about that one feature...

I think one way to fix this..(that I have tried to figure out how to add but couldn't figure it out yet) woud be to put a link to the recordings of the call next to the call on the CDR reports page(between status and duration would be great)... The end users can always seem to find the call in the cdr report but you try and find that same call under the monitor section they for some reason frequently cant find them.. This is the number 1 tech support call that we get when deploying the elastix distro for anyone...



I do thank you for the great distro I wish I knew more so I could add the link as I'm suggesting my self and not beg you guys to include it in your next update ;)
jhansen858
Fresh Boarder
Fresh Boarder
 
Posts: 11
Joined: Fri Jul 23, 2010 3:47 pm
Karma: 1

Re:Change call recording names and sort into folders

Postby dicko » Mon Jul 26, 2010 1:47 pm

There is another, and some find better "user portal" called "The Asterisk Recordings Interface" It just does the calls handling (forward email content etc. ) VMX if enabledd for that extension and voicemails and monitor files though.

it might be at

http:///recordings

but it might not be installed, see other posts concerning getting it onto your elastix box,or just do a version upgrade of FreePBX and it usually magically appears
There are other solutions!!
dicko
Platinum Boarder
Platinum Boarder
 
Posts: 4099
Joined: Fri Oct 24, 2008 12:39 pm
Location: Not available
Karma: 156

Re:Change call recording names and sort into folders

Postby doncipo » Wed Aug 18, 2010 4:22 am

Please someone publish here a complete howto on this issue.
Thanks in advance !
doncipo
Fresh Boarder
Fresh Boarder
 
Posts: 18
Joined: Thu Jun 03, 2010 2:46 am
Karma: 1

Re: Change call recording names and sort into folders

Postby azulay7 » Sun Jan 09, 2011 5:47 am

It seemes to work fins.
but in this 2 cases it doesn't.
1. when commiting calls between extensions. (thourgh trunk it works well).
2. when call monitor is "on demand"("always" works well).

thank you on advance.
azulay7
Fresh Boarder
Fresh Boarder
 
Posts: 1
Joined: Sun Jan 09, 2011 4:53 am
Karma: 0

Re: Change call recording names and sort into folders

Postby Gelevera » Fri Feb 11, 2011 2:03 pm

Aca esta..


Gelevera escribió:
la verdad que el que busca encuentra.
aca esta lo que necesitaba

grabar los archivos ordenados en sub-carpetas - limite de # de nombres en particiones ext3


En Elastix no viene por default.
que raro que a la hora de asignar donde grabar los de asterisk no se les haya ocurrido este problema de la ext3..
Podria agregarse a Elastix y también una opción para borrar las muy antiguas.




azulay7 escribió:
It seemes to work fins.
but in this 2 cases it doesn't.
1. when commiting calls between extensions. (thourgh trunk it works well).
2. when call monitor is "on demand"("always" works well).


las 2 extensiones tienen que tener habilitado

Record Incoming "allways"
Record Outgoing "allways"

o sinó

como-habilitar-la-grabacion-de-llamadas
Karma Image + !!
User avatar
Gelevera
Senior Boarder
Senior Boarder
 
Posts: 112
Joined: Sat Aug 21, 2010 8:28 pm
Karma: 4

Re: Change call recording names and sort into folders

Postby Gelevera » Wed Feb 16, 2011 9:28 am

hi! I need to save my recordings in sub-folders i try this

[quote="Fozzy"]

1. Create a script in /var/lib/asterisk/bin/ called archiver

nano /var/lib/asterisk/bin/archiver

2. in the archiver I have the following:


#!/bin/bash
ARCHDIR="`date +%Y`/`date +%m`/`date +%d`/"
mkdir -p /var/spool/asterisk/monitor/$ARCHDIR
mv /var/spool/asterisk/monitor/$1 /var/spool/asterisk/monitor/$ARCHDIR



3. chmod 777 /var/lib/asterisk/bin/archiver

4. chown -R asterisk:asterisk /var/lib/asterisk/bin/archiver

(If you don't then nothing will happen and you will sit scratching your head)



5. Now all we need to do is add the following line to FreePBX, General Settings,
"Run after recording":

/var/lib/asterisk/bin/archiver ^{CALLFILENAME}.^{MIXMON_FORMAT}

And there you go! You should then see your files moved to folders like this for example.

/var/spool/asterisk/monitor/2010/07/20/XXXX-00000.000.wav



and works great, but now i didn´t see my recordings in web interface 'monitoring'..

any clue?
Karma Image + !!
User avatar
Gelevera
Senior Boarder
Senior Boarder
 
Posts: 112
Joined: Sat Aug 21, 2010 8:28 pm
Karma: 4

Re: Change call recording names and sort into folders

Postby dicko » Wed Feb 16, 2011 10:49 am

The Original ARI at

http:///recordings

is recursive and will work (five levels deep, I believe) , the Elastix one is not and won't (unfortunately it is also still quite broken, as azulay7 has discovered :) )

If you read the whole underlying thread you will see I suggested

ln /var/spool/asterisk/monitor/$1 /var/spool/asterisk/monitor/$ARCHDIR

They will both work then with duplicates in ARI

how about

mkdir -p /var/spool/asterisk/otherdirectory/$ARCHDIR
ln /var/spool/asterisk/monitor/$1 /var/spool/asterisk/otherdirectory/$ARCHDIR


?
There are other solutions!!
dicko
Platinum Boarder
Platinum Boarder
 
Posts: 4099
Joined: Fri Oct 24, 2008 12:39 pm
Location: Not available
Karma: 156

Re: Change call recording names and sort into folders

Postby Gelevera » Thu Feb 17, 2011 2:23 pm

[quote="dicko"]The Original ARI at

http:///recordings

is recursive and will work (five levels deep, I believe) , the Elastix one is not and won't (unfortunately it is also still quite broken, as azulay7 has discovered



i found this

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)

    global $arrConf;
    global $arrConfModule;

    $arrConfModule['module_name']       = 'monitoring2';
    $arrConfModule['templates_dir']     = 'themes';
    $arrConfModule['records_dir']       = '/var/spool/asterisk/monitor/';
    $arrConfModule['dsn_conn_database'] = ''; // A ser leído de /etc/amportal.conf
?>

GeSHi ©



in /var/www/html/modules/monitoring/configs/default.conf.php

I am interested in this line:

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
$arrConfModule['records_dir']       = '/var/spool/asterisk/monitor/';
GeSHi ©


How i can do to tell it to search recursively?
Karma Image + !!
User avatar
Gelevera
Senior Boarder
Senior Boarder
 
Posts: 112
Joined: Sat Aug 21, 2010 8:28 pm
Karma: 4
Top

Re: Change call recording names and sort into folders

Postby dicko » Thu Feb 17, 2011 3:09 pm

:) :)

By rewriting the module from scratch?
There are other solutions!!
dicko
Platinum Boarder
Platinum Boarder
 
Posts: 4099
Joined: Fri Oct 24, 2008 12:39 pm
Location: Not available
Karma: 156

Re:Change call recording names and sort into folders

Postby franklin » Thu Mar 10, 2011 11:35 pm

dicko. Have a 1.6 SIP only box, FreePBX 2.7. customer has a small outbound call center. Wants to attach recording of call to his customer file. If I upload each .wav or mp3 to his FTP with the number called and the date and time he can take it from there. Have read all posts from searching /var/spool/asterisk/monitor as you suggest. Your code below seems like the right start. It also seems that instead of "use mail and mutt to email to the users email or cellphone, parse /etc/asterisk/voicemail.conf to get the address" I want to set up an FTP upload at this point. Can you comment, and tell me how to set up the FTP upload? Thanks.

Code:

#!/bin/sh
# the next two lines will make the directories, it preempts the need for your cron job,season to suit, it also puts the recordings where they belong temporally
DATE=`date -r $2$1 +'%Y/%m-%b/%d-%a'`
mkdir -p $2$DATE
# the next line extract and stores the UNIQUEID, it is only used once so for efficiency you can put it inline
UNIQUEID=`echo $1 |sed "s/.*\-\([.0-9]*\)\.[a-zA-Z]*$/\1/"`
# the next line extracts the format and is left here so any changes one made previously to the format will still be covered when run retrospecively. it also is only used once.
FILETYPE=`echo $1 |sed "s/.*\-[.0-9]*\(\.[a-zA-Z]*$\)/\1/"`
# the next line does the grunt work
NEWFILE=`/usr/bin/mysql -u root -peLaStIx.2oo7 -N -B -D asteriskcdrdb -e "SELECT calldate,'From:',clid,'To:',dst,'' FROM cdr WHERE uniqueid = $UNIQUEID LIMIT 1"|sed -e 's/\s/_/g' -e "s/_$/$FILETYPE/" -e "s/["<>]//g"`
# the next line saves you duplicating effort and overwriting good shit
if [ ! -f $2$DATE/$NEWFILE ] ;then ln $2$1 $2$DATE/$NEWFILE ;fi
# there is no nextline until you add it or insert previous lines perhaps to
# use sox to normalize levels if you use dahdi and haven't bothered to set it up right
# use sox to strip off the ringing tone , subtract calltime from answertime and start with that offset,and then the silence at either end, (watch out for the wink at the end of dahdi calls and remove the last 500 milliseconds)
# use lame to convert to mp3 to save space,and id2tag appropriately with extension datetime etc.
# use mail and mutt to email to the users email or cellphone, parse /etc/asterisk/voicemail.conf to get the address
# the world is your oyster . . .
User avatar
franklin
Senior Boarder
Senior Boarder
 
Posts: 254
Joined: Fri Oct 22, 2010 12:23 pm
Karma: 7

Re:Change call recording names and sort into folders

Postby dicko » Thu Mar 10, 2011 11:47 pm

ftp transfers are somewhat hard to script, you should probably wrap the session with 'expect'

basically a recipe I offer:

yum -y install expect;while ! false ; do man expect;man autoexpect;read -p "get it yet ?" ;done

then wait for brain to kick in . . . . :) :)

regards

dicko
There are other solutions!!
dicko
Platinum Boarder
Platinum Boarder
 
Posts: 4099
Joined: Fri Oct 24, 2008 12:39 pm
Location: Not available
Karma: 156

Re:Change call recording names and sort into folders

Postby franklin » Fri Mar 11, 2011 12:41 am

Let me start at the top.

When I run: [root@pbx ~]# !/bin/sh
I get this:
-bash: !/bin/sh: event not found

Read up on the shebang at http://en.wikipedia.org/wiki/Shebang_%28Unix%29

If I type root@pbx ~]# #!/bin/sh
The command prompt comes back. I entered

[root@pbx ~]# #!/bin/sh
[root@pbx ~]# DATE=`date -r $2$1 +'%Y/%m-%b/%d-%a'`
date: +%Y/%m-%b/%d-%a: No such file or directory
[root@pbx ~]#

I don't want to go too far like I did with Avanfax(which I am making progress on) and bugger things.

If there is "No such file or directory" I seems to me I would want to mkdir -p $2$DATE first, but that is your second line.

Please advise. Thanks.
User avatar
franklin
Senior Boarder
Senior Boarder
 
Posts: 254
Joined: Fri Oct 22, 2010 12:23 pm
Karma: 7

Re:Change call recording names and sort into folders

Postby dicko » Fri Mar 11, 2011 12:57 am

Don't try run the first line of a script in a shell, it is an artifact to let bash know what interpreter you want to use for the rest of the script

/bin/bash is a regular bash shell /bin/sh is a smaller shell without some "conveniences"
#!/usr/bin/perl says to use perl as the interpreter etc.

That the first character is # is supposed to allow the same script to run as a windows bash script it will be interpreted as a comment., yeah right !! Thus the firstline is spurious in a shell.

the $1 $2 etc. are interpreted as the argunents to the script, to use them directly in bash replace them with the literal string that you passed. e.g. $2$1 would be replaced by /var/spool/asterisk/monitor/ which is the perhaps the first argument concatenated with which would be the second argument. i,e $2$1 is seen as /var/spool/asterisk/monitor/

respectfully, you need a few iterations around a good bash script tutorial.

You will however get there I'm sure, I have previously noticed your stubbornness :)

regards

dicko
There are other solutions!!
dicko
Platinum Boarder
Platinum Boarder
 
Posts: 4099
Joined: Fri Oct 24, 2008 12:39 pm
Location: Not available
Karma: 156

Next

Return to Tips and Tricks

Who is online

Users browsing this forum: No registered users and 1 guest