Trigger Asterisk After Data Inserted In Mysql

Home » Asterisk Users » Trigger Asterisk After Data Inserted In Mysql
Asterisk Users 6 Comments

Hi all,

I would like to know, is there a way to trigger Asterisk after data inserted into mysql DB? Like here what I’m trying to do, when the new data inserted into MySQL DB, it sends the request to Asterisk along with the new data (that is inserted in DB) for making outbound call i.e. Realtime.

Currently I’ve set a cron job that execute my script every 30 seconds and checks for a new data in DB. If new data is inserted in 30 seconds that script will run and sends the data to Asterisk for making calls. (This is the case which I’m thinking to avoid)

Please advise.

6 thoughts on - Trigger Asterisk After Data Inserted In Mysql

  • It looks like the answer is yes.

    http://crazytechthoughts.blogspot.ca/2011/12/call-external-program-from-mysql.html

    From the page, here is code to execute a UDF library and call a shell. Clearly there would be a heavy penalty to launching a shell so you would want to carefully evaluate the frequency this is executed on your system.
    |
    DELIMITER @@|
    |CREATE| |TRIGGER| |Test_Trigger |
    |AFTER| |INSERT| |ON| |MyTable |
    |FOR| |EACH ROW |
    |BEGIN|
    |||DECLARE| |cmd ||CHAR||(255);|
    |||DECLARE| |result ||int||(10);|
    |||SET| |cmd=CONCAT(||’sudo /home/sarbac/hello_world ‘||,||’Sarbajit’||);|
    |||SET| |result = sys_exec(cmd);|
    |END||;|
    |@@|
    |DELIMITER ;

    |
    -dbc

  • David

    The way we do this is to have a trigger insert into a batch table. This table can be polled from a secondary process. That process/service is responsible for monitoring, working and cleanup. This allows for you to poll a highly optimized table without taking the db performance hit from larger tables that will grow over time. We process millions of cdr and process records a day this way. It also allows you balanced process loads across multiple servers. This can be extremely important on systems that are more heavily loaded. It also allows you to remove process load and latencies from the database servers.

    Thanks

    Bryant Zimmerman (ZK Tech Inc.)
    616-855-1030 Ext. 2003

    ————————————–

  • I thought the answer was 42.

    If you’re going to top-post (which is against the rules on this list), the least you can do is phrase your answers in a way that illustrates the question.

    Thanks!

  • It’s understandable that many are unaware of the rules, since it took some hunting for me to find them again. They aren’t mentioned at all on any of the mailman pages at lists.digium.com. The rules can be found here:

    http://www.asterisk.org/community/rules

    Anyway, there are many who like to top-post, and I’m not interested in a holy war.

    I just wanted to point out that if you want to top-post, it may be worthwhile to consider ways to minimize the impact–like phrasing the answer so that the question is immediately apparent, and you don’t force your readers to scroll down, possibly dodging signatures, disclaimers, pasted logs, and dragons, just to get to the question being answered.