File: 1.00.3a/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=get>";
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: 			// Bodge in node-side tests here
284: 			$nq="SELECT nstestid,testname,testtype,testdesc FROM fnnstest WHERE testrecord>0 AND nodeid=\"".ss($row['nodeid'])."\"";
285: 			$nr=$NATS->DB->Query($nq);
286: 			while ($nrow=$NATS->DB->Fetch_Array($nr))
287: 				{
288: 				echo "<input type=checkbox name=testlist[] value=N".$nrow['nstestid']."> ";
289: 				if ($nrow['testname']!="") echo $nrow['testname'];
290: 				else if ($nrow['testdesc']!="") echo $nrow['testdesc'];
291: 				else echo $nrow['testtype'];
292: 				echo " on ".$row['nodeid']."<br>";
293: 				}
294: 			$NATS->DB->Free($nr);
295: 			
296: 			
297: 			}
298: 		echo "<input type=checkbox name=testlist[] value=L".$row['localtestid']."> ";
299: 		if ($row['testname']!="") echo $row['testname'];
300: 		else
301: 			{
302: 			echo lText($row['testtype']);
303: 			if ($row['testparam']!="") echo " (".$row['testparam'].")";
304: 			}
305: 		echo " on ".$row['nodeid'];
306: 		echo "<br>";
307: 		}
308: 	$NATS->DB->Free($r);
309: 	
310: 	echo "<br><br>";
311: 	echo "<input type=hidden name=mode value=report>";
312: 	echo "<input type=submit value=\"View Availability Report\"><br>";
313: 	echo "<input type=checkbox name=showdetail value=1> Show breakdown details<br>";
314: 	echo "</form>";
315: 	Screen_Footer();
316: 	exit();
317: 		
318: 		
319: 	}
320: 
321: if ($mode!="report")
322: 	{
323: 	Screen_Header("Error");
324: 	echo "Sorry - illegal mode specified<br><br>";
325: 	Screen_Footer();
326: 	exit();
327: 	}
328: 
329: 
330: 
331: 
332: 
333: // the actual run
334: 
335: Screen_Header("Availability Report");
336: ob_end_flush();
337: 
338: echo "<b class=\"subtitle\">Reporting from ".nicedt($startx)." to ".nicedt($finishx)."</b><br><br>";
339: 
340: foreach($_REQUEST['testlist'] as $testid)
341: {
342: 
343: $tmode="";
344: switch($testid[0])
345: 	{
346: 	case "L": $tmode="local";
347: 	break;
348: 	case "N": $tmode="nodeside";
349: 	break;
350: 	default: $tmode="unknown";
351: 	}
352: $stid=substr($testid,1,128);
353: 
354: // get test info
355: $tnode="";
356: $tname="";
357: $ttype="";
358: $tparam="";
359: $tlastrunx="";
360: $trecord=1;
361: 
362: $q="";
363: if ($tmode=="local") $q="SELECT * FROM fnlocaltest WHERE localtestid=".ss($stid);
364: else if ($tmode=="nodeside") $q="SELECT * FROM fnnstest WHERE nstestid=".ss($stid);
365: 	
366: $r=$NATS->DB->Query($q);
367: 
368: if (!$row=$NATS->DB->Fetch_Array($r))
369: 	{
370: 	header("main.php?message=Error+opening+test+history");
371: 	exit();
372: 	}
373: 	
374: 	
375: 	
376: $tnode=$row['nodeid'];
377: $ttype=$row['testtype'];
378: if (isset($row['testparam'])) $tparam=$row['testparam'];
379: else $tparam="";
380: $tlastrunx=$row['lastrunx'];
381: $tunit="";
382: 
383: if ($tmode=="local")
384: 	{
385: 	$tname=lText($ttype);
386: 	$tunit=lUnit($ttype);
387: 	if ($tparam!="") $tname.=" (".$tparam.")";
388: 	if ($row['testname']!="")
389: 		{
390: 		$subtname=$tname;
391: 		$tname=$row['testname'];
392: 		$usesubname=true;
393: 		}
394: 	else $usesubname=false;
395: 	}
396: else if ($tmode=="nodeside")
397: 	{
398: 	if ($row['testname']!="") $tname=$row['testname'];
399: 	else $tname=$row['testtype'];
400: 	$subtname=$row['testdesc'];
401: 	$usesubname=true;
402: 	}
403: $NATS->DB->Free($r);
404: 
405: 
406: 
407: 
408: $diffx=$finishx-$startx;
409: $periods=8;
410: $periodx=$diffx/$periods;
411: $hperiodx=round($periodx/2,0);
412: $periodx=round($periodx,0);
413: $iwid=700;
414: $ihei=150;
415: $istart=50;
416: $iend=$iwid-5;
417: $idwid=$iend-$istart;
418: $iscale=$idwid/$periods;
419: 
420: 
421: 
422: 	
423: echo "<b>".$tname."</b>";
424: if ($usesubname) echo "<b> - ".$subtname."</b>";
425: echo "<b> on ".$tnode."</b>";
426: echo "<br>";
427: 
428: //echo "<i>node ";
429: //echo "<a href=node.php?nodeid=".$tnode.">".$tnode."</a>";
430: //echo " - ";
431: echo "<i>";
432: echo "Last Run : ";
433: 
434: if ($tlastrunx>0)
435: 	{
436: 	echo nicedt($tlastrunx)." - ";
437: 	echo dtago($tlastrunx);
438: 	}
439: else echo "Never";
440: echo "</i><br>";
441: 
442: 
443: //echo "<b>".$tname." from ".nicedt($startx)." to ".nicedt($finishx);
444: //if ($tunit!="") echo " (".$tunit.")";
445: // echo " (".nicediff($finishx-$startx).")";
446: //echo "</b><br><br>";
447: 
448: 
449: 
450: // table data
451: 
452: 
453: $q="SELECT alertlevel,testvalue,recordx FROM fnrecord WHERE ";
454: $q.="testid=\"".ss($testid)."\" AND recordx>=".ss($startx)." AND recordx<=".ss($finishx);
455: //if (!isset($_REQUEST['disp_pass'])) $q.=" AND alertlevel!=0";
456: $q.=" ORDER BY recordx ASC";
457: 
458: $firstx=0;
459: $lastx=0;
460: $records=0;
461: 
462: //echo $q;
463: $r=$NATS->DB->Query($q);
464: 
465: $testc=0;
466: $tested=0;
467: $untested=0;
468: $passc=0;
469: $warnc=0;
470: $failc=0;
471: $levelt=0;
472: 
473: while ($row=$NATS->DB->Fetch_Array($r))
474: 	{
475: 	$testc++;
476: 	$records++;
477: 	if ($firstx==0) $firstx=$row['recordx'];
478: 	$lastx=$row['recordx'];
479: 	switch ($row['alertlevel'])
480: 		{
481: 		case 0:
482: 			$passc++;
483: 			$tested++;
484: 			$levelt+=$row['testvalue'];
485: 			break;
486: 		case 1:
487: 			$warnc++;
488: 			$tested++;
489: 			//$levelt+=$row['testvalue'];
490: 			break;
491: 		case 2:
492: 			$failc++;
493: 			$tested++;
494: 			//$levelt+=$row['testvalue'];
495: 			break;
496: 		case -1:
497: 			$untested++;
498: 			break;
499: 		}
500: 	}
501: 	
502: 
503: echo "<table border=0>";
504: 
505: if (isset($_REQUEST['showdetail']))
506: 	{
507: 	echo "<tr><td>".$passc." passed out of ".$tested." valid tests";
508: 	echo "</td><td>&nbsp;</td><td>";
509: 	echo np($tested,$passc);
510: 	echo "</td></tr>";
511: 	
512: 	$notpass=$tested-$passc;
513: 	
514: 	echo "<tr><td>".$notpass." did not pass out of ".$tested." valid tests";
515: 	echo "</td><td>&nbsp;</td><td>";
516: 	echo np($tested,$notpass);
517: 	echo "</td></tr>";
518: 	
519: 	echo "<tr><td colspan=3>&nbsp;<br></td></tr>";
520: 	
521: 	echo "<tr><td>".$warnc." generated warnings out of ".$tested." valid tests";
522: 	echo "</td><td>&nbsp;</td><td>";
523: 	echo np($tested,$warnc);
524: 	echo "</td></tr>";
525: 	
526: 	echo "<tr><td>".$failc." generated failures out of ".$tested." valid tests";
527: 	echo "</td><td>&nbsp;</td><td>";
528: 	echo np($tested,$failc);
529: 	echo "</td></tr>";
530: 	
531: 	echo "<tr><td>".$warnc." generated warnings out of ".$notpass." unpassed tests";
532: 	echo "</td><td>&nbsp;</td><td>";
533: 	echo np($notpass,$warnc);
534: 	echo "</td></tr>";
535: 	
536: 	echo "<tr><td>".$failc." generated failures out of ".$notpass." unpassed tests";
537: 	echo "</td><td>&nbsp;</td><td>";
538: 	echo np($notpass,$failc);
539: 	echo "</td></tr>";
540: 	
541: 	echo "<tr><td colspan=3>&nbsp;<br></td></tr>";
542: 	
543: 	echo "<tr><td>the average test value returned by passed tests was</td>";
544: 	echo "<td>&nbsp;</td><td>";
545: 	if ($passc<=0) echo "n/a";
546: 	else if ($levelt==0) echo "0";
547: 	else echo round($levelt/$passc,4);
548: 	if ($tunit!="") echo " ".$tunit;
549: 	echo "</td></tr>";
550: 	
551: 	echo "<tr><td colspan=3>&nbsp;<br></td></tr>";
552: 	
553: 	$utt=$untested+$tested;
554: 	echo "<tr><td>".$untested." tests were untested (of ".$utt.")</td>";
555: 	echo "<td>&nbsp;</td><td>";
556: 	echo np($utt,$untested);
557: 	echo "</td></tr>";
558: 	
559: 	$npt=$untested+$notpass;
560: 	echo "<tr><td>of these (".$utt.") ".$npt." did not pass</td>";
561: 	echo "<td>&nbsp;</td><td>";
562: 	echo np($utt,$npt);
563: 	echo "</td></tr>";
564: 	
565: 	echo "<tr><td>of these (".$utt.") ".$passc." did pass</td>";
566: 	echo "<td>&nbsp;</td><td>";
567: 	echo np($utt,$passc);
568: 	echo "</td></tr>";
569: 	
570: 	echo "<tr><td colspan=3>&nbsp;<br></td></tr>";
571: 	
572: 	echo "<tr><td>".$testc." records of which ".$tested." returned a valid alert level";
573: 	echo "</td><td>&nbsp;</td><td>";
574: 	echo np($testc,$tested);
575: 	echo "</td></tr>";
576: 	
577: 	$nowx=time();
578: 	if ($finishx>$nowx) $fx=$nowx;
579: 	else $fx=$finishx;
580: 	$p=$fx-$startx;
581: 	$five_min=60*5;
582: 	$shouldhave=floor($p/$five_min);
583: 	
584: 	
585: 	echo "<tr><td>".$testc." records and you <i>should have</i> ".hlink("History:Should",12)." ".$shouldhave;
586: 	echo "</td><td>&nbsp;</td><td>";
587: 	echo np($shouldhave,$testc);
588: 	echo "</td></tr>";
589: 	}
590: 
591: echo "<tr><td colspan=3>&nbsp;<br></td></tr>";
592: echo "<tr><td>First Test Record";
593: echo "</td><td>&nbsp;</td><td>";
594: echo nicedt($firstx);
595: echo "</td></tr>";
596: 
597: echo "<tr><td>Last Test Record";
598: echo "</td><td>&nbsp;</td><td>";
599: echo nicedt($lastx);
600: echo "</td></tr>";
601: 
602: echo "<tr><td colspan=3>&nbsp;<br></td></tr>";
603: echo "<tr><td><b>Service Availability</b>";
604: echo "</td><td>&nbsp;</td><td><b>";
605: // Service level is tested-failed
606: echo np($tested,$tested-$failc);
607: echo "</b></td></tr>";
608: 
609: echo "</table><br>";
610: 
611: /* - zoom period debugging
612: echo "Period: $p s (".($p/$five_min).")<br>";
613: echo "sx: ".$startx." fx: ".$finishx."<br>";
614: echo "diffx: ".($finishx-$startx)."<br>";
615: echo "fx2: ".$fx." p: ".$p."<br>";
616: */
617: 
618: 
619: echo "<br><hr style=\"width: 400px; border: 0 solid #a0a0a0; height: 1px; background-color: #a0a0a0; align: left;\" align=\"left\"><br>";
620: }
621: Screen_Footer();
622: ?>
623: