[asterisk-users] AMI disconnects
Mike Diehl
mdiehl at diehlnet.com
Thu May 3 12:45:57 CDT 2012
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?
TIA.
--
Take care and have fun,
Mike Diehl.
More information about the asterisk-users
mailing list