Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Asterisk log monitoring
<?php
$output = array();
// This command finds the last 100 mentions of "Peer" in the log. Modify using your own keywords!
exec("grep Peer /var/log/asterisk/full | tail --lines=100", $output);
$output = array_reverse($output);
$today = date("M d");
$yesterday = date("M d",time()-86400);
$twodaysago = date("M d",time()-172800);
$output = preg_replace("/UNREACHABLE/", "<unreach>UNREACHABLE</unreach>", $output);
$output = preg_replace("/Lagged/", "<lag>Lagged</lag>", $output);
$output = preg_replace("/Reachable/", "<reach>Reachable</reach>", $output);
$today_data = preg_grep("/".$today."/i",$output);
$yesterday_data = preg_grep("/".$yesterday."/i",$output);
$twodaysago_data = preg_grep("/".$twodaysago."/i",$output);
echo "<html><head><style>
body { background-color: black; color: white; font:15px arial,sans-serif; }
unreach { background-color: maroon; }
lag { background-color: darkgoldenrod; }
reach { background-color: darkgreen; }
</style></head><body>";
echo "<h1>Asterisk Peers</h1>";
echo "<h2>Time is ".date("M d H:i:s")."</h2>";
echo "<b>Today ".$today."</b><br/>";
foreach($today_data as $line){
echo $line."<br/>";
}
echo "<b>Yesterday ".$yesterday."</b><br/>";
foreach($yesterday_data as $line){
echo $line."<br/>";
}
echo "<b>2 Days Ago ".$twodaysago."</b><br/>";
foreach($twodaysago_data as $line){
echo $line."<br/>";
}
echo "</body></html>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.