Helpdesk network status

From Wiki

Revision as of 16:39, 23 June 2008 by SYNACK (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to:navigation, search

Creator: Webman

Script Language: PHP

Forum topic Link: http://www.edugeek.net/forums/networks/16832-helpdesk-network-status.html

This PHP code will show to status of your servers, this is a live example http://www.bishopbarrington.net/status/

Big Thank you Webman for this code.

<php><?php

$hosts['10.0.0.2'] = 'Primary Domain Controller'; $hosts['10.0.0.3'] = 'Secondary Domain Controller'; $hosts['10.0.0.4'] = 'Management Server (SIMS)'; $hosts['10.0.0.1'] = 'Proxy Server'; $hosts['10.0.0.11'] = 'Email and Website'; $hosts['217.23.229.1'] = 'Internet access'; $hosts['panther'] = 'Backup file server'; $hosts['10.10.10.1'] = 'Wireless (Staff room)'; $hosts['10.10.10.2'] = 'Wireless (Study Centre)'; $hosts['10.10.10.3'] = 'Wireless Bridge (main block)'; $hosts['10.10.10.4'] = 'Wireless Bridge (sports hall)';


?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html> <head> <style type="text/css"> </style>

<title>Server Status</title> </head> <body>

<?php function ping($host){ $rv = exec( "ping $host -c 1 -w 1" ); if( $rv != "" ) { return true; } else { return false; } } $namesonly = true; if( $_GET["debug"] == "true" ) { $namesonly = false; } $faultcount = 0; foreach($hosts as $ip=>$name){ if( $namesonly == true ){ $txt = "$name"; } else { $txt = "$name ($ip)"; } if(ping($ip)){ echo ''."\n";

} else {

echo ''."\n";

$faultcount++; } } ?>

Bishop Barrington
Server Status


'.$txt.' Up
'.$txt.' Down

 

</body> </html> </pre>

Version Two - Credit to christhack, ittech, Webman and Rusdev

This version runs on Windows IIS.

- If you add portal=true to end of the url it shows a cutdown version with all ok message or there has been an error message.

- adding the above code to stop the debug error

- Adding a msg at the bottom of the screen that says how many and what servers are down (the as I call it the idiots msg as I can't be bothered to work the table out)

<?php

$hosts['90.56.156.16'] = 'LHS-SR-001';
$hosts['10.56.156.18'] = 'LHS-SR-002';
$hosts['10.56.157.16'] = 'LHS-SR-SIMS';
$hosts['10.56.156.15'] = 'Internal Support Server';


$ReportedErrors= "";
$portalview ="";

function ping($host){
	$hostconnect = "Ping request could not find host ". $host . ". Please check the name and try again." ;
	$ipconnect = "    Packets: Sent = 1, Received = 0, Lost = 1 (100% loss)," ;
	$rv = exec("ping $host -n 1 -w 1");
	if( $ipconnect == $rv )	{
		return false;
	} else {
		if( $hostconnect == $rv ) {
		return false;
	} else {
		return true;
	}
	}
}

if (isset($_GET["portal"])) {

if( $_GET["portal"] == "true" ) { $portalview = true; }
} else {
}


						
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<style type="text/css">
<!--

body{margin:0px;padding:0px;font-family: Tahoma, Verdana, Arial, sans-serif;}
p{font-size:11px;margin:15px;line-height:150%;}
td{font-size:10px;font-family:Verdana, Tahoma, Verdana, Arial;}
input{font-size:11px;font-family:Tahoma;}
img{border:0px;}
-->
</style>

<title>Network Status</title>
</head>
<body>
<p style="margin:1px;">
<table cellspacing="8" align="center">
<tr>

<?PHP
if ($portalview == False){
echo '<td colspan="3" align="center" style="border-bottom:4px solid gray;">
<span style="color:0080c0;font-size:18pt;font-weight:bold;font-family:tahoma;">Limehurst High School</span><br>
<span style="color:gray;font-size:13pt;font-weight:normal;font-family:tahoma;"><b>Network</b> Status</span>
<br>

<!--<img src="printericon.jpg" width="147" height="143"> -->
<br>
<br>

</td>';
}
?>

</tr>
<?php


$namesonly = true;

if (isset($_GET["debug"])) {
if( $_GET["debug"] == "true" ) { $namesonly = false; }
} else {
}


$txt = "";	
$faultcount = 0;

foreach($hosts as $ip=>$name){
	if( $namesonly == true ){
		if ($portalview == False){
			$txt = "$name";
		}
	} else {
		if ($portalview == False){
			$txt = "$name <span style=\"font-weight: normal;\">($ip)</span>";
		}
	}

	if(ping($ip)){
  		if ($portalview == False){
			echo '<tr><td style="font-size:11px;">'.$txt.'</td><td width="16"> </td><td align="center"><span style="color:#008000;"><strong>Up</strong></span></td></tr>'."\n";
		}
	} else {
		if ($portalview == False){
			echo '<tr><td style="font-size:11px;">'.$txt.'</td><td width="16"> </td><td align="center"><span style="color:red;"><strong>Down</strong></span></td></tr>'."\n";
		}
		$ReportedErrors = $ReportedErrors . $name . ", ";
		$faultcount++;
		
	}
}

?>
</table>
<?PHP

if ($faultcount>0) {
echo "<center> <SPAN style=\"font-size: 11pt\"><span style=\"color:red;\"><strong>There Are Currently $faultcount Connection Errors. <br> The Servers That Have Errors Are $ReportedErrors</strong></center></span></span>";
}else {
echo "<center> <SPAN style=\"font-size: 11pt\"><span style=\"color:#008000;\"><strong>All Servers Are Fine</strong></span></span>";}
?>



</p>
</body>
</html>

</php>

[[Category:Network Management]]
[[Category:PHP]]