tags:

views:

22

answers:

1

In one of our very simple custom contexts I would like to add some database logging outside of the built-in cdr app. I have something like the following:

[inbound-custom]
exten => _X.,1,MixMonitor(/mnt/temp/inbound-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}-${CALLERID(num)}-${EXTEN}-${UNIQUEID}.wav)
exten => _X.,n,MYSQL(Connect connid mysqlip cdr_logger mysqlpw asteriskcdrdb)
exten => _X.,n,MYSQL(Query resultid ${connid} INSERT INTO `call_recordings` (`asterisk_uniqueid`,`clid`,`filename`,`context`) VALUES (${UNIQUEID},${CALLERID(num)},inbound-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}-${CALLERID(num)}-${EXTEN}-${UNIQUEID}.wav,"inbound"))
exten => _X.,n,MYSQL(Clear ${resultid}) 
exten => _X.,n,MYSQL(Disconnect ${connid}) 
exten => _X.,n,Dial(SIP/cs1000/${EXTEN})
exten => _X.,n,Hangup()

This seems to work fine for the most part, however if someone hangs up before the context reaches the MYSQL(clear...) line there is a zombie connection left open on the MySQL server. On the voip info wiki there is mention of doing connection clean up in the h extension for a context, but there are no samples of this. I tried the following to no avail:

[inbound-custom]
exten => _X.,1,MixMonitor(/mnt/temp/inbound-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}-${CALLERID(num)}-${EXTEN}-${UNIQUEID}.wav)
exten => _X.,n,MYSQL(Connect connid mysqlip cdr_logger mysqlpw asteriskcdrdb)
exten => _X.,n,MYSQL(Query resultid ${connid} INSERT INTO `call_recordings` (`asterisk_uniqueid`,`clid`,`filename`,`context`) VALUES (${UNIQUEID},${CALLERID(num)},inbound-${STRFTIME(${EPOCH},,%Y%m%d-%H%M%S)}-${CALLERID(num)}-${EXTEN}-${UNIQUEID}.wav,"inbound"))
exten => _X.,n,Dial(SIP/cs1000/${EXTEN})
exten => _X.,n,Hangup()

exten => h,1,MYSQL(Clear ${resultid}) 
exten => h,n,MYSQL(Disconnect ${connid}) 

I imagine I'm doing something wrong in there but I cant quite tell what it is.

A: 

I was able to get this mostly working however clear seems to love throwing errors on inserts and the documentation is minimal at best. Gave up on using MYSQL() and opted to use system() to send the insert statement to a waiting python daemon.

HurnsMobile