File: 0.02.39a/server/web/history.test.php (View as HTML)

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