File: 0.02.20a/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 Foobar. 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: if ($tparam!="") $tname.=" (".$tparam.")"; 67: $NATS->DB->Free($r); 68: Screen_Header("History for ".$tname." on ".$tnode,1); 69: ob_end_flush(); 70: 71: $td_day=date("d"); 72: $td_mon=date("m"); 73: $td_yr=date("Y"); 74: 75: $start=array(); 76: $finish=array(); 77: if (isset($_REQUEST['st_day'])) $start['day']=$_REQUEST['st_day']; 78: else $start['day']=$td_day; 79: if (isset($_REQUEST['st_mon'])) $start['mon']=$_REQUEST['st_mon']; 80: else $start['mon']=$td_mon; 81: if (isset($_REQUEST['st_yr'])) $start['yr']=$_REQUEST['st_yr']; 82: else $start['yr']=$td_yr; 83: if (isset($_REQUEST['st_hour'])) $start['hour']=$_REQUEST['st_hour']; 84: else $start['hour']=0; 85: if (isset($_REQUEST['st_min'])) $start['min']=$_REQUEST['st_min']; 86: else $start['min']=0; 87: if (isset($_REQUEST['st_sec'])) $start['sec']=$_REQUEST['st_sec']; 88: else $start['sec']=0; 89: 90: if (isset($_REQUEST['fi_day'])) $finish['day']=$_REQUEST['fi_day']; 91: else $finish['day']=$td_day; 92: if (isset($_REQUEST['fi_mon'])) $finish['mon']=$_REQUEST['fi_mon']; 93: else $finish['mon']=$td_mon; 94: if (isset($_REQUEST['fi_yr'])) $finish['yr']=$_REQUEST['fi_yr']; 95: else $finish['yr']=$td_yr; 96: if (isset($_REQUEST['fi_hour'])) $finish['hour']=$_REQUEST['fi_hour']; 97: else $finish['hour']=23; 98: if (isset($_REQUEST['fi_min'])) $finish['min']=$_REQUEST['fi_min']; 99: else $finish['min']=59; 100: if (isset($_REQUEST['fi_sec'])) $finish['sec']=$_REQUEST['fi_sec']; 101: else $finish['sec']=59; 102: 103: 104: $startx=mktime($start['hour'],$start['min'],$start['sec'],$start['mon'],$start['day'],$start['yr']); 105: $finishx=mktime($finish['hour'],$finish['min'],$finish['sec'],$finish['mon'],$finish['day'],$finish['yr']); 106: //echo $startx." ".nicedt($startx)."
";
107: //echo $finishx." ".nicedt($finishx)."
";
108: 109: echo "
"; 110: echo "
"; 111: echo "".$tname."
";
112: 113: echo ""; 114: echo ""; 115: echo ""; 117: echo ""; 118: echo ""; 126: echo ""; 127: echo "
Node :".$tnode.""; 116: echo "
Last Run :"; 119: if ($tlastrunx>0) 120: { 121: echo nicedt($tlastrunx)."
";
122: echo dtago($tlastrunx); 123: } 124: else echo "Never"; 125: echo "
";
128: 129: echo "
 "; 130: 131: echo "Reporting Period
";
132: 133: echo ""; 134: echo ""; 135: echo "
";
136: echo ""; 137: 138: function slist($var,$min,$max,$val) 139: { 140: echo "\n\n"; 145: } 146: 147: 148: echo ""; 149: echo ""; 153: 154: echo ""; 158: 159: echo ""; 163: 164: echo ""; 168: 169: echo ""; 173: 174: echo ""; 180: 181: echo ""; 182: 183: // ----- finish 184: 185: echo ""; 186: echo ""; 190: 191: echo ""; 195: 196: echo ""; 200: 201: echo ""; 205: 206: echo ""; 210: 211: echo ""; 217: 218: echo ""; 219: 220: // 7 221: echo ""; 222: echo ""; 235: 236: echo ""; 237: echo "
 HourMinSecDayMonYear
Start:"; 150: slist("st_hour",0,23,$start['hour']); 151: echo ":"; 152: echo ""; 155: slist("st_min",0,59,$start['min']); 156: echo ":"; 157: echo ""; 160: slist("st_sec",0,59,$start['sec']); 161: echo "  "; 162: echo ""; 165: slist("st_day",1,31,$start['day']); 166: echo "/"; 167: echo ""; 170: slist("st_mon",1,12,$start['mon']); 171: echo "/"; 172: echo ""; 175: echo ""; 176: 177: echo " Today"; 178: 179: echo "
Finish:"; 187: slist("fi_hour",0,23,$finish['hour']); 188: echo ":"; 189: echo ""; 192: slist("fi_min",0,59,$finish['min']); 193: echo ":"; 194: echo ""; 197: slist("fi_sec",0,59,$finish['sec']); 198: echo "  "; 199: echo ""; 202: slist("fi_day",1,31,$finish['day']); 203: echo "/"; 204: echo ""; 207: slist("fi_mon",1,12,$finish['mon']); 208: echo "/"; 209: echo ""; 212: echo ""; 213: 214: echo " "; 215: 216: echo "
Opts:"; 223: function cbd($var,$name) 224: { 225: if (isset($_REQUEST[$var])) $s=" checked"; 226: else $s=""; 227: echo " ".$name; 228: } 229: cbd("disp_hdata","Hide Data"); 230: echo " "; 231: cbd("disp_pass","Show Passed"); 232: echo " "; 233: cbd("hide_graph","Hide Graph"); 234: echo "
";
238: 239: echo "
";
240: 241: echo "

