File: 0.04.08a/server/web/report.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 Report");
 32: 
 33: if (isset($_REQUEST['mode'])) $mode=$_REQUEST['mode'];
 34: else $mode="";
 35: 
 36: function slist($var,$min,$max,$val)
 37: 	{
 38: 	echo "\n<select name=\"".$var."\">\n";
 39: 	echo "<option value=\"".$val."\">".$val."</option>\n";
 40: 	for ($a=$min; $a<=$max; $a++)
 41: 		echo "<option value=\"".$a."\">".$a."</option>\n";
 42: 	echo "</select>\n";
 43: 	}
 44: 	
 45: function cbd($var,$name)
 46: 	{
 47: 	if (isset($_REQUEST[$var])) $s=" checked";
 48: 	else $s="";
 49: 	echo "<input type=checkbox name=\"".$var."\" value=1".$s."> ".$name;
 50: 	}
 51: 
 52: function np($big,$part)
 53: 	{
 54: 	if ($big==0) return "n/a";
 55: 	if ($part==0) return "0%";
 56: 	
 57: 	$p=($part/$big)*100;
 58: 	$p=round($p,2);
 59: 	return $p."%";
 60: 	}
 61: 
 62: $td_day=date("d");
 63: $td_mon=date("m");
 64: $td_yr=date("Y");
 65: 	
 66: $start=array();
 67: $finish=array();
 68: if (isset($_REQUEST['st_day'])) $start['day']=$_REQUEST['st_day'];
 69: else $start['day']=$td_day;
 70: if (isset($_REQUEST['st_mon'])) $start['mon']=$_REQUEST['st_mon'];
 71: else $start['mon']=$td_mon;
 72: if (isset($_REQUEST['st_yr'])) $start['yr']=$_REQUEST['st_yr'];
 73: else $start['yr']=$td_yr;
 74: if (isset($_REQUEST['st_hour'])) $start['hour']=$_REQUEST['st_hour'];
 75: else $start['hour']=0;
 76: if (isset($_REQUEST['st_min'])) $start['min']=$_REQUEST['st_min'];
 77: else $start['min']=0;
 78: if (isset($_REQUEST['st_sec'])) $start['sec']=$_REQUEST['st_sec'];
 79: else $start['sec']=0;
 80: 
 81: if (isset($_REQUEST['fi_day'])) $finish['day']=$_REQUEST['fi_day'];
 82: else $finish['day']=$td_day;
 83: if (isset($_REQUEST['fi_mon'])) $finish['mon']=$_REQUEST['fi_mon'];
 84: else $finish['mon']=$td_mon;
 85: if (isset($_REQUEST['fi_yr'])) $finish['yr']=$_REQUEST['fi_yr'];
 86: else $finish['yr']=$td_yr;
 87: if (isset($_REQUEST['fi_hour'])) $finish['hour']=$_REQUEST['fi_hour'];
 88: else $finish['hour']=23;
 89: if (isset($_REQUEST['fi_min'])) $finish['min']=$_REQUEST['fi_min'];
 90: else $finish['min']=59;
 91: if (isset($_REQUEST['fi_sec'])) $finish['sec']=$_REQUEST['fi_sec'];
 92: else $finish['sec']=59;
 93: 
 94: if (isset($_REQUEST['startx']))
 95: 	{
 96: 	$start['day']=date("d",$_REQUEST['startx']);
 97: 	$start['mon']=date("m",$_REQUEST['startx']);
 98: 	$start['yr']=date("Y",$_REQUEST['startx']);
 99: 	$start['hour']=date("H",$_REQUEST['startx']);
100: 	$start['min']=date("i",$_REQUEST['startx']);
101: 	$start['sec']=date("s",$_REQUEST['startx']);
102: 	$startx=$_REQUEST['startx'];
103: 	}
104: else
105: 	$startx=mktime($start['hour'],$start['min'],$start['sec'],$start['mon'],$start['day'],$start['yr']);
106: 
107: if (isset($_REQUEST['finishx']))
108: 	{
109: 	$finish['day']=date("d",$_REQUEST['finishx']);
110: 	$finish['mon']=date("m",$_REQUEST['finishx']);
111: 	$finish['yr']=date("Y",$_REQUEST['finishx']);
112: 	$finish['hour']=date("H",$_REQUEST['finishx']);
113: 	$finish['min']=date("i",$_REQUEST['finishx']);
114: 	$finish['sec']=date("s",$_REQUEST['finishx']);
115: 	$finishx=$_REQUEST['finishx'];
116: 	}
117: else
118: 	$finishx=mktime($finish['hour'],$finish['min'],$finish['sec'],$finish['mon'],$finish['day'],$finish['yr']);
119: //echo $startx." ".nicedt($startx)."<br>";
120: //echo $finishx." ".nicedt($finishx)."<br>";
121: 
122: 
123: if ($mode=="")
124: 	{
125: 	Screen_Header("Service Availability Report",1);
126: 	ob_end_flush();
127: 	
128: 
129: 	
130: 	
131: 	
132: 	
133: 	
134: 	echo "<br><table border=0>";
135: 	echo "<tr><td align=left valign=top>";
136: 	
137: 		
138: 	echo "<td align=left valign=top>";
139: 	
140: 	echo "<b class=\"subtitle\">Reporting Period</b><br><br>";
141: 	
142: 	echo "<table class=\"nicetable\">";
143: 	echo "<tr><td>&nbsp;</td><td>Hour</td><td>Min</td><td>Sec</td><td>Day</td><td>Mon</td><td>Year</td></tr>";
144: 	echo "<form action=report.php method=post>";
145: 	
146: 
147: 	
148: 	
149: 	echo "<tr><td><b>Start:</b></td>";
150: 	echo "<td>";
151: 	slist("st_hour",0,23,$start['hour']);
152: 	echo ":";
153: 	echo "</td>";
154: 	
155: 	echo "<td>";
156: 	slist("st_min",0,59,$start['min']);
157: 	echo ":";
158: 	echo "</td>";
159: 	
160: 	echo "<td>";
161: 	slist("st_sec",0,59,$start['sec']);
162: 	echo "&nbsp;&nbsp;";
163: 	echo "</td>";
164: 	
165: 	echo "<td>";
166: 	slist("st_day",1,31,$start['day']);
167: 	echo "/";
168: 	echo "</td>";
169: 	
170: 	echo "<td>";
171: 	slist("st_mon",1,12,$start['mon']);
172: 	echo "/";
173: 	echo "</td>";
174: 	
175: 	echo "<td>";
176: 	echo "<input type=text name=st_yr value=\"".$start['yr']."\" size=5 maxlength=4>";
177: 	
178: 	echo "&nbsp;";
179: 	
180: 	echo "</td>";
181: 	
182: 	echo "</tr>";
183: 	
184: 	// ----- finish
185: 	
186: 	echo "<tr><td><b>Finish:</b></td>";
187: 	echo "<td>";
188: 	slist("fi_hour",0,23,$finish['hour']);
189: 	echo ":";
190: 	echo "</td>";
191: 	
192: 	echo "<td>";
193: 	slist("fi_min",0,59,$finish['min']);
194: 	echo ":";
195: 	echo "</td>";
196: 	
197: 	echo "<td>";
198: 	slist("fi_sec",0,59,$finish['sec']);
199: 	echo "&nbsp;&nbsp;";
200: 	echo "</td>";
201: 	
202: 	echo "<td>";
203: 	slist("fi_day",1,31,$finish['day']);
204: 	echo "/";
205: 	echo "</td>";
206: 	
207: 	echo "<td>";
208: 	slist("fi_mon",1,12,$finish['mon']);
209: 	echo "/";
210: 	echo "</td>";
211: 	
212: 	echo "<td>";
213: 	echo "<input type=text name=fi_yr value=\"".$finish['yr']."\" size=5 maxlength=4>";
214: 	
215: 	echo "&nbsp;";
216: 	
217: 	echo "</td>";
218: 	
219: 	echo "</tr>";
220: 	
221: 	
222: 
223: 	echo "</table>";
224: 	
225: 	echo "</td></tr></table>";
226: 	
227: 	echo "<b>Pre-defined: </b>";
228: 	$now=time();
229: 	// td_day mon yr
230: 	
231: 	// mktime h mi s mo d y
232: 	
233: 	// last 30 days
234: 	$fx=mktime(0,0,0,$td_mon,$td_day,$td_yr);
235: 	$sx=$fx-(60*60*24*30);
236: 	echo "<a href=report.php?startx=".$sx."&finishx=".$fx.">";
237: 	echo "Last 30 Days";
238: 	echo "</a>&nbsp;";
239: 	
240: 	// last 28 days
241: 	$fx=mktime(0,0,0,$td_mon,$td_day,$td_yr);
242: 	$sx=$fx-(60*60*24*28);
243: 	echo "<a href=report.php?startx=".$sx."&finishx=".$fx.">";
244: 	echo "Last 28 Days";
245: 	echo "</a>&nbsp;";
246: 	
247: 	// last calendar month
248: 	$prev_mon=$td_mon-1;
249: 	$prev_yr=$td_yr;
250: 	if ($prev_mon<1)
251: 		{
252: 		$prev_mon=12;
253: 		$prev_yr--;
254: 		}
255: 	$fx=mktime(0,0,0,$td_mon,1,$td_yr);
256: 	$sx=mktime(0,0,0,$prev_mon,1,$prev_yr);
257: 	echo "<a href=report.php?startx=".$sx."&finishx=".$fx.">";
258: 	echo "Previous Month";
259: 	echo "</a>&nbsp;";
260: 	
261: 	
262: 	// this month
263: 	$sx=mktime(0,0,0,$td_mon,1,$td_yr);
264: 	$sx=$now;
265: 	echo "<a href=report.php?startx=".$sx."&finishx=".$fx.">";
266: 	echo "This Month";
267: 	echo "</a>&nbsp;";
268: 
269: 	
270: 	echo "<br><br>";
271: 	echo "<b class=\"subtitle\">Reported Tests</b><br>";
272: 	
273: 	$q="SELECT localtestid,nodeid,testname,testtype,testparam,testrecord FROM fnlocaltest WHERE testrecord>0 OR testtype=\"ICMP\" ORDER BY nodeid";
274: 	$r=$NATS->DB->Query($q);
275: 	$lastnode="";
276: 	while ($row=$NATS->DB->Fetch_Array($r))
277: 		{
278: 		if ($row['nodeid']!=$lastnode)
279: 			{
280: 			echo "<br><b>".$row['nodeid']."</b><br>";
281: 			$lastnode=$row['nodeid'];
282: 			}
283: 		echo "<input type=checkbox name=testlist[] value=L".$row['localtestid']."> ";
284: 		if ($row['testname']!="") echo $row['testname'];
285: 		else
286: 			{
287: 			echo lText($row['testtype']);
288: 			if ($row['testparam']!="") echo " (".$row['testparam'].")";
289: 			}
290: 		echo " on ".$row['nodeid'];
291: 		echo "<br>";
292: 		}
293: 	$NATS->DB->Free($r);
294: 	
295: 	echo "<br><br>";
296: 	echo "<input type=hidden name=mode value=report>";
297: 	echo "<input type=submit value=\"View Availability Report\"><br>";
298: 	echo "<input type=checkbox name=showdetail value=1> Show breakdown details<br>";
299: 	echo "</form>";
300: 	Screen_Footer();
301: 	exit();
302: 		
303: 		
304: 	}
305: 
306: if ($mode!="report")
307: 	{
308: 	Screen_Header("Error");
309: 	echo "Sorry - illegal mode specified<br><br>";
310: 	Screen_Footer();
311: 	exit();
312: 	}
313: 
314: 
315: 
316: 
317: 
318: // the actual run
319: 
320: Screen_Header("Availability Report");
321: ob_end_flush();
322: 
323: echo "<b class=\"subtitle\">Reporting from ".nicedt($startx)." to ".nicedt($finishx)."</b><br><br>";
324: 
325: foreach($_REQUEST['testlist'] as $testid)
326: {
327: 
328: $tmode="";
329: switch($testid[0])
330: 	{
331: 	case "L": $tmode="local";
332: 	break;
333: 	default: $tmode="unknown";
334: 	}
335: $stid=substr($testid,1,128);
336: 
337: // get test info
338: $tnode="";
339: $tname="";
340: $ttype="";
341: $tparam="";
342: $tlastrunx="";
343: $trecord=1;
344: 
345: $q="";
346: if ($tmode=="local") $q="SELECT * FROM fnlocaltest WHERE localtestid=".ss($stid);
347: 	
348: $r=$NATS->DB->Query($q);
349: 
350: if (!$row=$NATS->DB->Fetch_Array($r))
351: 	{
352: 	header("main.php?message=Error+opening+test+history");
353: 	exit();
354: 	}
355: 	
356: 	
357: 	
358: $tnode=$row['nodeid'];
359: $ttype=$row['testtype'];
360: $tparam=$row['testparam'];
361: $tlastrunx=$row['lastrunx'];
362: $tname=lText($ttype);
363: $tunit=lUnit($ttype);
364: if ($tparam!="") $tname.=" (".$tparam.")";
365: if ($row['testname']!="")
366: 	{
367: 	$subtname=$tname;
368: 	$tname=$row['testname'];
369: 	$usesubname=true;
370: 	}
371: else $usesubname=false;
372: $NATS->DB->Free($r);
373: 
374: 
375: 
376: 
377: $diffx=$finishx-$startx;
378: $periods=8;
379: $periodx=$diffx/$periods;
380: $hperiodx=round($periodx/2,0);
381: $periodx=round($periodx,0);
382: $iwid=700;
383: $ihei=150;
384: $istart=50;
385: $iend=$iwid-5;
386: $idwid=$iend-$istart;
387: $iscale=$idwid/$periods;
388: 
389: 
390: 
391: 	
392: echo "<b>".$tname."</b>";
393: if ($usesubname) echo "<b> - ".$subtname."</b>";
394: echo "<b> on ".$tnode."</b>";
395: echo "<br>";
396: 
397: //echo "<i>node ";
398: //echo "<a href=node.php?nodeid=".$tnode.">".$tnode."</a>";
399: //echo " - ";
400: echo "<i>";
401: echo "Last Run : ";
402: 
403: if ($tlastrunx>0)
404: 	{
405: 	echo nicedt($tlastrunx)." - ";
406: 	echo dtago($tlastrunx);
407: 	}
408: else echo "Never";
409: echo "</i><br>";
410: 
411: 
412: //echo "<b>".$tname." from ".nicedt($startx)." to ".nicedt($finishx);
413: //if ($tunit!="") echo " (".$tunit.")";
414: // echo " (".nicediff($finishx-$startx).")";
415: //echo "</b><br><br>";
416: 
417: 
418: 
419: // table data
420: 
421: 
422: $q="SELECT alertlevel,testvalue,recordx FROM fnrecord WHERE ";
423: $q.="testid=\"".ss($testid)."\" AND recordx>=".ss($startx)." AND recordx<=".ss($finishx);
424: //if (!isset($_REQUEST['disp_pass'])) $q.=" AND alertlevel!=0";
425: $q.=" ORDER BY recordx ASC";
426: 
427: $firstx=0;
428: $lastx=0;
429: $records=0;
430: 
431: //echo $q;
432: $r=$NATS->DB->Query($q);
433: 
434: $testc=0;
435: $tested=0;
436: $untested=0;
437: $passc=0;
438: $warnc=0;
439: $failc=0;
440: $levelt=0;
441: 
442: while ($row=$NATS->DB->Fetch_Array($r))
443: 	{
444: 	$testc++;
445: 	$records++;
446: 	if ($firstx==0) $firstx=$row['recordx'];
447: 	$lastx=$row['recordx'];
448: 	switch ($row['alertlevel'])
449: 		{
450: 		case 0:
451: 			$passc++;
452: 			$tested++;
453: 			$levelt+=$row['testvalue'];
454: 			break;
455: 		case 1:
456: 			$warnc++;
457: 			$tested++;
458: 			$levelt+=$row['testvalue'];
459: 			break;
460: 		case 2:
461: 			$failc++;
462: 			$tested++;
463: 			$levelt+=$row['testvalue'];
464: 			break;
465: 		case -1:
466: 			$untested++;
467: 			break;
468: 		}
469: 	}
470: 	
471: 
472: echo "<table border=0>";
473: 
474: if (isset($_REQUEST['showdetail']))
475: 	{
476: 	echo "<tr><td>".$passc." passed out of ".$tested." valid tests";
477: 	echo "</td><td>&nbsp;</td><td>";
478: 	echo np($tested,$passc);
479: 	echo "</td></tr>";
480: 	
481: 	$notpass=$tested-$passc;
482: 	
483: 	echo "<tr><td>".$notpass." did not pass out of ".$tested." valid tests";
484: 	echo "</td><td>&nbsp;</td><td>";
485: 	echo np($tested,$notpass);
486: 	echo "</td></tr>";
487: 	
488: 	echo "<tr><td colspan=3>&nbsp;<br></td></tr>";
489: 	
490: 	echo "<tr><td>".$warnc." generated warnings out of ".$tested." valid tests";
491: 	echo "</td><td>&nbsp;</td><td>";
492: 	echo np($tested,$warnc);
493: 	echo "</td></tr>";
494: 	
495: 	echo "<tr><td>".$failc." generated failures out of ".$tested." valid tests";
496: 	echo "</td><td>&nbsp;</td><td>";
497: 	echo np($tested,$failc);
498: 	echo "</td></tr>";
499: 	
500: 	echo "<tr><td>".$warnc." generated warnings out of ".$notpass." unpassed tests";
501: 	echo "</td><td>&nbsp;</td><td>";
502: 	echo np($notpass,$warnc);
503: 	echo "</td></tr>";
504: 	
505: 	echo "<tr><td>".$failc." generated failures out of ".$notpass." unpassed tests";
506: 	echo "</td><td>&nbsp;</td><td>";
507: 	echo np($notpass,$failc);
508: 	echo "</td></tr>";
509: 	
510: 	echo "<tr><td colspan=3>&nbsp;<br></td></tr>";
511: 	
512: 	echo "<tr><td>the average test value returned by valid tests was</td>";
513: 	echo "<td>&nbsp;</td><td>";
514: 	if ($tested<=0) echo "n/a";
515: 	else if ($levelt==0) echo "0";
516: 	else echo round($levelt/$tested,4);
517: 	if ($tunit!="") echo " ".$tunit;
518: 	echo "</td></tr>";
519: 	
520: 	echo "<tr><td colspan=3>&nbsp;<br></td></tr>";
521: 	
522: 	$utt=$untested+$tested;
523: 	echo "<tr><td>".$untested." tests were untested (of ".$utt.")</td>";
524: 	echo "<td>&nbsp;</td><td>";
525: 	echo np($utt,$untested);
526: 	echo "</td></tr>";
527: 	
528: 	$npt=$untested+$notpass;
529: 	echo "<tr><td>of these (".$utt.") ".$npt." did not pass</td>";
530: 	echo "<td>&nbsp;</td><td>";
531: 	echo np($utt,$npt);
532: 	echo "</td></tr>";
533: 	
534: 	echo "<tr><td>of these (".$utt.") ".$passc." did pass</td>";
535: 	echo "<td>&nbsp;</td><td>";
536: 	echo np($utt,$passc);
537: 	echo "</td></tr>";
538: 	
539: 	echo "<tr><td colspan=3>&nbsp;<br></td></tr>";
540: 	
541: 	echo "<tr><td>".$testc." records of which ".$tested." returned a valid alert level";
542: 	echo "</td><td>&nbsp;</td><td>";
543: 	echo np($testc,$tested);
544: 	echo "</td></tr>";
545: 	
546: 	$nowx=time();
547: 	if ($finishx>$nowx) $fx=$nowx;
548: 	else $fx=$finishx;
549: 	$p=$fx-$startx;
550: 	$five_min=60*5;
551: 	$shouldhave=floor($p/$five_min);
552: 	
553: 	
554: 	echo "<tr><td>".$testc." records and you <i>should have</i> ".hlink("History:Should",12)." ".$shouldhave;
555: 	echo "</td><td>&nbsp;</td><td>";
556: 	echo np($shouldhave,$testc);
557: 	echo "</td></tr>";
558: 	}
559: 
560: echo "<tr><td colspan=3>&nbsp;<br></td></tr>";
561: echo "<tr><td>First Test Record";
562: echo "</td><td>&nbsp;</td><td>";
563: echo nicedt($firstx);
564: echo "</td></tr>";
565: 
566: echo "<tr><td>Last Test Record";
567: echo "</td><td>&nbsp;</td><td>";
568: echo nicedt($lastx);
569: echo "</td></tr>";
570: 
571: echo "<tr><td colspan=3>&nbsp;<br></td></tr>";
572: echo "<tr><td><b>Service Availability</b>";
573: echo "</td><td>&nbsp;</td><td><b>";
574: // Service level is tested-failed
575: echo np($tested,$tested-$failc);
576: echo "</b></td></tr>";
577: 
578: echo "</table><br>";
579: 
580: /* - zoom period debugging
581: echo "Period: $p s (".($p/$five_min).")<br>";
582: echo "sx: ".$startx." fx: ".$finishx."<br>";
583: echo "diffx: ".($finishx-$startx)."<br>";
584: echo "fx2: ".$fx." p: ".$p."<br>";
585: */
586: 
587: 
588: echo "<br><hr style=\"width: 400px; border: 0 solid #a0a0a0; height: 1px; background-color: #a0a0a0; align: left;\" align=\"left\"><br>";
589: }
590: Screen_Footer();
591: ?>
592: