Monday, August 11, 2008

PHP script to monitor servers.


<title>Code</title>

<title>Server Status</title>

<center> <b><font style="" size="5" face="Times New Roman,Times,serif"> Servers - Status of critical services </font></b> </center>

<p><font style="" size="2" face="Verdana,Arial,Helvetica,sans-serif">

<b>Servers</b> ";
for( $j=0; $servicenames[$j]; $j++)
{ echo "<font color="blue"> <b> $servicenames[$j]</b></font> "; }


$serviceports_array = $ini_array['service_ports'];
$serviceports = explode (",",$serviceports_array);
sort($serviceports,SORT_NUMERIC);

for($i=0;$hostnames[$i];$i++)
{
$hostname = $hostnames[$i];
$port_array = $ini_array[$hostname];
$ports = explode (",",$port_array);
sort ($ports,SORT_NUMERIC);

echo " <font color="green"> <b> $hostname </b></font> ";
for($m=0,$n=0;$serviceports[$m];$m++)
{ if ($serviceports[$m] == $ports[$n])
{ disp_status($hostname,$ports[$n],'Y'); $n++;
} else {
disp_status($hostname,$ports[$n],'N');}
}
}

function disp_status($_hostname, $_port, $_status){

error_reporting(0);
// header("Content-type: image/gif");
if ($_status == 'Y')
{
$fp = fsockopen($_hostname, $_port);
if (!$fp)
{ echo " <img src="http://www.blogger.com/%27offline.png%27">";}
else
{ echo " <img src="http://www.blogger.com/%27online.png%27">";}
fclose($fp);
}
else
{ echo " <img src="http://www.blogger.com/%27NA.png%27">";}
}

?>


</font>
</p><p> <b>KEY : <img src="http://www.blogger.com/%27offline.png%27"> OFFLINE <img src="http://www.blogger.com/%27online.png%27"> ONLINE <img src="http://www.blogger.com/%27NA.png%27"> NOT MONITORED </b></p><b>



</b>

No comments: