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