File: 1.12.0a/server/web/history.test.php (View as Code)

1: 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: case "N": $tmode="nodeside"; 39: break; 40: default: $tmode="unknown"; 41: } 42: $stid=substr($_REQUEST['testid'],1,128); 43: 44: // get test info 45: $tnode=""; 46: $tname=""; 47: $ttype=""; 48: $tparam=""; 49: $tlastrunx=""; 50: $trecord=1; 51: 52: $q=""; 53: if ($tmode=="local") $q="SELECT * FROM fnlocaltest WHERE localtestid=".ss($stid); 54: else if ($tmode=="nodeside") $q="SELECT * FROM fnnstest WHERE nstestid=".ss($stid); 55: 56: $r=$NATS->DB->Query($q); 57: 58: if (!$row=$NATS->DB->Fetch_Array($r)) 59: { 60: header("main.php?message=Error+opening+test+history"); 61: exit(); 62: } 63: 64: 65: // This bit handles up-front the test interval stuff i.e. which is the interval that 66: // the test "should run" at 67: 68: $nodedata=$NATS->GetNode($row['nodeid']); // first load the data for the node 69: $show_expected_number=false; // show the expected number or not 70: $tinterval=0; // fallback zero 71: if ($tmode=="local") 72: { 73: $tinterval=$row['testinterval']; 74: if ($nodedata['testinterval']>$tinterval) $tinvteral=$ndoedata['testinterval']; 75: // for a local test use the test's interval or the node's, whichever is higher 76: $show_expected_number=true; 77: } 78: else if ($tmode=="nodeside") 79: { 80: if ( ($nodedata['nsenabled']==1) && ($nodedata['nspullenabled']==1) ) 81: { // is nodedside and test is PULLED 82: $tinterval=$nodedata['nsinterval']; 83: $show_expected_number=true; 84: } 85: } 86: if ($tinterval<1) $tinterval=1; // default one minute assumption 87: 88: // End of test interval bits 89: 90: $tnode=$row['nodeid']; 91: $ttype=$row['testtype']; 92: if ($tmode=="local") 93: { 94: $tparam=$row['testparam']; 95: $tlastrunx=$row['lastrunx']; 96: $tname=lText($ttype); 97: $tunit=lUnit($ttype); 98: if ($tparam!="") $tname.=" (".$tparam.")"; 99: if ($row['testname']!="") 100: { 101: $subtname=$tname; 102: $tname=$row['testname']; 103: $usesubname=true; 104: } 105: else $usesubname=false; 106: } 107: else if ($tmode=="nodeside") 108: { 109: $tlastrunx=$row['lastrunx']; 110: if ($row['testname']!="") $tname=$row['testname']; 111: else $tname=$row['testtype']; 112: $subtname=$row['testdesc']; 113: $usesubname=true; 114: $tunit=""; 115: } 116: $NATS->DB->Free($r); 117: Screen_Header("History for ".$tname." on ".$tnode,1); 118: ob_end_flush(); 119: 120: $td_day=date("d"); 121: $td_mon=date("m"); 122: $td_yr=date("Y"); 123: 124: $start=array(); 125: $finish=array(); 126: if (isset($_REQUEST['st_day'])) $start['day']=$_REQUEST['st_day']; 127: else $start['day']=$td_day; 128: if (isset($_REQUEST['st_mon'])) $start['mon']=$_REQUEST['st_mon']; 129: else $start['mon']=$td_mon; 130: if (isset($_REQUEST['st_yr'])) $start['yr']=$_REQUEST['st_yr']; 131: else $start['yr']=$td_yr; 132: if (isset($_REQUEST['st_hour'])) $start['hour']=$_REQUEST['st_hour']; 133: else $start['hour']=0; 134: if (isset($_REQUEST['st_min'])) $start['min']=$_REQUEST['st_min']; 135: else $start['min']=0; 136: if (isset($_REQUEST['st_sec'])) $start['sec']=$_REQUEST['st_sec']; 137: else $start['sec']=0; 138: 139: if (isset($_REQUEST['fi_day'])) $finish['day']=$_REQUEST['fi_day']; 140: else $finish['day']=$td_day; 141: if (isset($_REQUEST['fi_mon'])) $finish['mon']=$_REQUEST['fi_mon']; 142: else $finish['mon']=$td_mon; 143: if (isset($_REQUEST['fi_yr'])) $finish['yr']=$_REQUEST['fi_yr']; 144: else $finish['yr']=$td_yr; 145: if (isset($_REQUEST['fi_hour'])) $finish['hour']=$_REQUEST['fi_hour']; 146: else $finish['hour']=23; 147: if (isset($_REQUEST['fi_min'])) $finish['min']=$_REQUEST['fi_min']; 148: else $finish['min']=59; 149: if (isset($_REQUEST['fi_sec'])) $finish['sec']=$_REQUEST['fi_sec']; 150: else $finish['sec']=59; 151: 152: if (isset($_REQUEST['startx'])) 153: { 154: $start['day']=date("d",$_REQUEST['startx']); 155: $start['mon']=date("m",$_REQUEST['startx']); 156: $start['yr']=date("Y",$_REQUEST['startx']); 157: $start['hour']=date("H",$_REQUEST['startx']); 158: $start['min']=date("i",$_REQUEST['startx']); 159: $start['sec']=date("s",$_REQUEST['startx']); 160: $startx=$_REQUEST['startx']; 161: } 162: else 163: $startx=mktime($start['hour'],$start['min'],$start['sec'],$start['mon'],$start['day'],$start['yr']); 164: 165: if (isset($_REQUEST['finishx'])) 166: { 167: $finish['day']=date("d",$_REQUEST['finishx']); 168: $finish['mon']=date("m",$_REQUEST['finishx']); 169: $finish['yr']=date("Y",$_REQUEST['finishx']); 170: $finish['hour']=date("H",$_REQUEST['finishx']); 171: $finish['min']=date("i",$_REQUEST['finishx']); 172: $finish['sec']=date("s",$_REQUEST['finishx']); 173: $finishx=$_REQUEST['finishx']; 174: } 175: else 176: $finishx=mktime($finish['hour'],$finish['min'],$finish['sec'],$finish['mon'],$finish['day'],$finish['yr']); 177: //echo $startx." ".nicedt($startx)."
";
178: //echo $finishx." ".nicedt($finishx)."
";
179: 180: $diffx=$finishx-$startx; 181: $periods=8; 182: $periodx=$diffx/$periods; 183: $hperiodx=round($periodx/2,0); 184: $periodx=round($periodx,0); 185: $iwid=700; 186: $ihei=150; 187: $istart=50; 188: $iend=$iwid-5; 189: $idwid=$iend-$istart; 190: $iscale=$idwid/$periods; 191: 192: $zoom=array(); 193: for ($a=0; $a<$periods; $a++) 194: { 195: $x=($a*$periodx)+$hperiodx+$startx; 196: $zoom[$a]['startx']=$x-$periodx; 197: $zoom[$a]['finishx']=$x+$periodx; 198: $zoom[$a]['istart']=round($istart+($a*$iscale),0); 199: $zoom[$a]['ifinish']=round($istart+($a*$iscale)+$iscale,0); 200: } 201: 202: echo "
"; 203: echo "
"; 204: 205: echo "\n"; 206: for ($a=0; $a<$periods; $a++) 207: { 208: //echo $a." s ".nicedt($zoom[$a]['startx'])." f ".nicedt($zoom[$a]['finishx'])." x ".$zoom[$a]['istart']." - ".$zoom[$a]['ifinish']."
";
209: $s="history.test.php?nodeid=".$tnode."&testid=".$_REQUEST['testid']."&startx=".$zoom[$a]['startx']."&finishx=".$zoom[$a]['finishx']; 210: 211: echo "\n"; 212: 213: 214: } 215: echo "\n\n"; 216: 217: echo "".$tname."
";
218: if ($usesubname) echo "".$subtname."
";
219: 220: echo ""; 221: echo ""; 222: echo ""; 224: echo ""; 225: echo ""; 233: echo ""; 234: echo "
Node :".$tnode.""; 223: echo "
Last Run :"; 226: if ($tlastrunx>0) 227: { 228: echo nicedt($tlastrunx)."
";
229: echo dtago($tlastrunx); 230: } 231: else echo "Never"; 232: echo "
";
235: 236: echo "
 "; 237: 238: echo "Reporting Period
