1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
<!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>
<?
/* Path to checkservice configdir */
$debug = 7;
$confdir = "/etc/checkservice";
/* You don't have to change anything below here */
/* Parse global status page 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="<? 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<? print exec("$config[command] -v short"); ?></b></h1>
<h3>by Paul van Tilburg <<a href="mailto:paul@linvision.com">paul@linvision.com</a>></h3>
</div>
<br />
<table>
<tr>
<td>Status on:</td>
<td><? print strftime("$config[timeformat]", (!$cnt && file_exists($cache)) ? filectime($cache) : time()); ?></td>
<td><? print strftime("$config[dateformat]", (!$cnt && file_exists($cache)) ? filectime($cache) : time()); ?></td>
<? if (!$cnt && file_exists($cache)) print " <td><b><font color=\"red\">Cached!</font></b></td>\n"; ?>
</tr>
<tr>
<td>Next update on:</td>
<td><? print strftime("$config[timeformat]", time() + $config[refresh]); ?></td>
<td><? print strftime("$config[dateformat]", time() + $config[refresh]); ?></td>
<td><a href="<? print " . http://$HTTP_SERVER_VARS['HTTP_HOST']$HTTP_SERVER_VARS['PHP_SELF']
."?cnt=1" ?>">Update now!</a></td>
</tr>
</table>
<hr />
<?
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>
|