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