[asterisk-users] Lookup ${EXTEN} in database, update context/route if found... AGI?

Tim Nelson tnelson at rockbochs.com
Thu Jun 3 09:28:07 CDT 2010


----- "Doug Lytle" <support at drdos.info> wrote:
> I use the mysql add-on, I'd create a subroutine that gets called at
> dial 
> time.  As an example, I set outbound caller-id with the below 
> subroutine.  You would use ${EXTEN} for the lookup and decide the
> route 
> to take on the results.
> 
> [set_callerid]
> 
> exten => s,1,MYSQL(Connect connid 192.168.103.15 username 'password'
> did)
> exten => s,n,GosubIf($["${MYSQL_STATUS}" = "-1"]?mysql_failed,s,6)
> exten => s,n,MYSQL(Query resultid ${connid} SELECT setcid FROM
> Corporate 
> WHERE number = ${CALLERID(number)})
> exten => s,n,MYSQL(Fetch fetchid ${resultid} set.callerid)
> exten => s,n,MYSQL(Disconnect ${connid})
> exten => s,n,MYSQL(Clear ${resultid})
> exten => s,n,GotoIf($["${set.callerid}" != ""]?8:10)
> exten => s,n,Set(CALLERID(number)=${set.callerid})
> exten => s,n,Return()
> exten => s,n,Set(CALLERID(number)=269xxxxxxx)
> exten => s,n,Return()
> 

Thank you for the example. I'm using something very similar to this now, looking up the destination ${EXTEN}, and using GotoIf if the number of results from the query are > 0. It seems to be working quite well.

I do have a few additional questions however:

-How reliable is the MYSQL application?
-In the event of a failed database query (load too high), what happens to the call?
-Also, what about slow queries? If a query takes a few seconds to complete, does the call wait for the query to complete or are there timeouts for the query that could result in dropped calls? 
-Are there any problems with concurrency? What if there are 50 simultaneous calls that need to perform this database lookup? Providing the MySQL server is fine with that number of simultaneous queries, will the MYSQL app and/or Asterisk handle it gracefully?
-Does it make sense to open, disconnect, and clear every connection for every call? Is there a way to have a persistent connection for better performance?

As I'm sure you can tell, I've been using non-database driven dialplans thus far and I'm a bit nervous adding another 'link' in the chain that could cause problems. All thoughts appreciated!

--Tim



More information about the asterisk-users mailing list