";
239: 240: echo ""; 241: echo ""; 242: echo "
";
243: echo ""; 244: 245: function slist($var,$min,$max,$val) 246: { 247: echo "\n\n"; 252: } 253: 254: 255: echo ""; 256: echo ""; 260: 261: echo ""; 265: 266: echo ""; 270: 271: echo ""; 275: 276: echo ""; 280: 281: echo ""; 287: 288: echo ""; 289: 290: // ----- finish 291: 292: echo ""; 293: echo ""; 297: 298: echo ""; 302: 303: echo ""; 307: 308: echo ""; 312: 313: echo ""; 317: 318: echo ""; 324: 325: echo ""; 326: 327: // 7 328: echo ""; 329: echo ""; 342: 343: echo ""; 344: echo "
 HourMinSecDayMonYear
Start:"; 257: slist("st_hour",0,23,$start['hour']); 258: echo ":"; 259: echo ""; 262: slist("st_min",0,59,$start['min']); 263: echo ":"; 264: echo ""; 267: slist("st_sec",0,59,$start['sec']); 268: echo "  "; 269: echo ""; 272: slist("st_day",1,31,$start['day']); 273: echo "/"; 274: echo ""; 277: slist("st_mon",1,12,$start['mon']); 278: echo "/"; 279: echo ""; 282: echo ""; 283: 284: echo " Today"; 285: 286: echo "
Finish:"; 294: slist("fi_hour",0,23,$finish['hour']); 295: echo ":"; 296: echo ""; 299: slist("fi_min",0,59,$finish['min']); 300: echo ":"; 301: echo ""; 304: slist("fi_sec",0,59,$finish['sec']); 305: echo "  "; 306: echo ""; 309: slist("fi_day",1,31,$finish['day']); 310: echo "/"; 311: echo ""; 314: slist("fi_mon",1,12,$finish['mon']); 315: echo "/"; 316: echo ""; 319: echo ""; 320: 321: echo " "; 322: 323: echo "
Opts:"; 330: function cbd($var,$name) 331: { 332: if (isset($_REQUEST[$var])) $s=" checked"; 333: else $s=""; 334: echo " ".$name; 335: } 336: cbd("disp_hdata","Hide Data"); 337: echo " "; 338: cbd("disp_pass","Show Passed"); 339: echo " "; 340: cbd("hide_graph","Hide Graph"); 341: echo "
";
345: 346: echo "
";
347: 348: echo "

