AMI perl daemon

Home » Asterisk Users » AMI perl daemon
Asterisk Users 5 Comments

Thank you, that makes sense but actually I would be invoking the script using the “externnotify” in voicemail.conf, similar to “externnotify = /var/lib/asterisk/scripts/notify.pl”
I assume “externnotify” cannot call the FastAGI server…correct?

On Mon, May 16, 2011 at 8:23 AM, Alex Balashovwrote:

> On 05/16/2011 08:19 AM, vip killa wrote:
>
> If the script were called each time an extension were dialed in a
>> dialplan for example, wouldn’t each new instance of the script need to
>> re-connect to AMI, run command, disconnect?
>>
>
> Well, yes, if you invoke a new instance of the script each time, that is
> what would happen. The desired approach is to have some means of
> communicating with the running daemon to indicate to it that it should
> originate a call, perhaps via a control socket/API.
>
> If your invocation is in the dial plan, the simplest thing to do would be
> to build a FastAGI server in Perl. This CPAN module can save some work:
>
>
>
> http://search.cpan.org/~jaywhy/Asterisk-FastAGI-0.02/lib/Asterisk/FastAGI.pm
>
> Then have that process either maintain a persistent AMI connection, or open
> a new one each time if you don’t feel like/don’t know how to implement the
> asynchronous approach.
>
> When you want to initiate a dial, just call:
>
> exten => …,x,AGI(agi://some.server.ip/your_script)
>
> Of course, you could also use call files if the script is executing on the
> same Asterisk server as the one on which the dials take place.
>
>
> —
> Alex Balashov – Principal
> Evariste Systems LLC
> 260 Peachtree Street NW
> Suite 2200
> Atlanta, GA 30303
> Tel: +1-678-954-0670
> Fax: +1-404-961-1892
> Web: http://www.evaristesys.com/
>
> —
> _____________________________________________________________________
> — Bandwidth and Colocation Provided by http://www.api-digital.com
> New to Asterisk? Join us for a live introductory webinar every Thurs:
> http://www.asterisk.org/hello
>
> asterisk-users mailing list
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-users
>

 

5 thoughts on - AMI perl daemon

  • Alex is pointing you in the right direction. You should want a single
    daemon running that then gets notified by the voicemail script, either
    through a FIFO, a socket, or by dropping a file in a watched
    directory.

    If you are going to write a daemon, I would suggest looking at :

    http://search.cpan.org/~greenbean/Asterisk-AMI-v0.2.5/

    It has integration with event loops and should work well for what you
    are doing. It also has some features for detecting disconnects and
    timeouts.

    On Mon, May 16, 2011 at 5:42 AM, Alex Balashov
    wrote:

  • Calling ->action() is going to wait for the originate to finish (even
    if you use ‘Async’). I think the default timeout for Originate is 60
    seconds or so before it fails.

    I would recommend reading up on:

    http://search.cpan.org/~mlehmann/AnyEvent-5.34/
    http://search.cpan.org/~mlehmann/AnyEvent-DBI-2.1/

    You could us a timer to periodically poll your database and do
    non-blocking originates (with async) with callbacks to catch the
    response, update the log, and do the delete.

  • could you suggest a better method where the perl-daemon
    stays persistently connected to asterisk’s AMI ?

  • Umm thank you…apparently AMI::Asterisk sucks because that code did
    everything i needed in one try. thanks again!