There was a post today on the Asterisk Users mailing list about needing a simple way to monitor if your Asterisk lines are working ok.
As it turns out I had such a script in my little store of doom. So just in case the Asterisk Users post doesn’t get archived here it is:
<pre>
<?
///////////////////////////////////////////////////
// This is a quick script that allows the external
// monitoring to check that all is ok.
//
// Gareth#NetworksAreMadeOfString.co.uk
///////////////////////////////////////////////////
$s = stream_socket_client('tcp://127.0.0.1:5038',$e,$es,5);
if (!$s)
{
die('<pre>Error: '.$es.'</pre>');
}
stream_set_timeout($s,2,0);
fwrite($s,"Action: Command\r\n");
fwrite($s,"Command: zap show status\r\n");
fwrite($s,"\r\n");
$Response="";
while(!strstr($Response,'END COMMAND'))
{
$Chunk = fread($s,512);
$Response .= $Chunk;
}
fclose($s);
if(stristr($Response,"OK") === FALSE)
{
print("Issue detected");
print("-----");
print($Response);
}
else
{
print("Zap Lines OK");
}
?>
</pre>
Pretty simple I think you’ll agree, hope it helps someone out who doesn’t feel up to installing Nagios just to make sure the outside line is working!