Cactiusers.org


It is currently Mon May 21, 2012 4:50 pm




Post new topic Reply to topic  [ 1 post ] 
 Tools plugin with healthcheck services 
Author Message
User

Joined: Mon Dec 19, 2005 3:44 pm
Posts: 170
Post Tools plugin with healthcheck services
Hi

I 've had for my needs in tools plugin the possibility to do healthcheck (I have force for only the HEAD request.
Could you add it?

my changes:
in setup.php
Code:
   $nav["tools.php:healthcheck"] = array("title" => "Network Tools", "mapping" => "index.php:", "url" => "tools.php", "level" => "1");


in tools.php
Code:
32,34d31
<    case 'healthcheck':
<       ShowHealthCheck();
<       break;
50,53c47
<    print "<br><br><br><center>";
< print "<div align='left'>";
<    print "<table bgcolor=black cellpadding=1 cellspacing=0><tr><td>
<    <table width='100%' bgcolor=white cellspacing=3><tr><td>";
---
>    print "<br><br><br><center><table width=500 bgcolor=black cellpadding=1 cellspacing=0><tr><td><table width='100%' bgcolor=white cellspacing=3><tr><td>";
73,95d66
< //Port check
<    print "<tr><td colspan=2><hr width='100%'></td></tr>";
<    if (isset($_POST['porttocheck']))
<       $porttocheck = $_POST['porttocheck'];
<    else
<       $porttocheck = "";
<    if (isset($_POST['parameter']))
<       $parameter = $_POST['parameter'];
<    else
<       $parameter = "";
<    print "<tr><td><input type=radio name=action value=healthcheck";
<    if ($action == 'healthcheck')
<       print " checked";
<    print ">";
<    print "</td><td><h3>Http health check</h3>";
<    print "<table cellspacing=0 cellpadding=0 corder=0>";
<    print "<tr><td>port to check&nbsp;&nbsp;&nbsp;</td>";
<    print "<td><input type=text size=20 value='".$porttocheck."' name=porttocheck id=porttocheck></td></tr>";
<    print "<tr><td>path to check&nbsp;&nbsp;&nbsp;</td>";
<    print "<td><input type=text size=50 value='".$parameter."' name=parameter id=parameter></td></tr>";
<    print "<tr><td></td><td>ex: /linktocheck (when you want check http://myserver:port/linktocheck)</td></tr>";
<    print "</table>";
< //
100d70
< print "</div>";
110,112c80,81
< //   print "<br><br><br><center><table width=500 bgcolor=black cellpadding=1 cellspacing=0><tr><td><table width='100%' bgcolor=white><tr><td>";
<    print "<br><br><br><center><table bgcolor=black cellpadding=1 cellspacing=0><tr><td><table width='100%' bgcolor=white><tr><td>";
<       $results = array();
---
>    print "<br><br><br><center><table width=500 bgcolor=black cellpadding=1 cellspacing=0><tr><td><table width='100%' bgcolor=white><tr><td>";
>    $results = array();
127,213d95
< function ShowHealthCheck () {
<
<    if (isset($_POST['host']))
<       $host = $_POST['host'];
<    else
<       return;
<    if (isset($_POST['porttocheck']))
<       $porttocheck = $_POST['porttocheck'];
<    else
<       $porttocheck = "";
<    if (isset($_POST['parameter']))
<       { $req = $_POST['parameter']; $req = preg_replace('/\\\\/', '\\', $req); }
<    else
<       $req = "";
<    if ($porttocheck=="") exit;
<    print "<br>";
<    print "<div align='left'>";
<    print "<table bgcolor=black cellpadding=1 cellspacing=0>";
<    print "<tr><td><table width='100%' bgcolor=white><tr><td>";
<
<    print "<center><table><tr><td colspan=2>
<       <center><h3>Port check Results for $host</h3></center></td></tr>";
<    $results = array();
<    $results[] = HealthCheck($host, $porttocheck, $req);
<    $r=$results[0];
<
<    print "<tr><td>host=" . $r['host'] . "</td><td></td></tr>";
<    print "<tr><td>host=" . $r['port'] . "</td><td></td></tr>";
<    print "<tr><td>request=</td><td>" . $r['request'] . "</td></tr>";
<    print "<tr><td>" . $r['result'] . "</td><td>" . $r['time'] . "</td></tr>";
<    print "<tr><td>" . "error msg" . "</td><td>" . $r['error'] . "</td></tr>";
<
<    print "</table></center>";
<    print "</td></tr></table></td></tr></table>";
<    print "</div>";
< }
<
< function HealthCheck($host, $port, $req, $timeout = 10) {
<    $host = strtolower($host);
<    $req = preg_replace('/\\\\/', '\\', $req);
<    $Request ="HEAD " . $req . " HTTP/1.0\r\nUser-Agent: Service Check\r\nHost: $host\r\n\r\n";
<    $OkResults = array("200\D+OK", "200\D+Document\s+Follows", "302", "301");
<    if(!is_numeric($port)) $port = 80;
<
<    list($MSec, $Sec) = explode(" ", microtime());
<    $TimeBegin = (double) $MSec + (double) $Sec;
<    $Socket = @fsockopen($host, $port, $error_number, $error, $timeout);
<    list($MSec, $Sec) = explode(" ", microtime());
<    $TimeEnd = (double) $MSec + (double) $Sec;
<    $Time = number_format($TimeEnd - $TimeBegin, 3);
<    // Check port
<
<    if (is_resource($Socket)) {
<       if ($Request != "") {
<          fputs($Socket, $Request);
<          stream_set_timeout($Socket, $timeout);
<       }
<       if (!feof($Socket)) {
<          $Response = fgets($Socket, 4096);
<          stream_set_timeout($Socket, $timeout);
<       }
<       $Result = "Failed";
<       $Error  = $Response;
<
<       foreach($OkResults as $exp_result) {
<          if (preg_match("/$exp_result/",$Response)) {
<             $Error = "";
<             $Result = "Ok";
<          }
<       }
<       fclose($Socket);
<     } else {
<       $Result = "Failed";
<       $Error = ((!$error) ? "Time out" : $error);
<     }
<
<     return array(
<          'host'   => $host,
<          'port'   => $port,
<          'request'=> $Request,
<          'result' => $Result,
<          'time'   => $Time,
<          'error'  => $Error
<        );
<
< }
<


Attachments:
temphealthchek.jpg
temphealthchek.jpg [ 49.18 KiB | Viewed 636 times ]
Thu Aug 24, 2006 3:37 am
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: