I piped the output to a text file. I did get a "Array
(
)" I have noticed there is no closing php tag so I closed it but it did not make a difference.
[codes]#!/usr/local/bin/php
<?php
define('EMAIL' , 'kieranmullen@gmail.com');
define('IGNORE-GENERIC' , true);
$errors = array();
//Start cehcking Zaptel
$line = shell_exec('asterisk -rx "zap show status"');
$lines = explode("\n",$line);
array_shift($lines); //Remove the headers that are the first line.
array_pop($lines); //The last line is junk.
foreach ( $lines as $x ) {
$x = preg_replace('¦[ ][ ]+¦',"\t",$x);
list($board,$alarm,$irq) = explode("\t",$x);
if ( $alarm != "OK" ) {
if ( !IGNORE-GENERIC ¦¦ ( strpos($board,'Generic') === false ))
$errors[] = "Zaptel Card $board ($irq) is alarm $alarm";
}
}
//Start checking IAX2
$line = shell_exec('asterisk -rx "iax2 show registry"');
$lines = explode("\n",$line);
array_shift($lines); //Remove the headers that are the first line.
array_pop($lines); //The last line is junk.
foreach ( $lines as $x ) {
$x = preg_replace('¦[ ]+¦',"\t",$x);
list($host,$username,$dns,$preceived,$refresh,$state) = explode("\t",$x);
if ( $state != "Registered" ) {
$errors[] = "IAX $host ($username) is in state $state";
}
}
//Start checking Registry
$line = shell_exec('asterisk -rx "sip show registry"');
$lines = explode("\n",$line);
array_shift($lines); //Remove the headers that are the first line.
array_pop($lines); //The last line is junk.
foreach ( $lines as $x ) {
$x = preg_replace('¦[ ]+¦',"\t",$x);
list($host,$username,$refresh,$state) = explode("\t",$x);
if ( $state != "Registered" ) {
$errors[] = "Trunk $host ($username) is in state $state";
}
}
if ( count($errors) > 0 ) {
$h = fopen('/etc/asterisk/asteriskmonitor','a+');
foreach($errors as $x) {
fwrite($h,date("M d H:i:s") . ' ' . $x . "\n");
}
fclose($h);
$message = array(
'There where some problems with your Asterisk Registry',
'--------------------------------------------------------'
);
foreach ( $errors as $x )
$message[] = $x;
$message = implode("\r\n",$message);
$headers = implode("\r\n",array(
'From: monitord@omain.net'
));
mail(EMAIL,'Asterisk Registry Monitor2 - Link Down',$message,$headers);
}
print_r($errors);[codes]