Viewing File server/web/history.test.php of 0.02.77a
|
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: if ($row['testname']!="") 69: { 70: $subtname=$tname; 71: $tname=$row['testname']; 72: $usesubname=true; 73: } 74: else $usesubname=false; 75: $NATS->DB->Free($r); 76: Screen_Header("History for ".$tname." on ".$tnode,1); 77: ob_end_flush(); 78: 79: $td_day=date("d"); 80: $td_mon=date("m"); 81: $td_yr=date("Y"); 82: 83: $start=array(); 84: $finish=array(); 85: if (isset($_REQUEST['st_day'])) $start['day']=$_REQUEST['st_day']; 86: else $start['day']=$td_day; 87: if (isset($_REQUEST['st_mon'])) $start['mon']=$_REQUEST['st_mon']; 88: else $start['mon']=$td_mon; 89: if (isset($_REQUEST['st_yr'])) $start['yr']=$_REQUEST['st_yr']; 90: else $start['yr']=$td_yr; 91: if (isset($_REQUEST['st_hour'])) $start['hour']=$_REQUEST['st_hour']; 92: else $start['hour']=0; 93: if (isset($_REQUEST['st_min'])) $start['min']=$_REQUEST['st_min']; 94: else $start['min']=0; 95: if (isset($_REQUEST['st_sec'])) $start['sec']=$_REQUEST['st_sec']; 96: else $start['sec']=0; 97: 98: if (isset($_REQUEST['fi_day'])) $finish['day']=$_REQUEST['fi_day']; 99: else $finish['day']=$td_day; 100: if (isset($_REQUEST['fi_mon'])) $finish['mon']=$_REQUEST['fi_mon']; 101: else $finish['mon']=$td_mon; 102: if (isset($_REQUEST['fi_yr'])) $finish['yr']=$_REQUEST['fi_yr']; 103: else $finish['yr']=$td_yr; 104: if (isset($_REQUEST['fi_hour'])) $finish['hour']=$_REQUEST['fi_hour']; 105: else $finish['hour']=23; 106: if (isset($_REQUEST['fi_min'])) $finish['min']=$_REQUEST['fi_min']; 107: else $finish['min']=59; 108: if (isset($_REQUEST['fi_sec'])) $finish['sec']=$_REQUEST['fi_sec']; 109: else $finish['sec']=59; 110: 111: if (isset($_REQUEST['startx'])) 112: { 113: $start['day']=date("d",$_REQUEST['startx']); 114: $start['mon']=date("m",$_REQUEST['startx']); 115: $start['yr']=date("Y",$_REQUEST['startx']); 116: $start['hour']=date("H",$_REQUEST['startx']); 117: $start['min']=date("i",$_REQUEST['startx']); 118: $start['sec']=date("s",$_REQUEST['startx']); 119: $startx=$_REQUEST['startx']; 120: } 121: else 122: $startx=mktime($start['hour'],$start['min'],$start['sec'],$start['mon'],$start['day'],$start['yr']); 123: 124: if (isset($_REQUEST['finishx'])) 125: { 126: $finish['day']=date("d",$_REQUEST['finishx']); 127: $finish['mon']=date("m",$_REQUEST['finishx']); 128: $finish['yr']=date("Y",$_REQUEST['finishx']); 129: $finish['hour']=date("H",$_REQUEST['finishx']); 130: $finish['min']=date("i",$_REQUEST['finishx']); 131: $finish['sec']=date("s",$_REQUEST['finishx']); 132: $finishx=$_REQUEST['finishx']; 133: } 134: else 135: $finishx=mktime($finish['hour'],$finish['min'],$finish['sec'],$finish['mon'],$finish['day'],$finish['yr']); 136: //echo $startx." ".nicedt($startx)."<br>"; 137: //echo $finishx." ".nicedt($finishx)."<br>"; 138: 139: $diffx=$finishx-$startx; 140: $periods=8; 141: $periodx=$diffx/$periods; 142: $hperiodx=round($periodx/2,0); 143: $periodx=round($periodx,0); 144: $iwid=700; 145: $ihei=150; 146: $istart=50; 147: $iend=$iwid-5; 148: $idwid=$iend-$istart; 149: $iscale=$idwid/$periods; 150: 151: $zoom=array(); 152: for ($a=0; $a<$periods; $a++) 153: { 154: $x=($a*$periodx)+$hperiodx+$startx; 155: $zoom[$a]['startx']=$x-$periodx; 156: $zoom[$a]['finishx']=$x+$periodx; 157: $zoom[$a]['istart']=round($istart+($a*$iscale),0); 158: $zoom[$a]['ifinish']=round($istart+($a*$iscale)+$iscale,0); 159: } 160: 161: echo "<br><table border=0>"; 162: echo "<tr><td align=left valign=top>"; 163: 164: echo "<map id=\"zoommap\" name=\"zoommap\">\n"; 165: for ($a=0; $a<$periods; $a++) 166: { 167: //echo $a." s ".nicedt($zoom[$a]['startx'])." f ".nicedt($zoom[$a]['finishx'])." x ".$zoom[$a]['istart']." - ".$zoom[$a]['ifinish']."<br>"; 168: $s="history.test.php?nodeid=".$tnode."&testid=".$_REQUEST['testid']."&startx=".$zoom[$a]['startx']."&finishx=".$zoom[$a]['finishx']; 169: 170: echo "<area shape=\"rect\" coords=\"".$zoom[$a]['istart'].",0,".$zoom[$a]['ifinish'].",".$ihei."\" href=\"".$s."\">\n"; 171: 172: 173: } 174: echo "</map>\n\n"; 175: 176: echo "<b class=\"subtitle\">".$tname."</b><br>"; 177: if ($usesubname) echo "<b>".$subtname."</b><br>"; 178: 179: echo "<table class=\"nicetable\">"; 180: echo "<tr><td align=right>Node :</td>"; 181: echo "<td align=left><a href=node.php?nodeid=".$tnode.">".$tnode."</a>"; 182: echo "</tr></tr>"; 183: echo "<tr><td align=right valign=top>Last Run :</td>"; 184: echo "<td align=left align=top>"; 185: if ($tlastrunx>0) 186: { 187: echo nicedt($tlastrunx)."<br>"; 188: echo dtago($tlastrunx); 189: } 190: else echo "Never"; 191: echo "</td>"; 192: echo "</tr></tr>"; 193: echo "</table>"; 194: 195: echo "</td><td width=50> </td><td align=left valign=top>"; 196: 197: echo "<b><u>Reporting Period</u></b><br>"; 198: 199: echo "<table class=\"nicetable\">"; 200: echo "<tr><td> </td><td>Hour</td><td>Min</td><td>Sec</td><td>Day</td><td>Mon</td><td>Year</td></tr>"; 201: echo "<form action=history.test.php method=post>"; 202: echo "<input type=hidden name=testid value=\"".$_REQUEST['testid']."\">"; 203: 204: function slist($var,$min,$max,$val) 205: { 206: echo "\n<select name=\"".$var."\">\n"; 207: echo "<option value=\"".$val."\">".$val."</option>\n"; 208: for ($a=$min; $a<=$max; $a++) 209: echo "<option value=\"".$a."\">".$a."</option>\n"; 210: echo "</select>\n"; 211: } 212: 213: 214: echo "<tr><td><b>Start:</b></td>"; 215: echo "<td>"; 216: slist("st_hour",0,23,$start['hour']); 217: echo ":"; 218: echo "</td>"; 219: 220: echo "<td>"; 221: slist("st_min",0,59,$start['min']); 222: echo ":"; 223: echo "</td>"; 224: 225: echo "<td>"; 226: slist("st_sec",0,59,$start['sec']); 227: echo " "; 228: echo "</td>"; 229: 230: echo "<td>"; 231: slist("st_day",1,31,$start['day']); 232: echo "/"; 233: echo "</td>"; 234: 235: echo "<td>"; 236: slist("st_mon",1,12,$start['mon']); 237: echo "/"; 238: echo "</td>"; 239: 240: echo "<td>"; 241: echo "<input type=text name=st_yr value=\"".$start['yr']."\" size=5 maxlength=4>"; 242: 243: echo " <a href=history.test.php?testid=".$_REQUEST['testid'].">Today</a>"; 244: 245: echo "</td>"; 246: 247: echo "</tr>"; 248: 249: // ----- finish 250: 251: echo "<tr><td><b>Finish:</b></td>"; 252: echo "<td>"; 253: slist("fi_hour",0,23,$finish['hour']); 254: echo ":"; 255: echo "</td>"; 256: 257: echo "<td>"; 258: slist("fi_min",0,59,$finish['min']); 259: echo ":"; 260: echo "</td>"; 261: 262: echo "<td>"; 263: slist("fi_sec",0,59,$finish['sec']); 264: echo " "; 265: echo "</td>"; 266: 267: echo "<td>"; 268: slist("fi_day",1,31,$finish['day']); 269: echo "/"; 270: echo "</td>"; 271: 272: echo "<td>"; 273: slist("fi_mon",1,12,$finish['mon']); 274: echo "/"; 275: echo "</td>"; 276: 277: echo "<td>"; 278: echo "<input type=text name=fi_yr value=\"".$finish['yr']."\" size=5 maxlength=4>"; 279: 280: echo " <input type=submit value=Go>"; 281: 282: echo "</td>"; 283: 284: echo "</tr>"; 285: 286: // 7 287: echo "<tr><td><b>Opts:</b></td>"; 288: echo "<td colspan=\"6\">"; 289: function cbd($var,$name) 290: { 291: if (isset($_REQUEST[$var])) $s=" checked"; 292: else $s=""; 293: echo "<input type=checkbox name=\"".$var."\" value=1".$s."> ".$name; 294: } 295: cbd("disp_hdata","Hide Data"); 296: echo " "; 297: cbd("disp_pass","Show Passed"); 298: echo " "; 299: cbd("hide_graph","Hide Graph"); 300: echo "</td></tr>"; 301: 302: echo "</form>"; 303: echo "</table>"; 304: 305: echo "</td></tr></table>"; 306: 307: echo "<br><br>"; 308: 309: echo "<b>".$tname." from ".nicedt($startx)." to ".nicedt($finishx); 310: if ($tunit!="") echo " (".$tunit.")"; 311: // echo " (".nicediff($finishx-$startx).")"; 312: echo "</b><br><br>"; 313: 314: // graph data 315: if (!isset($_REQUEST['hide_graph'])) 316: { 317: mt_srand(microtime()*1000000); 318: $i=mt_rand(1000,1000000); 319: echo "<img src=\"test.graph.php?testid=".$_REQUEST['testid']."&startx=".$startx."&finishx=".$finishx."&nodeid=".$tnode."&i=".$i."\" border=0 usemap=\"#zoommap\"><br><br>"; 320: } 321: 322: // table data 323: 324: 325: $q="SELECT alertlevel,testvalue,recordx FROM fnrecord WHERE "; 326: $q.="testid=\"".ss($_REQUEST['testid'])."\" AND recordx>=".$startx." AND recordx<=".$finishx; 327: //if (!isset($_REQUEST['disp_pass'])) $q.=" AND alertlevel!=0"; 328: $q.=" ORDER BY recordx DESC"; 329: //echo $q; 330: $r=$NATS->DB->Query($q); 331: 332: $testc=0; 333: $tested=0; 334: $untested=0; 335: $passc=0; 336: $warnc=0; 337: $failc=0; 338: $levelt=0; 339: 340: echo "<table class=\"nicetable\">"; 341: while ($row=$NATS->DB->Fetch_Array($r)) 342: { 343: if ( (isset($_REQUEST['disp_pass']) || ($row['alertlevel']!=0) ) && (!isset($_REQUEST['disp_hdata'])) ) 344: { 345: echo "<tr><td>".nicedt($row['recordx'])."</td>"; 346: echo "<td><b class=\"al".$row['alertlevel']."\">".oText($row['alertlevel'])."</b></td>"; 347: echo "<td>".$row['testvalue']."</td>"; 348: echo "</tr>"; 349: } 350: $testc++; 351: switch ($row['alertlevel']) 352: { 353: case 0: 354: $passc++; 355: $tested++; 356: $levelt+=$row['testvalue']; 357: break; 358: case 1: 359: $warnc++; 360: $tested++; 361: $levelt+=$row['testvalue']; 362: break; 363: case 2: 364: $failc++; 365: $tested++; 366: $levelt+=$row['testvalue']; 367: break; 368: case -1: 369: $untested++; 370: break; 371: } 372: } 373: 374: echo "</tr>"; 375: echo "</table>"; 376: 377: echo "<br><br>"; 378: echo "<table border=0>"; 379: 380: function np($big,$part) 381: { 382: if ($big==0) return "n/a"; 383: if ($part==0) return "0%"; 384: 385: $p=($part/$big)*100; 386: $p=round($p,2); 387: return $p."%"; 388: } 389: 390: 391: echo "<tr><td>".$passc." passed out of ".$tested." valid tests"; 392: echo "</td><td> </td><td>"; 393: echo np($tested,$passc); 394: echo "</td></tr>"; 395: 396: $notpass=$tested-$passc; 397: 398: echo "<tr><td>".$notpass." did not pass out of ".$tested." valid tests"; 399: echo "</td><td> </td><td>"; 400: echo np($tested,$notpass); 401: echo "</td></tr>"; 402: 403: echo "<tr><td colspan=3> <br></td></tr>"; 404: 405: echo "<tr><td>".$warnc." generated warnings out of ".$tested." valid tests"; 406: echo "</td><td> </td><td>"; 407: echo np($tested,$warnc); 408: echo "</td></tr>"; 409: 410: echo "<tr><td>".$failc." generated failures out of ".$tested." valid tests"; 411: echo "</td><td> </td><td>"; 412: echo np($tested,$failc); 413: echo "</td></tr>"; 414: 415: echo "<tr><td>".$warnc." generated warnings out of ".$notpass." unpassed tests"; 416: echo "</td><td> </td><td>"; 417: echo np($notpass,$warnc); 418: echo "</td></tr>"; 419: 420: echo "<tr><td>".$failc." generated failures out of ".$notpass." unpassed tests"; 421: echo "</td><td> </td><td>"; 422: echo np($notpass,$failc); 423: echo "</td></tr>"; 424: 425: echo "<tr><td colspan=3> <br></td></tr>"; 426: 427: echo "<tr><td>the average test value returned by valid tests was</td>"; 428: echo "<td> </td><td>"; 429: if ($tested<=0) echo "n/a"; 430: else if ($levelt==0) echo "0"; 431: else echo round($levelt/$tested,4); 432: if ($tunit!="") echo " ".$tunit; 433: echo "</td></tr>"; 434: 435: echo "<tr><td colspan=3> <br></td></tr>"; 436: 437: $utt=$untested+$tested; 438: echo "<tr><td>".$untested." tests were untested (of ".$utt.")</td>"; 439: echo "<td> </td><td>"; 440: echo np($utt,$untested); 441: echo "</td></tr>"; 442: 443: $npt=$untested+$notpass; 444: echo "<tr><td>of these (".$utt.") ".$npt." did not pass</td>"; 445: echo "<td> </td><td>"; 446: echo np($utt,$npt); 447: echo "</td></tr>"; 448: 449: echo "<tr><td>of these (".$utt.") ".$passc." did pass</td>"; 450: echo "<td> </td><td>"; 451: echo np($utt,$passc); 452: echo "</td></tr>"; 453: 454: echo "<tr><td colspan=3> <br></td></tr>"; 455: 456: echo "<tr><td>".$testc." records of which ".$tested." returned a valid alert level"; 457: echo "</td><td> </td><td>"; 458: echo np($testc,$tested); 459: echo "</td></tr>"; 460: 461: $nowx=time(); 462: if ($finishx>$nowx) $fx=$nowx; 463: else $fx=$finishx; 464: $p=$fx-$startx; 465: $five_min=60*5; 466: $shouldhave=floor($p/$five_min); 467: 468: 469: echo "<tr><td>".$testc." records and you <i>should have</i> ".hlink("History:Should",12)." ".$shouldhave; 470: echo "</td><td> </td><td>"; 471: echo np($shouldhave,$testc); 472: echo "</td></tr>"; 473: 474: echo "</table><br>"; 475: 476: /* - zoom period debugging 477: echo "Period: $p s (".($p/$five_min).")<br>"; 478: echo "sx: ".$startx." fx: ".$finishx."<br>"; 479: echo "diffx: ".($finishx-$startx)."<br>"; 480: echo "fx2: ".$fx." p: ".$p."<br>"; 481: */ 482: Screen_Footer(); 483: ?> 484: