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