updown.php3 5.48 KB
Newer Older
1
<?php
Leigh B. Stoller's avatar
Leigh B. Stoller committed
2
#
3
# Copyright (c) 2000-2003, 2007 University of Utah and the Flux Group.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
# 
# {{{EMULAB-LICENSE
# 
# This file is part of the Emulab network testbed software.
# 
# This file is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or (at
# your option) any later version.
# 
# This file is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public
# License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this file.  If not, see <http://www.gnu.org/licenses/>.
# 
# }}}
Leigh B. Stoller's avatar
Leigh B. Stoller committed
23
#
24 25
require("defs.php3");

26 27
if (isset($_REQUEST["output"]) &&
    $_REQUEST["output"] == "xml") {
Chad Barb's avatar
 
Chad Barb committed
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
    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;
}

66 67 68 69 70
#
# Standard Testbed Header
#
PAGEHEADER("Node Up/Down Status");

71
$query_result =
72
    DBQueryFatal("SELECT n.node_id,n.type,ns.status,nt.class FROM nodes as n ".
73 74 75 76
	"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
77

78 79 80
$num_up    = 0;
$num_pd    = 0;
$num_down  = 0;
81
$num_unk   = 0;
Robert Ricci's avatar
Robert Ricci committed
82

83 84 85 86 87 88 89 90
while ($r = mysql_fetch_array($query_result)) {
	$status = $r["status"];

	switch ($status) {
	case "up":
	    $num_up++;
	    break;
	case "possibly down":
91
	case "unpingable":
92 93 94 95 96 97
	    $num_pd++;
	    break;
	case "down":
	    $num_down++;
	    break;
	default:
98
	    $num_unk++;
99 100 101
	    break;
	}
}
102
$num_total = ($num_up + $num_down + $num_pd + $num_unk);
103 104
mysql_data_seek($query_result, 0);

Robert Ricci's avatar
Robert Ricci committed
105 106
?>

107
<table>
108 109 110 111
<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>
112 113
<tr><td align="right">
    <b>Unknown</b></td><td align="left"><? echo $num_unk ?></td></tr>
114 115 116 117 118 119 120 121 122 123 124 125
<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
126
</table>
127

128 129

<b>
Robert Ricci's avatar
Robert Ricci committed
130 131
<?php
# Is there a better way to get 2 digit precision?
132
printf("%.2f",(($num_up)/$num_total) *100);
Robert Ricci's avatar
Robert Ricci committed
133
?>
134
% up </b>
Robert Ricci's avatar
Robert Ricci committed
135 136

<h3>Key:</h3>
Chad Barb's avatar
 
Chad Barb committed
137 138
<ul>
<li>
139
<img src="/autostatus-icons/greenball.gif" alt="up"> - Up<br>
Chad Barb's avatar
 
Chad Barb committed
140
</li><li>
141 142
<img src="/autostatus-icons/yellowball.gif" alt="Possibly Down"> -
     Possibly Down<br>
Chad Barb's avatar
 
Chad Barb committed
143
</li><li>
144
<img src="/autostatus-icons/redball.gif" alt="down"> - Down<br>
Chad Barb's avatar
 
Chad Barb committed
145
</li><li>
146
<img src="/autostatus-icons/blueball.gif" alt="Unknown"> - Unknown<br>
Chad Barb's avatar
 
Chad Barb committed
147 148 149
</li>
</ul>

Robert Ricci's avatar
Robert Ricci committed
150 151

<?php
152 153 154 155 156 157 158 159 160 161
$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"];
162
	$class = $r["class"];
163 164 165 166 167 168

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

169 170 171 172 173 174 175
                if ($class == "pc") {
  		    print("<a href=shownodetype.php3?node_type=$type>".
                          "<h4>$type</h4></a>\n");
                }
                else {
		    print("<h4>$type</h4>\n");
                }
176 177
		print("<table class=\"nogrid\" ".
                      "cellspacing=0 border=0 cellpadding=5>\n");
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204

		$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":
205
			print("<img src=\"/autostatus-icons/greenball.gif\" alt=\"up\">");
206
			break;
207
		case "unpingable":
208
		case "possibly down":
209
			print("<img src=\"/autostatus-icons/yellowball.gif\" alt=\"possibly down\">");
210 211
			break;
		case "down":
212
			print("<img src=\"/autostatus-icons/redball.gif\" alt=\"down\">");
213 214
			break;
		default:
215
			print("<img src=\"/autostatus-icons/blueball.gif\" alt=\"Unknown\">");
216 217 218 219 220 221 222 223 224
			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
225 226

<?php
227 228 229 230 231 232
#
# Standard Testbed Footer
# 
PAGEFOOTER();
?>