[asterisk-users] AMI disconnects

Paul Belanger paul.belanger at polybeacon.com
Thu May 3 14:47:09 CDT 2012


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.

-- 
Paul Belanger | PolyBeacon, Inc.
Jabber: paul.belanger at polybeacon.com | IRC: pabelanger (Freenode) |
Github: https://github.com/pabelanger | Twitter: 
https://twitter.com/pabelanger



More information about the asterisk-users mailing list