File: 1.12.0a/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: if ($mode=="savereport") 37: { 38: if ($NATS_Session->userlevel<5) UL_Error("Save Report"); 39: $q="INSERT INTO fnreport(reportname,reporttests) VALUES(\"".ss($_REQUEST['reportname'])."\",\"".ss($_REQUEST['reporttests'])."\")"; 40: $NATS->DB->Query($q); 41: header("Location: main.php?mode=views&message=Saved+Report"); 42: exit(); 43: } 44: 45: if ($mode=="delete") 46: { 47: if ($NATS_Session->userlevel<5) UL_Error("Delete Report"); 48: if (!isset($_REQUEST['confirmed'])) 49: { 50: $back="report.php?mode=delete&reportid=".$_REQUEST['reportid']."&confirmed=1"; 51: $back=urlencode($back); 52: $msg=urlencode("Delete availability report"); 53: header("Location: confirm.php?action=".$msg."&back=".$back); 54: exit(); 55: } 56: $q="DELETE FROM fnreport WHERE reportid=".ss($_REQUEST['reportid']); 57: $NATS->DB->Query($q); 58: $message=urlencode("Report Deleted"); 59: header("Location: main.php?mode=views&message=".$message); 60: exit(); 61: } 62: 63: $testlist=array(); 64: if (isset($_REQUEST['reportid'])) 65: { 66: $q="SELECT * FROM fnreport WHERE reportid=".ss($_REQUEST['reportid'])." LIMIT 0,1"; 67: $r=$NATS->DB->Query($q); 68: if ($rep=$NATS->DB->Fetch_Array($r)) 69: { 70: $testlist=explode(":",$rep['reporttests']); 71: } 72: } 73: 74: 75: function slist($var,$min,$max,$val) 76: { 77: echo "\n\n"; 82: } 83: 84: function cbd($var,$name) 85: { 86: if (isset($_REQUEST[$var])) $s=" checked"; 87: else $s=""; 88: echo " ".$name; 89: } 90: 91: function np($big,$part) 92: { 93: if ($big==0) return "n/a"; 94: if ($part==0) return "0%"; 95: 96: $p=($part/$big)*100; 97: $p=round($p,2); 98: return $p."%"; 99: } 100: 101: $td_day=date("d"); 102: $td_mon=date("m"); 103: $td_yr=date("Y"); 104: 105: $start=array(); 106: $finish=array(); 107: if (isset($_REQUEST['st_day'])) $start['day']=$_REQUEST['st_day']; 108: else $start['day']=$td_day; 109: if (isset($_REQUEST['st_mon'])) $start['mon']=$_REQUEST['st_mon']; 110: else $start['mon']=$td_mon; 111: if (isset($_REQUEST['st_yr'])) $start['yr']=$_REQUEST['st_yr']; 112: else $start['yr']=$td_yr; 113: if (isset($_REQUEST['st_hour'])) $start['hour']=$_REQUEST['st_hour']; 114: else $start['hour']=0; 115: if (isset($_REQUEST['st_min'])) $start['min']=$_REQUEST['st_min']; 116: else $start['min']=0; 117: if (isset($_REQUEST['st_sec'])) $start['sec']=$_REQUEST['st_sec']; 118: else $start['sec']=0; 119: 120: if (isset($_REQUEST['fi_day'])) $finish['day']=$_REQUEST['fi_day']; 121: else $finish['day']=$td_day; 122: if (isset($_REQUEST['fi_mon'])) $finish['mon']=$_REQUEST['fi_mon']; 123: else $finish['mon']=$td_mon; 124: if (isset($_REQUEST['fi_yr'])) $finish['yr']=$_REQUEST['fi_yr']; 125: else $finish['yr']=$td_yr; 126: if (isset($_REQUEST['fi_hour'])) $finish['hour']=$_REQUEST['fi_hour']; 127: else $finish['hour']=23; 128: if (isset($_REQUEST['fi_min'])) $finish['min']=$_REQUEST['fi_min']; 129: else $finish['min']=59; 130: if (isset($_REQUEST['fi_sec'])) $finish['sec']=$_REQUEST['fi_sec']; 131: else $finish['sec']=59; 132: 133: if (isset($_REQUEST['startx'])) 134: { 135: $start['day']=date("d",$_REQUEST['startx']); 136: $start['mon']=date("m",$_REQUEST['startx']); 137: $start['yr']=date("Y",$_REQUEST['startx']); 138: $start['hour']=date("H",$_REQUEST['startx']); 139: $start['min']=date("i",$_REQUEST['startx']); 140: $start['sec']=date("s",$_REQUEST['startx']); 141: $startx=$_REQUEST['startx']; 142: } 143: else 144: $startx=mktime($start['hour'],$start['min'],$start['sec'],$start['mon'],$start['day'],$start['yr']); 145: 146: if (isset($_REQUEST['finishx'])) 147: { 148: $finish['day']=date("d",$_REQUEST['finishx']); 149: $finish['mon']=date("m",$_REQUEST['finishx']); 150: $finish['yr']=date("Y",$_REQUEST['finishx']); 151: $finish['hour']=date("H",$_REQUEST['finishx']); 152: $finish['min']=date("i",$_REQUEST['finishx']); 153: $finish['sec']=date("s",$_REQUEST['finishx']); 154: $finishx=$_REQUEST['finishx']; 155: } 156: else 157: $finishx=mktime($finish['hour'],$finish['min'],$finish['sec'],$finish['mon'],$finish['day'],$finish['yr']); 158: //echo $startx." ".nicedt($startx)."
";
159: //echo $finishx." ".nicedt($finishx)."
";
160: 161: 162: if ($mode=="") 163: { 164: Screen_Header("Service Availability Report",1); 165: ob_end_flush(); 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: echo "Reporting Period

";
176: echo "
"; 177: echo "
";
178: echo "
"; 179: echo " Custom Period"; 180: echo ""; 181: echo ""; 182: echo ""; 183: 184: 185: 186: 187: 188: echo ""; 189: echo ""; 193: 194: echo ""; 198: 199: echo ""; 203: 204: echo ""; 208: 209: echo ""; 213: 214: echo ""; 220: 221: echo ""; 222: 223: // ----- finish 224: 225: echo ""; 226: echo ""; 230: 231: echo ""; 235: 236: echo ""; 240: 241: echo ""; 245: 246: echo ""; 250: 251: echo ""; 257: 258: echo ""; 259: 260: 261: 262: echo "
 HourMinSecDayMonYear
Start:"; 190: slist("st_hour",0,23,$start['hour']); 191: echo ":"; 192: echo ""; 195: slist("st_min",0,59,$start['min']); 196: echo ":"; 197: echo ""; 200: slist("st_sec",0,59,$start['sec']); 201: echo "  "; 202: echo ""; 205: slist("st_day",1,31,$start['day']); 206: echo "/"; 207: echo ""; 210: slist("st_mon",1,12,$start['mon']); 211: echo "/"; 212: echo ""; 215: echo ""; 216: 217: echo " "; 218: 219: echo "
Finish:"; 227: slist("fi_hour",0,23,$finish['hour']); 228: echo ":"; 229: echo ""; 232: slist("fi_min",0,59,$finish['min']); 233: echo ":"; 234: echo ""; 237: slist("fi_sec",0,59,$finish['sec']); 238: echo "  "; 239: echo ""; 242: slist("fi_day",1,31,$finish['day']); 243: echo "/"; 244: echo ""; 247: slist("fi_mon",1,12,$finish['mon']); 248: echo "/"; 249: echo ""; 252: echo ""; 253: 254: echo " "; 255: 256: echo "
";
263: 264: 265: echo "
"; 266: echo "Pre-defined "; 267: echo ""; 268: $now=time(); 269: /* 270: // td_day mon yr 271: 272: // mktime h mi s mo d y 273: 274: // last 30 days 275: $fx=mktime(0,0,0,$td_mon,$td_day,$td_yr); 276: $sx=$fx-(60*60*24*30); 277: echo ""; 278: echo "Last 30 Days"; 279: echo " "; 280: 281: // last 28 days 282: $fx=mktime(0,0,0,$td_mon,$td_day,$td_yr); 283: $sx=$fx-(60*60*24*28); 284: echo ""; 285: echo "Last 28 Days"; 286: echo " "; 287: 288: // last calendar month 289: $prev_mon=$td_mon-1; 290: $prev_yr=$td_yr; 291: if ($prev_mon<1) 292: { 293: $prev_mon=12; 294: $prev_yr--; 295: } 296: $fx=mktime(0,0,0,$td_mon,1,$td_yr); 297: $sx=mktime(0,0,0,$prev_mon,1,$prev_yr); 298: echo ""; 299: echo "Previous Month"; 300: echo " "; 301: 302: 303: // this month 304: $sx=mktime(0,0,0,$td_mon,1,$td_yr); 305: $sx=$now; 306: echo ""; 307: echo "This Month"; 308: echo " "; 309: */ 310: 311: echo " Last 30 Days
";
312: echo " Last 28 Days
";
313: echo " Last Calendar Month
";
314: echo " This Month
";
315: 316: echo "
";
317: echo "

";
318: 319: echo "Reported Tests
";
320: 321: $q="SELECT localtestid,nodeid,testname,testtype,testparam,testrecord FROM fnlocaltest WHERE testrecord>0 OR testtype=\"ICMP\" ORDER BY nodeid"; 322: $r=$NATS->DB->Query($q); 323: $lastnode=""; 324: while ($row=$NATS->DB->Fetch_Array($r)) 325: { 326: if ($row['nodeid']!=$lastnode) 327: { 328: echo "
".$row['nodeid']."
";
329: $lastnode=$row['nodeid']; 330: 331: // Bodge in node-side tests here 332: $nq="SELECT nstestid,testname,testtype,testdesc FROM fnnstest WHERE testrecord>0 AND nodeid=\"".ss($row['nodeid'])."\""; 333: $nr=$NATS->DB->Query($nq); 334: while ($nrow=$NATS->DB->Fetch_Array($nr)) 335: { 336: if (in_array("N".$nrow['nstestid'],$testlist)) $s=" checked"; 337: else $s=""; 338: echo " "; 339: if ($nrow['testname']!="") echo $nrow['testname']; 340: else if ($nrow['testdesc']!="") echo $nrow['testdesc']; 341: else echo $nrow['testtype']; 342: echo " on ".$row['nodeid']."
";
343: } 344: $NATS->DB->Free($nr); 345: 346: 347: } 348: if (in_array("L".$row['localtestid'],$testlist)) $s=" checked"; 349: else $s=""; 350: echo " "; 351: if ($row['testname']!="") echo $row['testname']; 352: else 353: { 354: echo lText($row['testtype']); 355: if ($row['testparam']!="") echo " (".$row['testparam'].")"; 356: } 357: echo " on ".$row['nodeid']; 358: echo "
";
359: } 360: $NATS->DB->Free($r); 361: 362: echo "

