updown.php3 4.74 KB
Newer Older
1
<?php
Leigh Stoller's avatar
Leigh Stoller committed
2 3
#
# EMULAB-COPYRIGHT
4
# Copyright (c) 2000-2003 University of Utah and the Flux Group.
Leigh Stoller's avatar
Leigh Stoller committed
5 6
# All rights reserved.
#
7 8
require("defs.php3");

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
if ($output == "xml") {
    header("Content-type: text/xml");

    $query_result =
	DBQueryFatal("SELECT n.node_id, n.type, ns.status FROM nodes as n ".
		     "left join node_types as nt on nt.type=n.type ".
		     "left join node_status as ns on ns.node_id=n.node_id ".
		     "WHERE nt.class!='shark' and role='testnode'".
		     "ORDER BY n.type,n.priority");

    print "<?xml version=\"1.0\" encoding=\"ISO-8859_1\" standalone=\"yes\"?>\n";

    print "<!DOCTYPE testbed \n[\n".
          "  <!ELEMENT testbed (node*)>\n".
	  "  <!ATTLIST testbed name CDATA #REQUIRED>\n".
          "  <!ELEMENT node EMPTY>\n".
	  "  <!ATTLIST node id     ID    #REQUIRED\n".
	  "                 type   CDATA #IMPLIED\n".
          "                 status CDATA \"unknown\"\n".
          "  >\n". 
	  "]>\n";

    print "<testbed name=\"$OURDOMAIN\">\n";
    while ($r = mysql_fetch_array($query_result)) {
	$node_id = $r["node_id"];
	$type = $r["type"];
	$status = $r["status"];
	
	print "  <node id=\"$node_id\" type=\"$type\" ";
	if ($status != "") {
	    print " status=\"$status\" ";
	}
	print "/>\n";
    }
    print "</testbed>\n";

    return;
}

48 49 50 51 52
#
# Standard Testbed Header
#
PAGEHEADER("Node Up/Down Status");

53
$query_result =
54
    DBQueryFatal("SELECT n.node_id,n.type,ns.status,nt.class FROM nodes as n ".
55 56 57 58
	"left join node_types as nt on nt.type=n.type ".
	"left join node_status as ns on ns.node_id=n.node_id ".
	"WHERE nt.class!='shark' and role='testnode'".
	"ORDER BY n.type,n.priority");
Robert Ricci's avatar
Robert Ricci committed
59

60 61 62
$num_up    = 0;
$num_pd    = 0;
$num_down  = 0;
63
$num_unk   = 0;
Robert Ricci's avatar
Robert Ricci committed
64

65 66 67 68 69 70 71 72
while ($r = mysql_fetch_array($query_result)) {
	$status = $r["status"];

	switch ($status) {
	case "up":
	    $num_up++;
	    break;
	case "possibly down":
73
	case "unpingable":
74 75 76 77 78 79
	    $num_pd++;
	    break;
	case "down":
	    $num_down++;
	    break;
	default:
80
	    $num_unk++;
81 82 83
	    break;
	}
}
84
$num_total = ($num_up + $num_down + $num_pd + $num_unk);
85 86
mysql_data_seek($query_result, 0);

Robert Ricci's avatar
Robert Ricci committed
87 88
?>

89
<table>
90 91 92 93
<tr><td align="right">
    <b>Up</b></td><td align="left"><? echo $num_up ?></td></tr>
<tr><td align="right">
    <b>Possibly Down</b></td><td align="left"><? echo $num_pd ?></td></tr>
94 95
<tr><td align="right">
    <b>Unknown</b></td><td align="left"><? echo $num_unk ?></td></tr>
96 97 98 99 100 101 102 103 104 105 106 107
<tr><td align="right"><b>Down</b></td><td align="left">
<?
if ($num_down > 0) {
    echo "<font color=\"red\">$num_down</font>";
}
else {
    echo "$num_down";
}
?>
</td></tr>
<tr><td align="right">
    <b>Total</b></td><td align="left"><? echo $num_total ?></td></tr>
Robert Ricci's avatar
Robert Ricci committed
108
</table>
109

110 111

<b>
Robert Ricci's avatar
Robert Ricci committed
112 113
<?php
# Is there a better way to get 2 digit precision?
114
printf("%.2f",(($num_up)/$num_total) *100);
Robert Ricci's avatar
Robert Ricci committed
115
?>
116
% up </b>
Robert Ricci's avatar
Robert Ricci committed
117 118

<h3>Key:</h3>
Chad Barb's avatar
Chad Barb committed
119 120
<ul>
<li>
121
<img src="/autostatus-icons/greenball.gif" alt="up"> - Up<br>
Chad Barb's avatar
Chad Barb committed
122
</li><li>
123 124
<img src="/autostatus-icons/yellowball.gif" alt="Possibly Down"> -
     Possibly Down<br>
Chad Barb's avatar
Chad Barb committed
125
</li><li>
126
<img src="/autostatus-icons/redball.gif" alt="down"> - Down<br>
Chad Barb's avatar
Chad Barb committed
127
</li><li>
128
<img src="/autostatus-icons/blueball.gif" alt="Unknown"> - Unknown<br>
Chad Barb's avatar
Chad Barb committed
129 130 131
</li>
</ul>

Robert Ricci's avatar
Robert Ricci committed
132 133

<?php
134 135 136 137 138 139 140 141 142 143
$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"];
144
	$class = $r["class"];
145 146 147 148 149 150

	if ($type != $lasttype) {
		if ($lasttype != "") { # Doesn't  need to happen the first time
			print("</table>\n\n");
		}

151 152 153 154 155 156 157
                if ($class == "pc") {
  		    print("<a href=shownodetype.php3?node_type=$type>".
                          "<h4>$type</h4></a>\n");
                }
                else {
		    print("<h4>$type</h4>\n");
                }
158 159
		print("<table class=\"nogrid\" ".
                      "cellspacing=0 border=0 cellpadding=5>\n");
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

		$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":
187
			print("<img src=\"/autostatus-icons/greenball.gif\" alt=\"up\">");
188
			break;
189
		case "unpingable":
190
		case "possibly down":
191
			print("<img src=\"/autostatus-icons/yellowball.gif\" alt=\"possibly down\">");
192 193
			break;
		case "down":
194
			print("<img src=\"/autostatus-icons/redball.gif\" alt=\"down\">");
195 196
			break;
		default:
197
			print("<img src=\"/autostatus-icons/blueball.gif\" alt=\"Unknown\">");
198 199 200 201 202 203 204 205 206
			break;
	}
	print("&nbsp;$node_id</nobr></td>");
}

# End the table printed on the last pass
print("</tr>\n</table>\n\n");

?>
Robert Ricci's avatar
Robert Ricci committed
207 208

<?php
209 210 211 212 213 214
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>