<?php
/* ##################################
* This function will check for all ports and send an email if one is down.
* This will also use the Name of the Server for easy identification.
*
* This script may NOT be distributed without express written
* permission from Jaguar Technologies, LLC .
* -- www.jaguarpc.com
################################### */
function checkServer($server){
//enter what email or emails (comma seperated) that should receive alerts if a server port isnt responding
$Email = "person@web_site.com, another_person@web_site.com";
while (list($key,$port)=each($server[ports])) {
$alertEmail = 0; // 1=on, 0=off
$fp = fsockopen($server[ip], $port, &$errno, &$errstr, 4);
$serviceName = array(
"21" =>"FTP ",
"22" =>"SSH ",
"25" =>"SMTP/Exim",
"53" =>"BIND/DNS ",
"80" =>"HTTP/DNS ",
"110" =>"POP3 ",
"3306"=>"MySQL ");
if (!$fp) {
$data_p = "<td width=\"25\" align=\"center\"><img src=\"down.gif\"><!-- ($server[ip]:$port) --></td>";
$alertEmail = 1; // 1=on, 0=off
$status_p = "$serviceName[$port]: DOWN <---\n";
} else {
$data_p = "<td width=\"25\" align=\"center\"><img src=\"up.gif\"><!-- ($server[ip]:$port) --></td>";
$status_p = "$serviceName[$port]: UP\n";
fclose($fp);
}
$data .= $data_p;
$status .= $status_p;
}
if ($alertEmail) {
$today = date("m-d-Y H:m:s");
$subject = "Server Alert! : $server[name]";
$body = "----------------------------------\n";
$body .= "Server : $server[name]\n";
$body .= "IP : $server[ip]\n";
$body .= "Time : $today\n";
$body .= "----------------------------------\n\n";
$msg = $status.$body;
mail($Email, $subject, $msg);
}
return $data;
}
?>
<table border="0" width="100%" cellpadding="2" cellspacing="1" bgcolor="#FFFFFF">
<tr bgcolor="#808080" style="font-weight:bold;color:#ffffff;">
<td>Server Name</td>
<td>Info</td>
<td>Http</td>
<td>FTP</td>
<td>SSH</td>
<td>MySQL</td>
<td>Mail</td>
</tr>
<tr>
<td bgcolor="#c0c0c0">SERVERNAME</td>
<td align="center" bgcolor="#c0c0c0">INFO</td>
<?php
$server[ip] = "69.73.xxx.xxx"; //server ip of the machine being monitored
$server[name] = "SERVERNAME"; //server hostname of the machine being monitored
$server[ports] = array("80","21","22","3306","25"); //no need to alter these values unless you want to check different port numbers
echo checkServer($server);
?>
</tr>
</table>