AMI disconnects

Home » Asterisk Users » AMI disconnects
Asterisk Users 2 Comments

On 12-05-03 01:45 PM, Mike Diehl wrote:
> Hi all.
>
> I’ve got a perl script that connects to Asterisk’s management interface using Asterisk::AMI. So far, its proven to be very useful.
>
> I’m hoping to use this to detect and respond to asterisk restarts and sip reloads.
>
> However, my script gets disconnected quite frequently, causing false alarms in my monitoring.
>
> Here’s what the code looks like:
>
> =========================================================
> while ($more) {
> $change = 0;
>
> while (!$ami->connected(5)) {
> Event::Shutdown(Event=>”Shutdown”);
> send_to_subscribers( {“Event” => “Shutdown”, “customer_id” => 0}, “Connection to Asterisk lost on $server”);
>
> $change++;
> sleep(1);
>
> ami_connect();
>
> next;
> }
>
> $watchdog = 10;
> while ($ami->get_event(1)&& $watchdog–) {
> if ($watchdog< 2) { print "Watchdog timer too short.n"; }
> $change++;
> }
>
> Do other stuff from here.
>
> if ($change == 0) {
> sleep(2);
> }
>
> }
>
> exit 1;
> =========================================================
>
> When this scrip disconnects, the asterisk console simply says that the manager logged off from 127.0.0.1 and got logged back on. No reall
> error indication given.
>
> Any suggestions on how to make this script keep it’s connection?
>
This belongs on the asterisk-users list. However, something like StarPY
(Python) has this functionality by using the Twisted. It simply
monitors events on the AMI, and if the connect break, can be setup to
re-connect.

2 thoughts on - AMI disconnects

  • Heh, apparently this is the asterisk-user list. Sorry, dealing with a
    new mail client and misread my folder labels.

  • I posted this to the asterisk-users list… Did I miss something?

    My code doesn’t have any problems getting re-connected in a timely fashion.
    The issue is that it’s getting disconnected for no apparent reason!