[Nagios-db-checkins] nagios-db/ui/hostDetails data.php,NONE,1.1 selector.php,NONE,1.1
Status: Beta
Brought to you by:
bench23
From: Bench <be...@us...> - 2005-02-10 23:43:13
|
Update of /cvsroot/nagios-db/nagios-db/ui/hostDetails In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14302/hostDetails Added Files: data.php selector.php Log Message: rudimentary support for host details --- NEW FILE: data.php --- <?php require_once '../globals.php'; require_once '../init.php'; if($_GET["startBound"] == 1) { $startTime = mktime(0,0,0,$_GET["startMonth"],$_GET["startDay"],$_GET["startYear"]); $startTitle = $_GET["startYear"] . "-" . $_GET["startMonth"] . "-" . $_GET["startDay"]; } else { $startTime = "null"; $startTitle = "the beginning"; } if($_GET["stopBound"] == 1) { $stopTime = mktime(0,0,0,$_GET["stopMonth"],$_GET["stopDay"],$_GET["stopYear"]); $stopTitle = $_GET["stopYear"] . "-" . $_GET["stopMonth"] . "-" . $_GET["stopDay"]; } else { $stopTime = "null"; $stopTitle = "now"; } ?> <html> <head> <title>host details</title> <link rel="stylesheet" href="/neb/css/defaults.css"> <script type='text/javascript'> function toggle(n) { var i,c; var t = this.document.getElementById(n).firstChild; c = t.childNodes.length; i = 1; while(i < c) { if(t.childNodes[i].style.display == 'none') t.childNodes[i].style.display = ''; else t.childNodes[i].style.display = 'none'; i++; } } function toggleTables() { var tables = document.getElementsByTagName("table"); var i; for(i=0; tables[i]; i++) { if(tables[i].id == "hosts" || tables[i].id.substring(0,7) === "service") toggle(tables[i].id); } } </script> </head> <body link="black" alink="black" vlink="black" onload="toggleTables()"> <table width="100%"> <?php echo "<tr><td colspan=2><b>Host Details from $startTitle through $stopTitle (inclusive)</b></td></tr>"; echo "<p>"; echo "<tr><td align=\"right\"><b>Host:</b></td><td><h2>" . $_GET["host"] . "</h2></td></tr>"; echo "<p>"; ?> </table> <?php $q = $app->Backend->hostHistory($startTime, $stopTime, $_GET["host"]); $row_count = count($q); $hostStarted = $q[$row_count-1]["started"]; $hostStopped = $q[0]["started"]+$q[0]["lasted"]; echo "<table id='hosts' width=100%>"; echo "<tr bgcolor=\"#cccccc\"><td colspan=3><table width=100%><tr><td width=30 onclick=\"toggle('hosts')\">[+|-]</td><td align=\"left\">Host history"; if($hostStarted > $startTime || $hostStopped < $stopTime) { echo "</td><td align=\"right\"><font color=\"red\"><i>Availabe data from " . date("Y-M-d",$hostStarted) . " to " . date("Y-M-d",$hostStopped) . " is less than the requested interval</font></i>"; } else { echo "</td><td>"; } echo "</td></tr></table></td></tr><tr><td colspan=3><hr></td></tr>"; $lastColor = 0; for($i = 0; $i < $row_count; $i++) { echo "<tr bgcolor=\""; switch($q[$i]["soft_state"]) { case "0": echo "$green1"; break; case "1": echo "$red1"; break; case "2": echo "$orange1"; break; default: echo "white"; break; } echo "\"><td>" . date("Y-M-d H:i:s",$q[$i]["started"]) . "</td><td>"; switch($q[$i]["soft_state"]) { case "0": echo "OK"; break; case "1": echo "Critical"; break; case "2": echo "Unreachable"; break; default: echo $q[$i]["soft_state"]; break; } echo "</td><td>" . $q[$i]["plugin_output"] . "</td></tr>"; } echo "</table><p>"; $q = $app->Backend->serviceHistory($startTime, $stopTime, $_GET["host"]); $row_count = count($q); $serviceHistories = array(); for($i = 0; $i < $row_count; $i++) { if(!array_key_exists($q[$i]["service_description"],$serviceHistories)) { $serviceHistories[$q[$i]["service_description"]] = array("service_description" => $q[$i]["service_description"], "service_started" => $q[$i]["started"], "service_stopped" => $q[$i]["started"] + $q[$i]["lasted"]); } // Because the query is sorted, we know that the started column will continue descreasing for this service_description. $serviceHistories[$q[$i]["service_description"]]["service_started"] = $q[$i]["started"]; } $i = 0; foreach($serviceHistories as $thisService) { echo "<table id='service$i' width=100%>"; echo "<tr bgcolor=\"#cccccc\"><td colspan=3><table width=100%><tr><td width=30 onclick=\"toggle('service$i')\">[+|-]</td><td>Service history for service " . $thisService["service_description"]; if($thisService["service_started"] > $startTime || $thisService["service_stopped"] < $stopTime) { echo "</td><td align=\"right\"><i><font color=\"red\">Availabe data from " . date("Y-M-d",$thisService["service_started"]) . " to " . date("Y-M-d",$thisService["service_stopped"]) . " is less than the requested interval</font></i>"; } else { echo "</td><td>"; } echo "</td></tr></table></td></tr><tr><td colspan=3><hr></td></tr>"; $lastColor = 0; while($i < $row_count && $q[$i]["service_description"] == $thisService["service_description"]) { echo "<tr bgcolor=\""; switch($q[$i]["soft_state"]) { case "0": echo "$green1"; break; case "1": echo "$yellow1"; break; case "2": echo "$red1"; break; case "3": echo "$orange1"; break; default: echo "white"; break; } echo "\"><td>" . date("Y-M-d H:i:s",$q[$i]["started"]) . "</td><td>"; switch($q[$i]["soft_state"]) { case "0": echo "OK"; break; case "1": echo "Warning"; break; case "2": echo "Critical"; break; case "3": echo "Unknown"; break; default: echo $q[$i]["soft_state"]; break; } echo "</td><td>" . $q[$i]["plugin_output"] . "</td></tr>"; $i++; } echo "</table><p>"; } ?> </body> </html> --- NEW FILE: selector.php --- <SCRIPT TYPE="text/javascript"> <!-- // copyright 1999 Idocs, Inc. http://www.idocs.com // Distribute this script freely but keep this notice in place function numbersonly(myfield, e, dec) { var key; var keychar; if (window.event) key = window.event.keyCode; else if (e) key = e.which; else return true; keychar = String.fromCharCode(key); // control keys if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27)) return true; // numbers else if ((("0123456789").indexOf(keychar) > -1)) return true; // decimal point jump else if (dec && (keychar == ".")) { myfield.form.elements[dec].focus(); return false; } else return false; } function disablestart() { var day = document.getElementById("startDay"); var month = document.getElementById("startMonth"); var year = document.getElementById("startYear"); day.disabled = true; month.disabled = true; year.disabled = true; } function enablestart() { var day = document.getElementById("startDay"); var month = document.getElementById("startMonth"); var year = document.getElementById("startYear"); day.disabled = false; month.disabled = false; year.disabled = false; } function disablestop() { var day = document.getElementById("stopDay"); var month = document.getElementById("stopMonth"); var year = document.getElementById("stopYear"); day.disabled = true; month.disabled = true; year.disabled = true; } function enablestop() { var day = document.getElementById("stopDay"); var month = document.getElementById("stopMonth"); var year = document.getElementById("stopYear"); day.disabled = false; month.disabled = false; year.disabled = false; } --> </SCRIPT> <?php require_once '../init.php'; $rightNow = time(); ?> <html> <head> <title>host details selector</title> </head> <body> Enter which host to report availability on: <form method="get" target="main" action="/neb/hostDetails/data.php"> <input type=text name="host" id="host" size="20" maxlength="40"> <hr> <input type=radio name="startBound" value="0" onClick="disablestart()">Unbounded Start Time<br> <input type=radio name="startBound" value="1" checked onClick="enablestart()">Bounded Start Time<br> <input type=text value="<?php echo date("Y",$rightNow-2419200); ?>" name="startYear" id="startYear" size="4" maxlength="4" onKeyPress="return numbersonly(this, event)"> - <select name=startMonth id="startMonth"> <option value=1 <?php if(1 == date("n",$rightNow-2419200)) echo "selected"; ?>>Jan</option> <option value=2 <?php if(2 == date("n",$rightNow-2419200)) echo "selected"; ?>>Feb</option> <option value=3 <?php if(3 == date("n",$rightNow-2419200)) echo "selected"; ?>>Mar</option> <option value=4 <?php if(4 == date("n",$rightNow-2419200)) echo "selected"; ?>>Apr</option> <option value=5 <?php if(5 == date("n",$rightNow-2419200)) echo "selected"; ?>>May</option> <option value=6 <?php if(6 == date("n",$rightNow-2419200)) echo "selected"; ?>>Jun</option> <option value=7 <?php if(7 == date("n",$rightNow-2419200)) echo "selected"; ?>>Jul</option> <option value=8 <?php if(8 == date("n",$rightNow-2419200)) echo "selected"; ?>>Aug</option> <option value=9 <?php if(9 == date("n",$rightNow-2419200)) echo "selected"; ?>>Sep</option> <option value=10 <?php if(10 == date("n",$rightNow-2419200)) echo "selected"; ?>>Oct</option> <option value=11 <?php if(11 == date("n",$rightNow-2419200)) echo "selected"; ?>>Nov</option> <option value=12 <?php if(12 == date("n",$rightNow-2419200)) echo "selected"; ?>>Dec</option> </select> - <input type=text value="<?php echo date("j",$rightNow-2419200); ?>" name="startDay" id="startDay" size="2" maxlength="2" onKeyPress="return numbersonly(this, event)"> <hr> <input type=radio name="stopBound" value="0" onClick="disablestop()">Unbounded Stop Time<br> <input type=radio name="stopBound" value="1" checked onClick="enablestop()">Bounded Stop Time<br> <input type=text value="<?php echo date("Y",$rightNow); ?>" name="stopYear" id="stopYear" size="4" maxlength="4" onKeyPress="return numbersonly(this, event)"> - <select name=stopMonth id="stopMonth"> <option value=1 <?php if(1 == date("n",$rightNow)) echo "selected"; ?>>Jan</option> <option value=2 <?php if(2 == date("n",$rightNow)) echo "selected"; ?>>Feb</option> <option value=3 <?php if(3 == date("n",$rightNow)) echo "selected"; ?>>Mar</option> <option value=4 <?php if(4 == date("n",$rightNow)) echo "selected"; ?>>Apr</option> <option value=5 <?php if(5 == date("n",$rightNow)) echo "selected"; ?>>May</option> <option value=6 <?php if(6 == date("n",$rightNow)) echo "selected"; ?>>Jun</option> <option value=7 <?php if(7 == date("n",$rightNow)) echo "selected"; ?>>Jul</option> <option value=8 <?php if(8 == date("n",$rightNow)) echo "selected"; ?>>Aug</option> <option value=9 <?php if(9 == date("n",$rightNow)) echo "selected"; ?>>Sep</option> <option value=10 <?php if(10 == date("n",$rightNow)) echo "selected"; ?>>Oct</option> <option value=11 <?php if(11 == date("n",$rightNow)) echo "selected"; ?>>Nov</option> <option value=12 <?php if(12 == date("n",$rightNow)) echo "selected"; ?>>Dec</option> </select> - <input type=text value="<?php echo date("j",$rightNow); ?>" name="stopDay" id="stopDay" size="2" maxlength="2" onKeyPress="return numbersonly(this, event)"> <hr> <input type=submit value="get details"> </form> </body> </html> |