Fixed nag.php

This commit is contained in:
Will Bradley 2012-02-18 20:47:10 -07:00
parent cadb70da77
commit 4bcd4462d0

62
nag.php
View File

@ -1,7 +1,6 @@
<?php <?php
// nag.php by Will Bradley, www.zyphon.com/arduino-nagios // nag.php by Will Bradley, www.zyphon.com/arduino-nagios
// Script to parse Nagios status.dat and present it in simplified HTML. // Script to parse Nagios status.dat and present it in simplified HTML.
// usage: nag.php for human view, nag.php?minimal=1 for computer view.
// //
// Based on statusXML.php by Jason Antman // Based on statusXML.php by Jason Antman
// //
@ -29,14 +28,12 @@
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// | Authors: Jason Antman <jason@jasonantman.com> | // | Authors: Jason Antman <jason@jasonantman.com> |
// +----------------------------------------------------------------------+ // +----------------------------------------------------------------------+
// $Id: nag.php,v 1.0 2011/12/11 03:76:14 wbradley Exp $ // $Id: statusXML.php,v 1.6 2009/02/07 03:32:14 jantman Exp $
// $Source: ArduinoNagiosDisplay/nag.php,v $ // $Source: /usr/local/cvsroot/admin-portal/nagios/statusXML.php,v $
// change the statusFile to the location of status.dat on your Nagios system
$statusFile = "/var/cache/nagios3/status.dat"; $statusFile = "/var/cache/nagios3/status.dat";
// ------------- end config
$nag_version = getFileVersion($statusFile); // returns integer 2 or 3 $nag_version = getFileVersion($statusFile); // returns integer 2 or 3
$created_ts = 0; $created_ts = 0;
@ -71,12 +68,12 @@ $ret = "";
// begin outputting XML // begin outputting XML
//header("Content-type: text/xml"); //header("Content-type: text/xml");
if($minimal){ if($minimal){
$ret .= "$"; $ret .= "^";
} }
else { else {
$ret .= "<html>"."\n"; $ret .= "<html>"."\n";
$ret .= '<head><style type="text/css">body {font:15px arial,sans-serif; } dt { font-weight: bold; float: left; margin-right: 1em; }</style></head>'."\n"; $ret .= '<head><style type="text/css">body { background-color: #fff; font:15px arial,sans-serif; } table {margin: 10px auto; } th { width: 400px; text-align: left; } .OK { background-color: green; } .WARNING { background-color: yellow; } .CRITICAL { background-color: red; } .perf { color: #666; font-size: 0.7em; padding-left: 50px; } </style></head>'."\n";
$ret .= "<body>"."\n"; $ret .= "<body>"."<table>\n";
} }
// program status // program status
/* /*
@ -99,8 +96,24 @@ $ret = "";
$ret .= $hostArray['current_state']; $ret .= $hostArray['current_state'];
} }
else { else {
$ret .= "<dt>".$hostArray['host_name']."</dt>"; $ret .= "<tr>";
$ret .= "<dd>".$hostArray['current_state']."</dd>"; $ret .= "<th>".$hostArray['host_name']."</th>";
switch($hostArray['current_state']) {
case 0:
$hoststate = "OK";
break;
case 1:
$hoststate = "WARNING";
break;
case 2:
$hoststate = "CRITICAL";
break;
}
$ret .= "<td class='".$hoststate."'>";
$ret .= $hoststate;
$ret .= "</td>";
$ret .= "<td class='perf'>".$hostArray['plugin_output']."</td>";
$ret .= "</tr>";
} }
/* /*
$current_state = $hostArray['current_state']; $current_state = $hostArray['current_state'];
@ -124,14 +137,33 @@ $ret = "";
$ret .= $serviceArray['current_state']; $ret .= $serviceArray['current_state'];
} }
else { else {
$ret .= "<dt>".$serviceArray['host_name']." ".$serviceArray['service_description']."</dt>"; $ret .= "<tr>";
$ret .= "<dd>".$serviceArray['current_state']."</dd>"; $ret .= "<th>".$serviceArray['host_name']." ".$serviceArray['service_description']."</th>";
switch($serviceArray['current_state']) {
case 0:
$servstate = "OK";
break;
case 1:
$servstate = "WARNING";
break;
case 2:
$servstate = "CRITICAL";
break;
}
$ret .= "<td class='".$servstate."'>";
$ret .= $servstate;
$ret .= "</td>";
$ret .= "<td class='perf'>".$serviceArray['plugin_output']."</td>";
$ret .= "</tr>";
} }
} }
} }
if(!$minimal){ if($minimal){
$ret .= "</body></html>"; $ret .= "$";
}
else{
$ret .= "</table></body></html>";
} }
return $ret; return $ret;
} }