";
242: 243: echo "Report from ".nicedt($startx)." to ".nicedt($finishx); 244: // echo " (".nicediff($finishx-$startx).")"; 245: echo "

";
246: 247: // graph data 248: if (!isset($_REQUEST['hide_graph'])) 249: { 250: mt_srand(microtime()*1000000); 251: $i=mt_rand(1000,1000000); 252: echo "

";
253: } 254: 255: // table data 256: 257: if (!isset($_REQUEST['disp_hdata'])) 258: { 259: $q="SELECT alertlevel,testvalue,recordx FROM fnrecord WHERE "; 260: $q.="testid=\"".ss($_REQUEST['testid'])."\" AND recordx>=".$startx." AND recordx<=".$finishx; 261: //if (!isset($_REQUEST['disp_pass'])) $q.=" AND alertlevel!=0"; 262: $q.=" ORDER BY recordx DESC"; 263: //echo $q; 264: $r=$NATS->DB->Query($q); 265: 266: $testc=0; 267: $tested=0; 268: $passc=0; 269: $warnc=0; 270: $failc=0; 271: $levelt=0; 272: 273: echo ""; 274: while ($row=$NATS->DB->Fetch_Array($r)) 275: { 276: if (isset($_REQUEST['disp_pass']) || ($row['alertlevel']!=0) ) 277: { 278: echo ""; 279: echo ""; 280: echo ""; 281: echo ""; 282: } 283: $testc++; 284: switch ($row['alertlevel']) 285: { 286: case 0: 287: $passc++; 288: $tested++; 289: $levelt+=$row['testvalue']; 290: break; 291: case 1: 292: $warnc++; 293: $tested++; 294: $levelt+=$row['testvalue']; 295: break; 296: case 2: 297: $failc++; 298: $tested++; 299: $levelt+=$row['testvalue']; 300: break; 301: } 302: } 303: 304: echo ""; 305: echo "
".nicedt($row['recordx'])."".oText($row['alertlevel'])."".$row['testvalue']."
";
306: } 307: echo "

";
308: echo ""; 309: 310: function np($big,$part) 311: { 312: if ($big==0) return "n/a"; 313: if ($part==0) return "0%"; 314: 315: $p=($part/$big)*100; 316: $p=round($p,2); 317: return $p."%"; 318: } 319: 320: 321: echo ""; 325: 326: $notpass=$tested-$passc; 327: 328: echo ""; 332: 333: echo ""; 334: 335: echo ""; 339: 340: echo ""; 344: 345: echo ""; 349: 350: echo ""; 354: 355: echo ""; 356: 357: echo ""; 358: echo ""; 363: 364: echo ""; 365: 366: echo ""; 370: 371: $nowx=time(); 372: if ($finishx>$nowx) $fx=$nowx; 373: else $fx=$nowx; 374: $p=$fx-$startx; 375: $five_min=60*5; 376: $shouldhave=floor($p/$five_min); 377: 378: 379: echo ""; 383: 384: echo "
".$passc." passed out of ".$tested." valid tests"; 322: echo " "; 323: echo np($tested,$passc); 324: echo "
".$notpass." did not pass out of ".$tested." valid tests"; 329: echo " "; 330: echo np($tested,$notpass); 331: echo "
 
".$warnc." generated warnings out of ".$tested." valid tests"; 336: echo " "; 337: echo np($tested,$warnc); 338: echo "
".$failc." generated failures out of ".$tested." valid tests"; 341: echo " "; 342: echo np($tested,$failc); 343: echo "
".$warnc." generated warnings out of ".$notpass." unpassed tests"; 346: echo " "; 347: echo np($notpass,$warnc); 348: echo "
".$failc." generated failures out of ".$notpass." unpassed tests"; 351: echo " "; 352: echo np($notpass,$failc); 353: echo "
 
the average test value returned by valid tests was "; 359: if ($tested<=0) echo "n/a"; 360: else if ($levelt==0) echo "0"; 361: else echo round($levelt/$tested,4); 362: echo "
 
".$testc." records of which ".$tested." returned a valid alert level"; 367: echo " "; 368: echo np($testc,$tested); 369: echo "
".$testc." records and you should have ".hlink("History:Should",12)." ".$shouldhave; 380: echo " "; 381: echo np($shouldhave,$testc); 382: echo "

";
385: 386: Screen_Footer(); 387: ?> 388: