File: 1.19.1b/server/web/history.test.php (View as Code)

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

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

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

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

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

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