File: 0.04.29a/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: echo " "; 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 "
";
292: } 293: $NATS->DB->Free($r); 294: 295: echo "

";
296: echo ""; 297: echo "
";
298: echo " Show breakdown details
";
299: echo ""; 300: Screen_Footer(); 301: exit(); 302: 303: 304: } 305: 306: if ($mode!="report") 307: { 308: Screen_Header("Error"); 309: echo "Sorry - illegal mode specified

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

";
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 "".$tname.""; 393: if ($usesubname) echo " - ".$subtname.""; 394: echo " on ".$tnode.""; 395: echo "
";
396: 397: //echo "node "; 398: //echo "".$tnode.""; 399: //echo " - "; 400: echo ""; 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 "
"; 410: 411: 412: //echo "".$tname." from ".nicedt($startx)." to ".nicedt($finishx); 413: //if ($tunit!="") echo " (".$tunit.")"; 414: // echo " (".nicediff($finishx-$startx).")"; 415: //echo "

"; 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 ""; 473: 474: if (isset($_REQUEST['showdetail'])) 475: { 476: echo ""; 480: 481: $notpass=$tested-$passc; 482: 483: echo ""; 487: 488: echo ""; 489: 490: echo ""; 494: 495: echo ""; 499: 500: echo ""; 504: 505: echo ""; 509: 510: echo ""; 511: 512: echo ""; 513: echo ""; 519: 520: echo ""; 521: 522: $utt=$untested+$tested; 523: echo ""; 524: echo ""; 527: 528: $npt=$untested+$notpass; 529: echo ""; 530: echo ""; 533: 534: echo ""; 535: echo ""; 538: 539: echo ""; 540: 541: echo ""; 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 ""; 558: } 559: 560: echo ""; 561: echo ""; 565: 566: echo ""; 570: 571: echo ""; 572: echo ""; 577: 578: echo "
".$passc." passed out of ".$tested." valid tests"; 477: echo " "; 478: echo np($tested,$passc); 479: echo "
".$notpass." did not pass out of ".$tested." valid tests"; 484: echo " "; 485: echo np($tested,$notpass); 486: echo "
 
".$warnc." generated warnings out of ".$tested." valid tests"; 491: echo " "; 492: echo np($tested,$warnc); 493: echo "
".$failc." generated failures out of ".$tested." valid tests"; 496: echo " "; 497: echo np($tested,$failc); 498: echo "
".$warnc." generated warnings out of ".$notpass." unpassed tests"; 501: echo " "; 502: echo np($notpass,$warnc); 503: echo "
".$failc." generated failures out of ".$notpass." unpassed tests"; 506: echo " "; 507: echo np($notpass,$failc); 508: echo "
 
the average test value returned by passed tests was "; 514: if ($passc<=0) echo "n/a"; 515: else if ($levelt==0) echo "0"; 516: else echo round($levelt/$passc,4); 517: if ($tunit!="") echo " ".$tunit; 518: echo "
 
".$untested." tests were untested (of ".$utt.") "; 525: echo np($utt,$untested); 526: echo "
of these (".$utt.") ".$npt." did not pass "; 531: echo np($utt,$npt); 532: echo "
of these (".$utt.") ".$passc." did pass "; 536: echo np($utt,$passc); 537: echo "
 
".$testc." records of which ".$tested." returned a valid alert level"; 542: echo " "; 543: echo np($testc,$tested); 544: echo "
".$testc." records and you should have ".hlink("History:Should",12)." ".$shouldhave; 555: echo " "; 556: echo np($shouldhave,$testc); 557: echo "
 
First Test Record"; 562: echo " "; 563: echo nicedt($firstx); 564: echo "
Last Test Record"; 567: echo " "; 568: echo nicedt($lastx); 569: echo "
 
Service Availability"; 573: echo " "; 574: // Service level is tested-failed 575: echo np($tested,$tested-$failc); 576: echo "

";
579: 580: /* - zoom period debugging 581: echo "Period: $p s (".($p/$five_min).")
";
582: echo "sx: ".$startx." fx: ".$finishx."
";
583: echo "diffx: ".($finishx-$startx)."
";
584: echo "fx2: ".$fx." p: ".$p."
";
585: */ 586: 587: 588: echo "


";
589: } 590: Screen_Footer(); 591: ?> 592: