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