";
363: echo ""; 364: echo "
";
365: echo " Show breakdown details
";
366: echo ""; 367: Screen_Footer(); 368: exit(); 369: 370: 371: } 372: 373: if ($mode!="report") 374: { 375: Screen_Header("Error"); 376: echo "Sorry - illegal mode specified

";
377: Screen_Footer(); 378: exit(); 379: } 380: 381: 382: 383: 384: 385: // the actual run 386: 387: Screen_Header("Availability Report"); 388: ob_end_flush(); 389: 390: if (isset($_REQUEST['period'])) $period=$_REQUEST['period']; 391: else $period=""; 392: $now=time(); 393: $nowx=$now; 394: switch ($period) 395: { 396: // td_day mon yr 397: 398: // mktime h mi s mo d y 399: 400: case "last30days": 401: // last 30 days 402: $finishx=mktime(0,0,0,$td_mon,$td_day,$td_yr); 403: $startx=$finishx-(60*60*24*30); 404: break; 405: 406: case "last28days": 407: $fx=mktime(0,0,0,$td_mon,$td_day,$td_yr); 408: $sx=$finishx-(60*60*24*28); 409: break; 410: 411: case "lastcalmonth": 412: // last calendar month 413: $prev_mon=$td_mon-1; 414: $prev_yr=$td_yr; 415: if ($prev_mon<1) 416: { 417: $prev_mon=12; 418: $prev_yr--; 419: } 420: $finishx=mktime(0,0,0,$td_mon,1,$td_yr); 421: $startx=mktime(0,0,0,$prev_mon,1,$prev_yr); 422: break; 423: 424: case "thiscalmonth": case "thismonth": 425: // this month 426: $startx=mktime(0,0,0,$td_mon,1,$td_yr); 427: $finishx=$now; 428: break; 429: } 430: 431: echo "Reporting from ".nicedt($startx)." to ".nicedt($finishx)."

