File: 1.00.4a/server/web/report.php (View as Code)

1: 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\n"; 43: } 44: 45: function cbd($var,$name) 46: { 47: if (isset($_REQUEST[$var])) $s=" checked"; 48: else $s=""; 49: echo " ".$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)."
";
120: //echo $finishx." ".nicedt($finishx)."
";
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 "
"; 135: echo "
"; 136: 137: 138: echo ""; 139: 140: echo "Reporting Period

";
141: 142: echo ""; 143: echo ""; 144: echo "
";
145: 146: 147: 148: 149: echo ""; 150: echo ""; 154: 155: echo ""; 159: 160: echo ""; 164: 165: echo ""; 169: 170: echo ""; 174: 175: echo ""; 181: 182: echo ""; 183: 184: // ----- finish 185: 186: echo ""; 187: echo ""; 191: 192: echo ""; 196: 197: echo ""; 201: 202: echo ""; 206: 207: echo ""; 211: 212: echo ""; 218: 219: echo ""; 220: 221: 222: 223: echo "
 HourMinSecDayMonYear
Start:"; 151: slist("st_hour",0,23,$start['hour']); 152: echo ":"; 153: echo ""; 156: slist("st_min",0,59,$start['min']); 157: echo ":"; 158: echo ""; 161: slist("st_sec",0,59,$start['sec']); 162: echo "  "; 163: echo ""; 166: slist("st_day",1,31,$start['day']); 167: echo "/"; 168: echo ""; 171: slist("st_mon",1,12,$start['mon']); 172: echo "/"; 173: echo ""; 176: echo ""; 177: 178: echo " "; 179: 180: echo "
Finish:"; 188: slist("fi_hour",0,23,$finish['hour']); 189: echo ":"; 190: echo ""; 193: slist("fi_min",0,59,$finish['min']); 194: echo ":"; 195: echo ""; 198: slist("fi_sec",0,59,$finish['sec']); 199: echo "  "; 200: echo ""; 203: slist("fi_day",1,31,$finish['day']); 204: echo "/"; 205: echo ""; 208: slist("fi_mon",1,12,$finish['mon']); 209: echo "/"; 210: echo ""; 213: echo ""; 214: 215: echo " "; 216: 217: echo "
";
224: 225: echo "
";
226: 227: echo "Pre-defined: "; 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 ""; 237: echo "Last 30 Days"; 238: echo " ";
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 ""; 244: echo "Last 28 Days"; 245: echo " "; 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 ""; 258: echo "Previous Month"; 259: echo " "; 260: 261: 262: // this month 263: $sx=mktime(0,0,0,$td_mon,1,$td_yr); 264: $sx=$now; 265: echo ""; 266: echo "This Month"; 267: echo " "; 268: 269: 270: echo "

";
271: echo "Reported Tests
";
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 "
".$row['nodeid']."
";
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 " "; 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']."
";
293: } 294: $NATS->DB->Free($nr); 295: 296: 297: } 298: echo " "; 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 "
";
307: } 308: $NATS->DB->Free($r); 309: 310: echo "

";
311: echo ""; 312: echo "
";
313: echo " Show breakdown details
";
314: echo ""; 315: Screen_Footer(); 316: exit(); 317: 318: 319: } 320: 321: if ($mode!="report") 322: { 323: Screen_Header("Error"); 324: echo "Sorry - illegal mode specified

";
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 "Reporting from ".nicedt($startx)." to ".nicedt($finishx)."

";
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 "".$tname.""; 424: if ($usesubname) echo " - ".$subtname.""; 425: echo " on ".$tnode.""; 426: echo "
";
427: 428: //echo "node "; 429: //echo "".$tnode.""; 430: //echo " - "; 431: echo ""; 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 "
"; 441: 442: 443: //echo "".$tname." from ".nicedt($startx)." to ".nicedt($finishx); 444: //if ($tunit!="") echo " (".$tunit.")"; 445: // echo " (".nicediff($finishx-$startx).")"; 446: //echo "

"; 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 ""; 504: 505: if (isset($_REQUEST['showdetail'])) 506: { 507: echo ""; 511: 512: $notpass=$tested-$passc; 513: 514: echo ""; 518: 519: echo ""; 520: 521: echo ""; 525: 526: echo ""; 530: 531: echo ""; 535: 536: echo ""; 540: 541: echo ""; 542: 543: echo ""; 544: echo ""; 550: 551: echo ""; 552: 553: $utt=$untested+$tested; 554: echo ""; 555: echo ""; 558: 559: $npt=$untested+$notpass; 560: echo ""; 561: echo ""; 564: 565: echo ""; 566: echo ""; 569: 570: echo ""; 571: 572: echo ""; 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 ""; 589: } 590: 591: echo ""; 592: echo ""; 596: 597: echo ""; 601: 602: echo ""; 603: echo ""; 608: 609: echo "
".$passc." passed out of ".$tested." valid tests"; 508: echo " "; 509: echo np($tested,$passc); 510: echo "
".$notpass." did not pass out of ".$tested." valid tests"; 515: echo " "; 516: echo np($tested,$notpass); 517: echo "
 
".$warnc." generated warnings out of ".$tested." valid tests"; 522: echo " "; 523: echo np($tested,$warnc); 524: echo "
".$failc." generated failures out of ".$tested." valid tests"; 527: echo " "; 528: echo np($tested,$failc); 529: echo "
".$warnc." generated warnings out of ".$notpass." unpassed tests"; 532: echo " "; 533: echo np($notpass,$warnc); 534: echo "
".$failc." generated failures out of ".$notpass." unpassed tests"; 537: echo " "; 538: echo np($notpass,$failc); 539: echo "
 
the average test value returned by passed tests was "; 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 "
 
".$untested." tests were untested (of ".$utt.") "; 556: echo np($utt,$untested); 557: echo "
of these (".$utt.") ".$npt." did not pass "; 562: echo np($utt,$npt); 563: echo "
of these (".$utt.") ".$passc." did pass "; 567: echo np($utt,$passc); 568: echo "
 
".$testc." records of which ".$tested." returned a valid alert level"; 573: echo " "; 574: echo np($testc,$tested); 575: echo "
".$testc." records and you should have ".hlink("History:Should",12)." ".$shouldhave; 586: echo " "; 587: echo np($shouldhave,$testc); 588: echo "
 
First Test Record"; 593: echo " "; 594: echo nicedt($firstx); 595: echo "
Last Test Record"; 598: echo " "; 599: echo nicedt($lastx); 600: echo "
 
Service Availability"; 604: echo " "; 605: // Service level is tested-failed 606: echo np($tested,$tested-$failc); 607: echo "

";
610: 611: /* - zoom period debugging 612: echo "Period: $p s (".($p/$five_min).")
";
613: echo "sx: ".$startx." fx: ".$finishx."
";
614: echo "diffx: ".($finishx-$startx)."
";
615: echo "fx2: ".$fx." p: ".$p."
";
616: */ 617: 618: 619: echo "


";
620: } 621: Screen_Footer(); 622: ?> 623: