Commit 56d7db7a authored by Robert Ricci's avatar Robert Ricci

New version of the node status page. Presents the output in a far more

pleasing format.

Outputs in a multi-column table, with the number of columns controllable via
the $maxcolumns variable.
parent db269119
......@@ -6,61 +6,47 @@ require("defs.php3");
#
PAGEHEADER("Node Up/Down Status");
?>
<?php
# This is kinda a pain!
$query_result = mysql_db_query($TBDBNAME,
"SELECT node_id, type, status FROM nodes ".
"WHERE type='pc' OR type='shark' " .
"ORDER BY type,priority");
"SELECT count(*) FROM nodes ".
"WHERE status = 'up'");
if (! $query_result) {
$err = mysql_error();
TBERROR("Database Error getting node status: $err\n", 1);
}
# I want the summary at the top of the page, so I build an array that
# gets printed later, while couting the number of nodes with each status
$num_up = 0;
$num_pd = 0;
$num_down = 0;
$num_unpingable = 0;
$lines = array();
$r = mysql_fetch_array($query_result);
$num_up = $r[0];
while ($r = mysql_fetch_array($query_result)) {
$node_id = $r["node_id"];
$type = $r["type"];
$status = $r["status"];
# If you get an answer the first time, you're probably not gonna get an error the
# second time...
$query_result = mysql_db_query($TBDBNAME,
"SELECT count(*) FROM nodes ".
"WHERE status = 'possibly down'");
$r = mysql_fetch_array($query_result);
$num_pd = $r[0];
$line = "<tr><td>$node_id</td><td>$type</td>";
$query_result = mysql_db_query($TBDBNAME,
"SELECT count(*) FROM nodes ".
"WHERE status = 'down'");
$r = mysql_fetch_array($query_result);
$num_down = $r[0];
switch ($status) {
case "up":
$num_up++;
$line .= "<td><img src=\"/autostatus-icons/up.png\" alt=\"up\"></td>";
break;
case "possibly down":
$num_pd++;
$line .= "<td><img src=\"/autostatus-icons/maybe.png\" alt=\"possibly down\"></td>";
break;
case "down":
$num_down++;
$line .= "<td><img src=\"/autostatus-icons/down.png\" alt=\"down\"></td>";
break;
case "unpingable":
$num_unpingable++;
$line .= "<td><img src=\"/autostatus-icons/dep.png\" alt=\"unpingable\"></td>";
break;
default:
$line .= "<td><b>Unknown</b></td>";
break;
}
$query_result = mysql_db_query($TBDBNAME,
"SELECT count(*) FROM nodes ".
"WHERE status = 'unpingable'");
$r = mysql_fetch_array($query_result);
$num_unpingable = $r[0];
$line .= "</tr>\n";
$lines[sizeof($lines)] = $line;
}
$num_total = ($num_up + $num_unpingable + $num_down + $num_pd);
?>
<table align="center">
<table>
<tr><td align="right"><b>Up</b></td><td align="left"><? echo $num_up ?></td></tr>
<tr><td align="right"><b>Unpingable</b></td><td align="left"><? echo $num_unpingable ?></td></tr>
<tr><td align="right"><b>Possibly Down</b></td><td align="left"><? echo $num_pd ?></td></tr>
<tr><td align="right"><b>Down</b></td><td align="left"><?
if ($num_down > 0) {
......@@ -68,16 +54,16 @@ while ($r = mysql_fetch_array($query_result)) {
} else {
echo "$num_down";
} ?> </td></tr>
<tr><td align="right"><b>Unpingable</b></td><td align="left"><? echo $num_unpingable ?></td></tr>
<tr><td align="right"><b>Total</b></td><td align="left"><? echo $num_total ?></td></tr>
</table>
<h3 align="center">
<b>
<?php
# Is there a better way to get 2 digit precision?
printf("%.2f",(($num_up + $num_unpingable)
/($num_up + $num_unpingable + $num_down + $num_pd)) *100);
printf("%.2f",(($num_up + $num_unpingable)/$num_total) *100);
?>
% up or unpingable</h3>
% up or unpingable</b>
<h3>Key:</h3>
<p>
......@@ -87,18 +73,85 @@ printf("%.2f",(($num_up + $num_unpingable)
<img src="/autostatus-icons/dep.png" alt="unpingable"> - Unpingable: Running an operating system that does not respond to pings<br>
</p>
<table align="center">
<tr>
<th>Node</th><th>Type</th><th>Status</th>
</tr>
<?php
for ($i = 0; $i < sizeof($lines); $i++) {
echo $lines[$i];
$query_result = mysql_db_query($TBDBNAME,
"SELECT node_id, type, status FROM nodes ".
# "WHERE type='pc' OR type='shark' " .
"ORDER BY type,priority");
if (! $query_result) {
$err = mysql_error();
TBERROR("Database Error getting node status: $err\n", 1);
}
?>
</table>
$nodecount = 0;
$maxcolumns = 4;
$column = 0; # First pass will increment to 1
$lasttype = "";
while ($r = mysql_fetch_array($query_result)) {
$node_id = $r["node_id"];
$type = $r["type"];
$status = $r["status"];
if ($type != $lasttype) {
if ($lasttype != "") { # Doesn't need to happen the first time
print("</table>\n\n");
}
print("<h3>$type</h3>\n");
print("<table cellspacing=0 cellpadding=5>\n");
$lasttype = $type;
$column = 0;
}
if ($column == $maxcolumns) {
$column = 1;
# End the old row
print "</tr>\n";
} else {
$column++;
}
if ($column %2) {
$tdbg = ""; # Make odd #'d rows have a white background
} else {
$tdbg = "bgcolor=\"#ffffff\"";
}
# Only start a new <tr> if back in column 0
if ($column == 0) {
print("<tr>");
}
print("<td $tdbg><nobr>");
switch ($status) {
case "up":
print("<img src=\"/autostatus-icons/up.png\" alt=\"up\">");
break;
case "possibly down":
print("<img src=\"/autostatus-icons/maybe.png\" alt=\"possibly down\">");
break;
case "down":
print("<img src=\"/autostatus-icons/down.png\" alt=\"down\">");
break;
case "unpingable":
print("<img src=\"/autostatus-icons/dep.png\" alt=\"unpingable\">");
break;
default:
print("<b>Unknown</b>");
break;
}
print("&nbsp;$node_id</nobr></td>");
}
# End the table printed on the last pass
print("</tr>\n</table>\n\n");
?>
<?php
#
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment