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