checkservice (1.1.0-11) checkservice.php

Summary

 checkservice.php |  200 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 200 insertions(+)

    
download this patch

Patch contents

--- checkservice-1.1.0.orig/checkservice.php
+++ checkservice-1.1.0/checkservice.php
@@ -0,0 +1,200 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html>
+<head>
+  <title>Linvision Checkservice</title>
+  <?php 
+     /* Path to checkservice configdir */
+     $debug = 7;
+     $confdir = "/etc/checkservice";
+
+     /* You don't have to change anything below here */
+     /* Parse global statuspage configfile */
+     $globconf = file("$confdir/statuspage.conf");
+     for ($x = 0; $x < sizeof($globconf); $x++) {
+       $line = chop($globconf[$x]);
+       if (ereg("^([a-z]*)\s*=\s*(.*)$", $line, $data)) { $config[$data[1]] = $data[2]; }
+     }
+
+     /* Parse global checkservice configfile */
+     $globconf = file("$confdir/checkservice.conf");
+     for ($x = 0; $x < sizeof($globconf); $x++) {
+       $line = chop($globconf[$x]);
+       if (ereg("^([a-z]*)\s*=\s*(.*)$", $line, $data)) { $config[$data[1]] = $data[2]; }
+     }
+ 
+     if (!isset($cnt)) $cnt = 0;
+     error_reporting(isset($debug) ? $debug : 15);
+     $cache = "$config[cachepath]/web.cache";
+     $failures = "$config[cachepath]/failures.cache"; ?>
+<style type="text/css">
+  body { background: white; }
+  div.center { text-align: center; }
+</style>
+<meta http-equiv="refresh" content="<?php print "$config[refresh];url=http://${HTTP_HOST}${PHP_SELF}?cnt=". ($cnt + 1); ?>" />
+</head>  
+<body>
+
+<div class="center">
+  <h1><b><a href="http://www.linvision.com/checkservice">Linvision Checkservice</a> v<?php print exec("$config[command] -v short"); ?></b></h1>
+  <h3>by Paul van Tilburg &lt;<a href="mailto:paul@linvision.com">paul@linvision.com</a>&gt;</h3>
+</div>
+
+<br />
+<table>
+  <tr>
+    <td>Status on:</td>
+    <td><?php print strftime("$config[timeformat]", (!$cnt && file_exists($cache)) ? filectime($cache) : time()); ?></td>
+    <td><?php print strftime("$config[dateformat]", (!$cnt && file_exists($cache)) ? filectime($cache) : time()); ?></td>
+<?php if (!$cnt && file_exists($cache)) print "    <td><b><font color=\"red\">Cached!</font></b></td>\n"; ?>
+  </tr>
+  <tr>
+    <td>Next update on:</td>
+    <td><?php print strftime("$config[timeformat]", time() + $config[refresh]); ?></td>
+    <td><?php print strftime("$config[dateformat]", time() + $config[refresh]); ?></td>
+    <td><a href="<?php print "http://$HTTP_SERVER_VARS[HTTP_HOST]$HTTP_SERVER_VARS[PHP_SELF]?cnt=1" ?>">Update now!</a></td>
+  </tr>
+</table>
+
+<hr />
+
+<?php
+if ($cnt || !file_exists($cache))
+  exec("$config[command] -c $confdir -l -", $Check); 
+else
+  $Check = file($cache);
+
+$group = "!!UNKNOWN!!";
+for ($x = 0; $x < sizeof($Check); $x++) {
+  $Data = explode(":", chop($Check[$x]));
+
+  if ($Data[0] == "host") {
+    $tmp = chop($Data[1]);
+    $na_flag = 0;
+    if (ereg("^([^/]*)$", $tmp, $d)) {
+      $prev_group = $group;
+      $group = "";
+      $host = $d[1];
+    }
+    elseif (ereg("^(.*)/([^/]*)$", $tmp, $d)) {
+      $prev_group = $group;
+      $group = $d[1];
+      $host = $d[2];
+    }
+    $url = "http://$host";
+    $hostconf = file("$confdir/hosts/$group/$host");
+    for ($y = 0; $y < sizeof($hostconf); $y++) {
+      $line = chop($hostconf[$y]);
+      if (ereg("^([a-z]*)\s*=\s*(.*)$", $line, $data) && $data[1] == "url") { $url = $data[2]; }
+    } 
+    if ($group != $prev_group)
+      print "<hr />\n<h3>Group: " . str_replace("/", " > ", $group ? $group : "general"). " </h3>\n";
+    print "<table border=\"0\" align=\"center\" width=\"$config[tablewpc]\" bgcolor=\"silver\">\n";
+    if ($config[useurl])
+      print "  <caption><b><i>Servicecheck of host <a href=\"$url\"><font color=\"blue\">$host</font></a></i></b></caption>\n";
+    else
+      print "  <caption><b><i>Servicecheck of host <font color=\"blue\">$host</font></i></b></caption>\n";
+    print "  <tr bgcolor=\"#000066\">
+    <th width=\"46%\"><font color=\"white\">Name</font></th>
+    <th width=\"14%\"><font color=\"white\">Service</font></th>
+    <th width=\"14%\"><font color=\"white\">Port#</font></th>
+    <th width=\"4%\"><font color=\"white\">M</font></th>
+    <th width=\"14%\"><font color=\"white\">Status</font></th>\n";
+    if ($config[showpercentage]) {
+      if ($config[showaverage]) {
+        $avrperc = 0;
+        $avrcnt = 0;
+      }
+      print "    <th width=\"8%\"><font color=\"white\">Up %</font></th>\n";
+    print "  </tr>\n";
+    }
+  }
+  elseif ($Data[0] == "error") {
+    print "  <tr>
+    <td colspan=\"";
+    print $config[showpercentage] ? "6" : "5";
+    print "\" align=\"center\"><font color=\"red\"><b>Host $host is unreachable!</b></font></td>
+  </tr>\n";
+  }
+  elseif ($Data[0] == "service") {
+    print "  <tr>
+    <td>$Data[4]</td>
+    <td>$Data[2]</td>
+    <td>$Data[1]</td>
+    <td>$Data[3]</td>
+    <td><b><font color=\"";
+    if (ereg("ok", $Data[5])) { print "green"; }
+    elseif (ereg("timeout", $Data[5])) { print "purple"; }
+    elseif (ereg("failed", $Data[5])) { print "red"; }
+    else { print "gray"; }
+    print "\">" . chop(strtoupper($Data[5]));
+    print "</font></b></td>\n";
+    if ($config[showpercentage]) {
+      if ($config[showaverage]) {
+        $avrperc += $Data[6];
+        $avrcnt++;
+      }
+      if ($Data[6] == "n/a") {
+	$na_flag = 1;
+        print ("    <td><div align=\"right\">N/A</div></td>\n");
+      }
+      else
+        printf ("    <td><div align=\"right\">%3.$config[uptdec]f</div></td>\n", $Data[6]);
+    }
+    print "  </tr>\n";
+  }  
+  elseif ($Data[0] == "endhost") {
+    if ($config[showpercentage] && $config[showaverage]) {
+      print "  <tr>
+    <td colspan=\"5\"><b>Average uptime all services:</b></td>
+    <td><div align=\"right\"><b>";
+    $na_flag ? print "N/A" : printf ("%3.$config[uptdec]f", $avrcnt ?  $avrperc / $avrcnt : "N/A");
+    print "</b></div></td>
+  </tr>\n";
+    }
+    print "</table>\n<br />\n\n";
+  } 
+}
+
+if (file_exists($failures) && sizeof($Fails = file($failures))) {
+  print "<hr />\n<table border=\"0\" align=\"center\" width=\"$config[tablewpc]\" bgcolor=\"silver\">
+<caption><b><i>Last <font color=\"red\">" . count($Fails) . "</font> failure" . (count($Fails) > 1 ? "s:" : ":") . "</i></b></caption>
+  <tr bgcolor=\"#000066\">
+    <th width=\"28%\"><font color=\"white\">Host</font></th>
+    <th width=\"12%\"><font color=\"white\">Service</font></th>
+    <th width=\"12%\"><font color=\"white\">Port#</font></th>
+    <th width=\"19%\"><font color=\"white\">Error</font></th>
+    <th width=\"19%\"><font color=\"white\">Time/Date</font></th>
+  </tr>\n";
+  for ($x = 0; $x < sizeof($Fails); $x++) {
+    $Data = explode(":", $Fails[$x]);
+    print "  <tr>
+    <td>$Data[0]</td>
+    <td>$Data[1]</td>
+    <td>$Data[2]</td>
+    <td>";
+    if (ereg("ok", $Data[3])) print "<b><font color=\"green\">";
+    elseif (ereg("unreachable", $Data[3])) print "<b><font color=\"purple\">";
+    else print "<b><font color=\"red\">";
+    print chop(strtoupper($Data[3]));
+    print "</font></b></td>
+    <td>";
+    print strftime("$config[timeformat] $config[dateformat]", $Data[4]) . "</td>
+  </tr>\n";
+  }
+  print "</table>";
+}
+else
+  print "<hr />\n<div class=\"center\"><b><i><font color=\"red\">No</font> recorded failures</i></b></div>\n";
+
+?>
+
+<hr /><hr />
+
+<p>
+  <a href="http://validator.w3.org/check/referer">
+  <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a>
+</p>
+<br />
+
+</body>
+</html>