Change call recording names and sort into folders

Discussion in 'General' started by jhansen858, Jul 23, 2010.

  1. jhansen858

    Joined:
    Jul 23, 2010
    Messages:
    11
    Likes Received:
    0
    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...
     
  2. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    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:
    #!/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 . . . 
    
    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.<php|html|whatyouaddedtomakeacceptable> 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.
     
  3. jhansen858

    Joined:
    Jul 23, 2010
    Messages:
    11
    Likes Received:
    0
    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 ;)
     
  4. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    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://<IP>/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
     
  5. doncipo

    Joined:
    Jun 3, 2010
    Messages:
    18
    Likes Received:
    0
    Please someone publish here a complete howto on this issue.
    Thanks in advance !
     
  6. azulay7

    Joined:
    Jan 9, 2011
    Messages:
    1
    Likes Received:
    0
    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.
     
  7. Gelevera

    Joined:
    Aug 22, 2010
    Messages:
    143
    Likes Received:
    0
    Aca esta..


    Gelevera escribió:


    azulay7 escribió:
    las 2 extensiones tienen que tener habilitado

    Record Incoming "allways"
    Record Outgoing "allways"

    o sinó

    como-habilitar-la-grabacion-de-llamadas
     
  8. Gelevera

    Joined:
    Aug 22, 2010
    Messages:
    143
    Likes Received:
    0
    hi! I need to save my recordings in sub-folders i try this

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

    any clue?
     
  9. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    The Original ARI at

    http://<ip>/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


    ?
     
  10. Gelevera

    Joined:
    Aug 22, 2010
    Messages:
    143
    Likes Received:
    0

    i found this

    Code:
    
        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
    ?>
    
    

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

    I am interested in this line:

    Code:
    $arrConfModule['records_dir']       = '/var/spool/asterisk/monitor/';
    
    How i can do to tell it to search recursively?
     
  11. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    :) :)

    By rewriting the module from scratch?
     
  12. franklin

    Joined:
    Oct 22, 2010
    Messages:
    254
    Likes Received:
    0
    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 . . .
     
  13. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    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
     
  14. franklin

    Joined:
    Oct 22, 2010
    Messages:
    254
    Likes Received:
    0
    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.
     
  15. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    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 <file> which would be the second argument. i,e $2$1 is seen as /var/spool/asterisk/monitor/<file>

    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
     
  16. franklin

    Joined:
    Oct 22, 2010
    Messages:
    254
    Likes Received:
    0
    I have the free linux tutorial that linux.org has been offering -- GNU/Linux Basic. Been meaning to go through it. Perhaps tomorrow is the day to set aside. Cobbling things together... I saw a sign at a church tonight, it said something like "Being almost there is like being completely lost."

    I think this thing is going to blow up if you answer. d4K!
     
  17. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    Being almost there is often one step away from actually being there, don't be confused by those who believe they know what god thinks, they are almost always wrong, just ask her, she is on your side not theirs, they just want your money ;)
     
  18. franklin

    Joined:
    Oct 22, 2010
    Messages:
    254
    Likes Received:
    0
    Ha! I ruined a friendship with a Catholic once by suggesting God was a She!

    Maybe this thing will self destruct at 4001... I'm reading. Just got through the history of Linux. 28/255... onward ye FSF soldiers.
     
  19. dicko

    Joined:
    Oct 24, 2008
    Messages:
    4,099
    Likes Received:
    0
    Having been brought up as one, I can assure you that most Catholics are not catholic in any way. but thats another story and we shouldn't talk religion or politics here or we will be shot down in flames by a hire (sic) power.
     
  20. franklin

    Joined:
    Oct 22, 2010
    Messages:
    254
    Likes Received:
    0
    onward with the reading. Hard to slow down and do it. But to get through my bungled Avant, get Fail installed correctly, this, that, the next thing, better get right with the Penguin, and God...
     

Share This Page