";
432: 433: foreach($_REQUEST['testlist'] as $testid) 434: { 435: 436: $tmode=""; 437: switch($testid[0]) 438: { 439: case "L": $tmode="local"; 440: break; 441: case "N": $tmode="nodeside"; 442: break; 443: default: $tmode="unknown"; 444: } 445: $stid=substr($testid,1,128); 446: 447: // get test info 448: $tnode=""; 449: $tname=""; 450: $ttype=""; 451: $tparam=""; 452: $tlastrunx=""; 453: $trecord=1; 454: 455: $q=""; 456: if ($tmode=="local") $q="SELECT * FROM fnlocaltest WHERE localtestid=".ss($stid); 457: else if ($tmode=="nodeside") $q="SELECT * FROM fnnstest WHERE nstestid=".ss($stid); 458: 459: $r=$NATS->DB->Query($q); 460: 461: if (!$row=$NATS->DB->Fetch_Array($r)) 462: { 463: header("main.php?message=Error+opening+test+history"); 464: exit(); 465: } 466: 467: 468: 469: $tnode=$row['nodeid']; 470: $ttype=$row['testtype']; 471: if (isset($row['testparam'])) $tparam=$row['testparam']; 472: else $tparam=""; 473: $tlastrunx=$row['lastrunx']; 474: $tunit=""; 475: 476: if ($tmode=="local") 477: { 478: $tname=lText($ttype); 479: $tunit=lUnit($ttype); 480: if ($tparam!="") $tname.=" (".$tparam.")"; 481: if ($row['testname']!="") 482: { 483: $subtname=$tname; 484: $tname=$row['testname']; 485: $usesubname=true; 486: } 487: else $usesubname=false; 488: } 489: else if ($tmode=="nodeside") 490: { 491: if ($row['testname']!="") $tname=$row['testname']; 492: else $tname=$row['testtype']; 493: $subtname=$row['testdesc']; 494: $usesubname=true; 495: } 496: $NATS->DB->Free($r); 497: 498: 499: 500: 501: $diffx=$finishx-$startx; 502: $periods=8; 503: $periodx=$diffx/$periods; 504: $hperiodx=round($periodx/2,0); 505: $periodx=round($periodx,0); 506: $iwid=700; 507: $ihei=150; 508: $istart=50; 509: $iend=$iwid-5; 510: $idwid=$iend-$istart; 511: $iscale=$idwid/$periods; 512: 513: 514: 515: 516: echo "".$tname.""; 517: if ($usesubname) echo " - ".$subtname.""; 518: echo " on ".$tnode.""; 519: echo "
";
520: 521: //echo "node "; 522: //echo "".$tnode.""; 523: //echo " - "; 524: echo ""; 525: echo "Last Run : "; 526: 527: if ($tlastrunx>0) 528: { 529: echo nicedt($tlastrunx)." - "; 530: echo dtago($tlastrunx); 531: } 532: else echo "Never"; 533: echo "
";
534: 535: 536: //echo "".$tname." from ".nicedt($startx)." to ".nicedt($finishx); 537: //if ($tunit!="") echo " (".$tunit.")"; 538: // echo " (".nicediff($finishx-$startx).")"; 539: //echo "

"; 540: 541: 542: 543: // table data 544: 545: 546: $q="SELECT alertlevel,testvalue,recordx FROM fnrecord WHERE "; 547: $q.="testid=\"".ss($testid)."\" AND recordx>=".ss($startx)." AND recordx<=".ss($finishx); 548: //if (!isset($_REQUEST['disp_pass'])) $q.=" AND alertlevel!=0"; 549: $q.=" ORDER BY recordx ASC"; 550: 551: $firstx=0; 552: $lastx=0; 553: $records=0; 554: 555: //echo $q; 556: $r=$NATS->DB->Query($q); 557: 558: $testc=0; 559: $tested=0; 560: $untested=0; 561: $passc=0; 562: $warnc=0; 563: $failc=0; 564: $levelt=0; 565: 566: while ($row=$NATS->DB->Fetch_Array($r)) 567: { 568: $testc++; 569: $records++; 570: if ($firstx==0) $firstx=$row['recordx']; 571: $lastx=$row['recordx']; 572: switch ($row['alertlevel']) 573: { 574: case 0: 575: $passc++; 576: $tested++; 577: $levelt+=$row['testvalue']; 578: break; 579: case 1: 580: $warnc++; 581: $tested++; 582: //$levelt+=$row['testvalue']; 583: break; 584: case 2: 585: $failc++; 586: $tested++; 587: //$levelt+=$row['testvalue']; 588: break; 589: case -1: 590: $untested++; 591: break; 592: } 593: } 594: 595: 596: echo ""; 597: 598: if (isset($_REQUEST['showdetail'])) 599: { 600: echo ""; 604: 605: $notpass=$tested-$passc; 606: 607: echo ""; 611: 612: echo ""; 613: 614: echo ""; 618: 619: echo ""; 623: 624: echo ""; 628: 629: echo ""; 633: 634: echo ""; 635: 636: echo ""; 637: echo ""; 643: 644: echo ""; 645: 646: $utt=$untested+$tested; 647: echo ""; 648: echo ""; 651: 652: $npt=$untested+$notpass; 653: echo ""; 654: echo ""; 657: 658: echo ""; 659: echo ""; 662: 663: echo ""; 664: 665: echo ""; 669: 670: $nowx=time(); 671: if ($finishx>$nowx) $fx=$nowx; 672: else $fx=$finishx; 673: $p=$fx-$startx; 674: $five_min=60*5; 675: $shouldhave=floor($p/$five_min); 676: 677: } 678: 679: echo ""; 680: echo ""; 684: 685: echo ""; 689: 690: echo ""; 691: echo ""; 696: 697: echo "
".$passc." passed out of ".$tested." valid tests"; 601: echo " "; 602: echo np($tested,$passc); 603: echo "
".$notpass." did not pass out of ".$tested." valid tests"; 608: echo " "; 609: echo np($tested,$notpass); 610: echo "
 
".$warnc." generated warnings out of ".$tested." valid tests"; 615: echo " "; 616: echo np($tested,$warnc); 617: echo "
".$failc." generated failures out of ".$tested." valid tests"; 620: echo " "; 621: echo np($tested,$failc); 622: echo "
".$warnc." generated warnings out of ".$notpass." unpassed tests"; 625: echo " "; 626: echo np($notpass,$warnc); 627: echo "
".$failc." generated failures out of ".$notpass." unpassed tests"; 630: echo " "; 631: echo np($notpass,$failc); 632: echo "
 
the average test value returned by passed tests was "; 638: if ($passc<=0) echo "n/a"; 639: else if ($levelt==0) echo "0"; 640: else echo round($levelt/$passc,4); 641: if ($tunit!="") echo " ".$tunit; 642: echo "
 
".$untested." tests were untested (of ".$utt.") "; 649: echo np($utt,$untested); 650: echo "
of these (".$utt.") ".$npt." did not pass "; 655: echo np($utt,$npt); 656: echo "
of these (".$utt.") ".$passc." did pass "; 660: echo np($utt,$passc); 661: echo "
 
".$testc." records of which ".$tested." returned a valid alert level"; 666: echo " "; 667: echo np($testc,$tested); 668: echo "
 
First Test Record"; 681: echo " "; 682: echo nicedt($firstx); 683: echo "
Last Test Record"; 686: echo " "; 687: echo nicedt($lastx); 688: echo "
 
Service Availability"; 692: echo " "; 693: // Service level is tested-failed 694: echo np($tested,$tested-$failc); 695: echo "

";
698: 699: /* - zoom period debugging 700: echo "Period: $p s (".($p/$five_min).")
";
701: echo "sx: ".$startx." fx: ".$finishx."
";
702: echo "diffx: ".($finishx-$startx)."
";
703: echo "fx2: ".$fx." p: ".$p."
";
704: */ 705: 706: 707: echo "


";
708: } 709: 710: $savestring=""; 711: $first=true; 712: foreach($_REQUEST['testlist'] as $testid) 713: { 714: if ($first) $first=false; 715: else $savestring.=":"; 716: $savestring.=$testid; 717: } 718: echo "
"; 719: echo ""; 720: echo ""; 721: echo "Save Report As "; 722: echo "

";
723: 724: Screen_Footer(); 725: ?> 726: