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