Viewing File server/web/history.test.php of 0.02.53a
|
1: <?php 2: /* ------------------------------------------------------------- 3: This file is part of FreeNATS 4: 5: FreeNATS is (C) Copyright 2008 PurplePixie Systems 6: 7: FreeNATS is free software: you can redistribute it and/or modify 8: it under the terms of the GNU General Public License as published by 9: the Free Software Foundation, either version 3 of the License, or 10: (at your option) any later version. 11: 12: FreeNATS is distributed in the hope that it will be useful, 13: but WITHOUT ANY WARRANTY; without even the implied warranty of 14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15: GNU General Public License for more details. 16: 17: You should have received a copy of the GNU General Public License 18: along with FreeNATS. If not, see www.gnu.org/licenses 19: 20: For more information see www.purplepixie.org/freenats 21: -------------------------------------------------------------- */ 22: 23: ob_start(); 24: require("include.php"); 25: $NATS->Start(); 26: if (!$NATS_Session->Check($NATS->DB)) 27: { 28: header("Location: ./?login_msg=Invalid+Or+Expired+Session"); 29: exit(); 30: } 31: if ($NATS_Session->userlevel<1) UL_Error("View Test History"); 32: 33: $tmode=""; 34: switch($_REQUEST['testid'][0]) 35: { 36: case "L": $tmode="local"; 37: break; 38: default: $tmode="unknown"; 39: } 40: $stid=substr($_REQUEST['testid'],1,128); 41: 42: // get test info 43: $tnode=""; 44: $tname=""; 45: $ttype=""; 46: $tparam=""; 47: $tlastrunx=""; 48: $trecord=1; 49: 50: $q=""; 51: if ($tmode=="local") $q="SELECT * FROM fnlocaltest WHERE localtestid=".ss($stid); 52: 53: $r=$NATS->DB->Query($q); 54: 55: if (!$row=$NATS->DB->Fetch_Array($r)) 56: { 57: header("main.php?message=Error+opening+test+history"); 58: exit(); 59: } 60: 61: $tnode=$row['nodeid']; 62: $ttype=$row['testtype']; 63: $tparam=$row['testparam']; 64: $tlastrunx=$row['lastrunx']; 65: $tname=lText($ttype); 66: $tunit=lUnit($ttype); 67: if ($tparam!="") $tname.=" (".$tparam.")"; 68: $NATS->DB->Free($r); 69: Screen_Header("History for ".$tname." on ".$tnode,1); 70: ob_end_flush(); 71: 72: $td_day=date("d"); 73: $td_mon=date("m"); 74: $td_yr=date("Y"); 75: 76: $start=array(); 77: $finish=array(); 78: if (isset($_REQUEST['st_day'])) $start['day']=$_REQUEST['st_day']; 79: else $start['day']=$td_day; 80: if (isset($_REQUEST['st_mon'])) $start['mon']=$_REQUEST['st_mon']; 81: else $start['mon']=$td_mon; 82: if (isset($_REQUEST['st_yr'])) $start['yr']=$_REQUEST['st_yr']; 83: else $start['yr']=$td_yr; 84: if (isset($_REQUEST['st_hour'])) $start['hour']=$_REQUEST['st_hour']; 85: else $start['hour']=0; 86: if (isset($_REQUEST['st_min'])) $start['min']=$_REQUEST['st_min']; 87: else $start['min']=0; 88: if (isset($_REQUEST['st_sec'])) $start['sec']=$_REQUEST['st_sec']; 89: else $start['sec']=0; 90: 91: if (isset($_REQUEST['fi_day'])) $finish['day']=$_REQUEST['fi_day']; 92: else $finish['day']=$td_day; 93: if (isset($_REQUEST['fi_mon'])) $finish['mon']=$_REQUEST['fi_mon']; 94: else $finish['mon']=$td_mon; 95: if (isset($_REQUEST['fi_yr'])) $finish['yr']=$_REQUEST['fi_yr']; 96: else $finish['yr']=$td_yr; 97: if (isset($_REQUEST['fi_hour'])) $finish['hour']=$_REQUEST['fi_hour']; 98: else $finish['hour']=23; 99: if (isset($_REQUEST['fi_min'])) $finish['min']=$_REQUEST['fi_min']; 100: else $finish['min']=59; 101: if (isset($_REQUEST['fi_sec'])) $finish['sec']=$_REQUEST['fi_sec']; 102: else $finish['sec']=59; 103: 104: if (isset($_REQUEST['startx'])) 105: { 106: $start['day']=date("d",$_REQUEST['startx']); 107: $start['mon']=date("m",$_REQUEST['startx']); 108: $start['yr']=date("Y",$_REQUEST['startx']); 109: $start['hour']=date("H",$_REQUEST['startx']); 110: $start['min']=date("i",$_REQUEST['startx']); 111: $start['sec']=date("s",$_REQUEST['startx']); 112: $startx=$_REQUEST['startx']; 113: } 114: else 115: $startx=mktime($start['hour'],$start['min'],$start['sec'],$start['mon'],$start['day'],$start['yr']); 116: 117: if (isset($_REQUEST['finishx'])) 118: { 119: $finish['day']=date("d",$_REQUEST['finishx']); 120: $finish['mon']=date("m",$_REQUEST['finishx']); 121: $finish['yr']=date("Y",$_REQUEST['finishx']); 122: $finish['hour']=date("H",$_REQUEST['finishx']); 123: $finish['min']=date("i",$_REQUEST['finishx']); 124: $finish['sec']=date("s",$_REQUEST['finishx']); 125: $finishx=$_REQUEST['finishx']; 126: } 127: else 128: $finishx=mktime($finish['hour'],$finish['min'],$finish['sec'],$finish['mon'],$finish['day'],$finish['yr']); 129: //echo $startx." ".nicedt($startx)."<br>"; 130: //echo $finishx." ".nicedt($finishx)."<br>"; 131: 132: $diffx=$finishx-$startx; 133: $periods=8; 134: $periodx=$diffx/$periods; 135: $hperiodx=round($periodx/2,0); 136: $periodx=round($periodx,0); 137: $iwid=700; 138: $ihei=150; 139: $istart=50; 140: $iend=$iwid-5; 141: $idwid=$iend-$istart; 142: $iscale=$idwid/$periods; 143: 144: $zoom=array(); 145: for ($a=0; $a<$periods; $a++) 146: { 147: $x=($a*$periodx)+$hperiodx+$startx; 148: $zoom[$a]['startx']=$x-$periodx; 149: $zoom[$a]['finishx']=$x+$periodx; 150: $zoom[$a]['istart']=round($istart+($a*$iscale),0); 151: $zoom[$a]['ifinish']=round($istart+($a*$iscale)+$iscale,0); 152: } 153: 154: echo "<br><table border=0>"; 155: echo "<tr><td align=left valign=top>"; 156: 157: echo "<map id=\"zoommap\" name=\"zoommap\">\n"; 158: for ($a=0; $a<$periods; $a++) 159: { 160: //echo $a." s ".nicedt($zoom[$a]['startx'])." f ".nicedt($zoom[$a]['finishx'])." x ".$zoom[$a]['istart']." - ".$zoom[$a]['ifinish']."<br>"; 161: $s="history.test.php?nodeid=".$tnode."&testid=".$_REQUEST['testid']."&startx=".$zoom[$a]['startx']."&finishx=".$zoom[$a]['finishx']; 162: 163: echo "<area shape=\"rect\" coords=\"".$zoom[$a]['istart'].",0,".$zoom[$a]['ifinish'].",".$ihei."\" href=\"".$s."\">\n"; 164: 165: 166: } 167: echo "</map>\n\n"; 168: 169: echo "<b class=\"subtitle\">".$tname."</b><br>"; 170: 171: echo "<table class=\"nicetable\">"; 172: echo "<tr><td align=right>Node :</td>"; 173: echo "<td align=left><a href=node.php?nodeid=".$tnode.">".$tnode."</a>"; 174: echo "</tr></tr>"; 175: echo "<tr><td align=right valign=top>Last Run :</td>"; 176: echo "<td align=left align=top>"; 177: if ($tlastrunx>0) 178: { 179: echo nicedt($tlastrunx)."<br>"; 180: echo dtago($tlastrunx); 181: } 182: else echo "Never"; 183: echo "</td>"; 184: echo "</tr></tr>"; 185: echo "</table>"; 186: 187: echo "</td><td width=50> </td><td align=left valign=top>"; 188: 189: echo "<b><u>Reporting Period</u></b><br>"; 190: 191: echo "<table class=\"nicetable\">"; 192: echo "<tr><td> </td><td>Hour</td><td>Min</td><td>Sec</td><td>Day</td><td>Mon</td><td>Year</td></tr>"; 193: echo "<form action=history.test.php method=post>"; 194: echo "<input type=hidden name=testid value=\"".$_REQUEST['testid']."\">"; 195: 196: function slist($var,$min,$max,$val) 197: { 198: echo "\n<select name=\"".$var."\">\n"; 199: echo "<option value=\"".$val."\">".$val."</option>\n"; 200: for ($a=$min; $a<=$max; $a++) 201: echo "<option value=\"".$a."\">".$a."</option>\n"; 202: echo "</select>\n"; 203: } 204: 205: 206: echo "<tr><td><b>Start:</b></td>"; 207: echo "<td>"; 208: slist("st_hour",0,23,$start['hour']); 209: echo ":"; 210: echo "</td>"; 211: 212: echo "<td>"; 213: slist("st_min",0,59,$start['min']); 214: echo ":"; 215: echo "</td>"; 216: 217: echo "<td>"; 218: slist("st_sec",0,59,$start['sec']); 219: echo " "; 220: echo "</td>"; 221: 222: echo "<td>"; 223: slist("st_day",1,31,$start['day']); 224: echo "/"; 225: echo "</td>"; 226: 227: echo "<td>"; 228: slist("st_mon",1,12,$start['mon']); 229: echo "/"; 230: echo "</td>"; 231: 232: echo "<td>"; 233: echo "<input type=text name=st_yr value=\"".$start['yr']."\" size=5 maxlength=4>"; 234: 235: echo " <a href=history.test.php?testid=".$_REQUEST['testid'].">Today</a>"; 236: 237: echo "</td>"; 238: 239: echo "</tr>"; 240: 241: // ----- finish 242: 243: echo "<tr><td><b>Finish:</b></td>"; 244: echo "<td>"; 245: slist("fi_hour",0,23,$finish['hour']); 246: echo ":"; 247: echo "</td>"; 248: 249: echo "<td>"; 250: slist("fi_min",0,59,$finish['min']); 251: echo ":"; 252: echo "</td>"; 253: 254: echo "<td>"; 255: slist("fi_sec",0,59,$finish['sec']); 256: echo " "; 257: echo "</td>"; 258: 259: echo "<td>"; 260: slist("fi_day",1,31,$finish['day']); 261: echo "/"; 262: echo "</td>"; 263: 264: echo "<td>"; 265: slist("fi_mon",1,12,$finish['mon']); 266: echo "/"; 267: echo "</td>"; 268: 269: echo "<td>"; 270: echo "<input type=text name=fi_yr value=\"".$finish['yr']."\" size=5 maxlength=4>"; 271: 272: echo " <input type=submit value=Go>"; 273: 274: echo "</td>"; 275: 276: echo "</tr>"; 277: 278: // 7 279: echo "<tr><td><b>Opts:</b></td>"; 280: echo "<td colspan=\"6\">"; 281: function cbd($var,$name) 282: { 283: if (isset($_REQUEST[$var])) $s=" checked"; 284: else $s=""; 285: echo "<input type=checkbox name=\"".$var."\" value=1".$s."> ".$name; 286: } 287: cbd("disp_hdata","Hide Data"); 288: echo " "; 289: cbd("disp_pass","Show Passed"); 290: echo " "; 291: cbd("hide_graph","Hide Graph"); 292: echo "</td></tr>"; 293: 294: echo "</form>"; 295: echo "</table>"; 296: 297: echo "</td></tr></table>"; 298: 299: echo "<br><br>"; 300: 301: echo "<b>".$tname." from ".nicedt($startx)." to ".nicedt($finishx); 302: if ($tunit!="") echo " (".$tunit.")"; 303: // echo " (".nicediff($finishx-$startx).")"; 304: echo "</b><br><br>"; 305: 306: // graph data 307: if (!isset($_REQUEST['hide_graph'])) 308: { 309: mt_srand(microtime()*1000000); 310: $i=mt_rand(1000,1000000); 311: echo "<img src=\"test.graph.php?testid=".$_REQUEST['testid']."&startx=".$startx."&finishx=".$finishx."&nodeid=".$tnode."&i=".$i."\" border=0 usemap=\"#zoommap\"><br><br>"; 312: } 313: 314: // table data 315: 316: 317: $q="SELECT alertlevel,testvalue,recordx FROM fnrecord WHERE "; 318: $q.="testid=\"".ss($_REQUEST['testid'])."\" AND recordx>=".$startx." AND recordx<=".$finishx; 319: //if (!isset($_REQUEST['disp_pass'])) $q.=" AND alertlevel!=0"; 320: $q.=" ORDER BY recordx DESC"; 321: //echo $q; 322: $r=$NATS->DB->Query($q); 323: 324: $testc=0; 325: $tested=0; 326: $untested=0; 327: $passc=0; 328: $warnc=0; 329: $failc=0; 330: $levelt=0; 331: 332: echo "<table class=\"nicetable\">"; 333: while ($row=$NATS->DB->Fetch_Array($r)) 334: { 335: if ( (isset($_REQUEST['disp_pass']) || ($row['alertlevel']!=0) ) && (!isset($_REQUEST['disp_hdata'])) ) 336: { 337: echo "<tr><td>".nicedt($row['recordx'])."</td>"; 338: echo "<td><b class=\"al".$row['alertlevel']."\">".oText($row['alertlevel'])."</b></td>"; 339: echo "<td>".$row['testvalue']."</td>"; 340: echo "</tr>"; 341: } 342: $testc++; 343: switch ($row['alertlevel']) 344: { 345: case 0: 346: $passc++; 347: $tested++; 348: $levelt+=$row['testvalue']; 349: break; 350: case 1: 351: $warnc++; 352: $tested++; 353: $levelt+=$row['testvalue']; 354: break; 355: case 2: 356: $failc++; 357: $tested++; 358: $levelt+=$row['testvalue']; 359: break; 360: case -1: 361: $untested++; 362: break; 363: } 364: } 365: 366: echo "</tr>"; 367: echo "</table>"; 368: 369: echo "<br><br>"; 370: echo "<table border=0>"; 371: 372: function np($big,$part) 373: { 374: if ($big==0) return "n/a"; 375: if ($part==0) return "0%"; 376: 377: $p=($part/$big)*100; 378: $p=round($p,2); 379: return $p."%"; 380: } 381: 382: 383: echo "<tr><td>".$passc." passed out of ".$tested." valid tests"; 384: echo "</td><td> </td><td>"; 385: echo np($tested,$passc); 386: echo "</td></tr>"; 387: 388: $notpass=$tested-$passc; 389: 390: echo "<tr><td>".$notpass." did not pass out of ".$tested." valid tests"; 391: echo "</td><td> </td><td>"; 392: echo np($tested,$notpass); 393: echo "</td></tr>"; 394: 395: echo "<tr><td colspan=3> <br></td></tr>"; 396: 397: echo "<tr><td>".$warnc." generated warnings out of ".$tested." valid tests"; 398: echo "</td><td> </td><td>"; 399: echo np($tested,$warnc); 400: echo "</td></tr>"; 401: 402: echo "<tr><td>".$failc." generated failures out of ".$tested." valid tests"; 403: echo "</td><td> </td><td>"; 404: echo np($tested,$failc); 405: echo "</td></tr>"; 406: 407: echo "<tr><td>".$warnc." generated warnings out of ".$notpass." unpassed tests"; 408: echo "</td><td> </td><td>"; 409: echo np($notpass,$warnc); 410: echo "</td></tr>"; 411: 412: echo "<tr><td>".$failc." generated failures out of ".$notpass." unpassed tests"; 413: echo "</td><td> </td><td>"; 414: echo np($notpass,$failc); 415: echo "</td></tr>"; 416: 417: echo "<tr><td colspan=3> <br></td></tr>"; 418: 419: echo "<tr><td>the average test value returned by valid tests was</td>"; 420: echo "<td> </td><td>"; 421: if ($tested<=0) echo "n/a"; 422: else if ($levelt==0) echo "0"; 423: else echo round($levelt/$tested,4); 424: if ($tunit!="") echo " ".$tunit; 425: echo "</td></tr>"; 426: 427: echo "<tr><td colspan=3> <br></td></tr>"; 428: 429: $utt=$untested+$tested; 430: echo "<tr><td>".$untested." tests were untested (of ".$utt.")</td>"; 431: echo "<td> </td><td>"; 432: echo np($utt,$untested); 433: echo "</td></tr>"; 434: 435: $npt=$untested+$notpass; 436: echo "<tr><td>of these (".$utt.") ".$npt." did not pass</td>"; 437: echo "<td> </td><td>"; 438: echo np($utt,$npt); 439: echo "</td></tr>"; 440: 441: echo "<tr><td>of these (".$utt.") ".$passc." did pass</td>"; 442: echo "<td> </td><td>"; 443: echo np($utt,$passc); 444: echo "</td></tr>"; 445: 446: echo "<tr><td colspan=3> <br></td></tr>"; 447: 448: echo "<tr><td>".$testc." records of which ".$tested." returned a valid alert level"; 449: echo "</td><td> </td><td>"; 450: echo np($testc,$tested); 451: echo "</td></tr>"; 452: 453: $nowx=time(); 454: if ($finishx>$nowx) $fx=$nowx; 455: else $fx=$finishx; 456: $p=$fx-$startx; 457: $five_min=60*5; 458: $shouldhave=floor($p/$five_min); 459: 460: 461: echo "<tr><td>".$testc." records and you <i>should have</i> ".hlink("History:Should",12)." ".$shouldhave; 462: echo "</td><td> </td><td>"; 463: echo np($shouldhave,$testc); 464: echo "</td></tr>"; 465: 466: echo "</table><br>"; 467: 468: /* - zoom period debugging 469: echo "Period: $p s (".($p/$five_min).")<br>"; 470: echo "sx: ".$startx." fx: ".$finishx."<br>"; 471: echo "diffx: ".($finishx-$startx)."<br>"; 472: echo "fx2: ".$fx." p: ".$p."<br>"; 473: */ 474: Screen_Footer(); 475: ?> 476: