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