";
349: 350: echo "".$tname." from ".nicedt($startx)." to ".nicedt($finishx); 351: if ($tunit!="") echo " (".$tunit.")"; 352: // echo " (".nicediff($finishx-$startx).")"; 353: echo "

";
354: 355: // graph data 356: if (!isset($_REQUEST['hide_graph'])) 357: { 358: mt_srand(microtime()*1000000); 359: $i=mt_rand(1000,1000000); 360: echo "

";
361: } 362: 363: // table data 364: 365: 366: $q="SELECT alertlevel,testvalue,recordx FROM fnrecord WHERE "; 367: $q.="testid=\"".ss($_REQUEST['testid'])."\" AND recordx>=".ss($startx)." AND recordx<=".ss($finishx); 368: //if (!isset($_REQUEST['disp_pass'])) $q.=" AND alertlevel!=0"; 369: $q.=" ORDER BY recordx DESC"; 370: //echo $q; 371: $r=$NATS->DB->Query($q); 372: 373: $testc=0; 374: $tested=0; 375: $untested=0; 376: $passc=0; 377: $warnc=0; 378: $failc=0; 379: $levelt=0; 380: 381: echo ""; 382: while ($row=$NATS->DB->Fetch_Array($r)) 383: { 384: if ( (isset($_REQUEST['disp_pass']) || ($row['alertlevel']!=0) ) && (!isset($_REQUEST['disp_hdata'])) ) 385: { 386: echo ""; 387: echo ""; 388: echo ""; 389: echo ""; 390: } 391: $testc++; 392: switch ($row['alertlevel']) 393: { 394: case 0: 395: $passc++; 396: $tested++; 397: $levelt+=$row['testvalue']; // for passed only 398: break; 399: case 1: 400: $warnc++; 401: $tested++; 402: //$levelt+=$row['testvalue']; 403: break; 404: case 2: 405: $failc++; 406: $tested++; 407: //$levelt+=$row['testvalue']; 408: break; 409: case -1: 410: $untested++; 411: break; 412: } 413: } 414: 415: echo ""; 416: echo "
".nicedt($row['recordx'])."".oText($row['alertlevel'])."".$row['testvalue']."
";
417: 418: echo "

