2

I am a novice in Asterisk and i want to record my calls to MYSQL database. My Astersik is running on Ubuntu. I am successfully recording the calls but I want the recorded files to be stored in MYSQL database instead of Asterisk's Monitor folder. How can i configure that? i have successfully setup MYSQL database, my sip users are there, i am successfully configured the CDR but i want to record calls to MySQL database? who can help me please?

[MySQL]----- odbcinst.ini
Description = ODBC for MySQL
Driver      = /usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
Setup       = /usr/lib/x86_64-linux-gnu/odbc/libodbcmyS.so
FileUsage   = 1
UsageCount  = 4

[asterisk-connector]--- odbc.ini
Description = MySQL connection to 'asterisk' database
Driver      = MySQL
Database    = asterisk
Server      = localhost
UserName    = asterisk
Password    = XXXX
Port        = 3306
Socket      = /var/run/mysqld/mysqld.sock

[asterisk] -----------res_odbc
enabled => yes
dsn => asterisk-connector
username => asterisk
password => XXXX
pooling => no
limit => 1
pre-connect => yes

[general]   -------------res_config_mysql.conf
dbhost = 127.0.0.1
dbname = asterisk
dbuser = asterisk
dbpass = XXXX
dbport = 3306
dbsock = /tmp/mysql.sock
dbcharset = latin1
requirements=warn
Jack Smart
  • 21
  • 1
  • 4

1 Answers1

0

You're going to need to create a custom script which performs this action for you, there's not a built-in way to do this with Asterisk.

What you could do is create a hangup action in your dialplan which executes a script which stores the file in a database.

Or, as recommended by arheops -- put a script command in your MixMonitor() call.

I've provided a short example below showing how that would work.

[your_context]

exten => s,1,Noop(Your regular extension)
same =>    n,MixMonitor(myrecording.ulaw,,/path/to/insert_recording.sh)
same =>    n,Dial([...])
same =>    n,Hangup()

exten => h,1,Noop(Actions on hangup)
same =>    n,System(/not/recommended/insert_recording.sh)

This will record the file for you and then execute the shell script referenced, /path/to/insert_recording.sh

The code required to store files in a database is left as an exercise for the person asking, as it's not really specific to Asterisk.

You may also be interested in the ${MONITOR_EXEC} variable which is typically used for executing a command to mix two channels of audio together in a custom fashion. You can learn more about it from the monitor documentation in the Asterisk docs.

Lastly -- depending on your situation, and the scale at which you expect -- storing files in a database may or may not be wise. Personally, I tend toward storing just a pointer to a file path in a database record. You might be able to learn a little more about storing blobs from this stackexchange question.

You could use the same paradigm of executing a script on hangup which inserts information into a database.

edit: Added mixmonitor script per arheops.

Community
  • 1
  • 1
dougBTV
  • 1,883
  • 1
  • 15
  • 18
  • 1
    Please not use this way. NEVER. It can result asterisk crash or file not fully stored. Use mixmonitor script or external script based on CDR. – arheops Mar 10 '15 at 03:33
  • thank you dear dougBTV, lot of essentials ))) but how can i get the shell script? could you give some directions? – Jack Smart Mar 10 '15 at 11:44
  • @arheops -- can you further explain this? The hangup extension has been vastly improved since Asterisk 1.4ish. I have a whole pool of things that happen on hangup, including this. And I have yet to see a crash. Granted, my script for moving / changing files waits until it hasn't been touched for 90 seconds. Additionally I edited my answer to reflect this. I'd love to open a conversation with you and earn your upvote. – dougBTV Mar 10 '15 at 12:25
  • @JackSmart -- no problem. I'll point you to this PHP example, but, honestly I still wouldn't recommend it unless there's a strong reason to store it in the database, otherwise... Store it on a storage device (like a NAS). http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx (just ignore the part about uploading, just use the storage features) – dougBTV Mar 10 '15 at 12:27
  • 2
    hangup extension not designed for long tasks. if tasks are more then 5 sec, behavour become unpredictable when alot of hangup issued. it is NOT recommended do it for long task. Just record event in db(like which file to process etc) and do it in background thread by external script. – arheops Mar 11 '15 at 06:24
  • @arheops thanks for the wisdom regarding it. I have changed the answer to reflect this input, and do appreciate the explanation. – dougBTV Mar 11 '15 at 14:51