";
419: echo ""; 420: 421: function np($big,$part) 422: { 423: if ($big==0) return "n/a"; 424: if ($part==0) return "0%"; 425: 426: $p=($part/$big)*100; 427: $p=round($p,2); 428: return $p."%"; 429: } 430: 431: 432: echo ""; 436: 437: $notpass=$tested-$passc; 438: 439: echo ""; 443: 444: echo ""; 445: 446: echo ""; 450: 451: echo ""; 455: 456: echo ""; 460: 461: echo ""; 465: 466: echo ""; 467: 468: echo ""; 469: echo ""; 475: 476: echo ""; 477: 478: $utt=$untested+$tested; 479: echo ""; 480: echo ""; 483: 484: $npt=$untested+$notpass; 485: echo ""; 486: echo ""; 489: 490: echo ""; 491: echo ""; 494: 495: echo ""; 496: 497: echo ""; 501: 502: if ($show_expected_number) 503: { 504: $nowx=time(); 505: if ($finishx>$nowx) $fx=$nowx; 506: else $fx=$finishx; 507: $p=$fx-$startx; 508: $interval_min=60*$tinterval; 509: $shouldhave=floor($p/$interval_min); 510: 511: 512: echo ""; 516: } 517: 518: echo "
".$passc." passed out of ".$tested." valid tests"; 433: echo " "; 434: echo np($tested,$passc); 435: echo "
".$notpass." did not pass out of ".$tested." valid tests"; 440: echo " "; 441: echo np($tested,$notpass); 442: echo "
 
".$warnc." generated warnings out of ".$tested." valid tests"; 447: echo " "; 448: echo np($tested,$warnc); 449: echo "
".$failc." generated failures out of ".$tested." valid tests"; 452: echo " "; 453: echo np($tested,$failc); 454: echo "
".$warnc." generated warnings out of ".$notpass." unpassed tests"; 457: echo " "; 458: echo np($notpass,$warnc); 459: echo "
".$failc." generated failures out of ".$notpass." unpassed tests"; 462: echo " "; 463: echo np($notpass,$failc); 464: echo "
 
the average test value returned by passed tests was "; 470: if ($passc<=0) echo "n/a"; 471: else if ($levelt==0) echo "0"; 472: else echo round($levelt/$passc,4); 473: if ($tunit!="") echo " ".$tunit; 474: echo "
 
".$untested." tests were untested (of ".$utt.") "; 481: echo np($utt,$untested); 482: echo "
of these (".$utt.") ".$npt." did not pass "; 487: echo np($utt,$npt); 488: echo "
of these (".$utt.") ".$passc." did pass "; 492: echo np($utt,$passc); 493: echo "
 
".$testc." records of which ".$tested." returned a valid alert level"; 498: echo " "; 499: echo np($testc,$tested); 500: echo "
".$testc." records and you should have ".hlink("History:Should",12)." ".$shouldhave; 513: echo " "; 514: echo np($shouldhave,$testc); 515: echo "

";
519: 520: /* - zoom period debugging 521: echo "Period: $p s (".($p/$five_min).")
";
522: echo "sx: ".$startx." fx: ".$finishx."
";
523: echo "diffx: ".($finishx-$startx)."
";
524: echo "fx2: ".$fx." p: ".$p."
";
525: */ 526: Screen_Footer(); 527: ?> 528: