Extension talk:NagiosStatus


 * Doesn't appear to work with MediaWiki 1.11. SeanFromIT 18:12, 2 October 2007 (UTC)
 * 1) Does anybody want to help me fix this? $output seems to be null.


 * Added a new parameter so that it displays a specific host's service checks summary.  I will update the new version to the main wiki page soon. -- (Smcnaught) 20:18, 4 August 2006 (UTC)

Example: host=10.0.0.1

<?php
 * 1) NagiosStatus Mediawiki extension
 * 2) original by smcnaught 24.07.2005  - I am also available on irc.chekmate.org #MediaWiki
 * 3) Installation:
 * 4)  * put this file (NagiosStatus.php) into the extension directory of your mediawiki installation
 * 5)  * add the following to the end of LocalSettings.php: include("extensions/NagiosStatus.php");
 * 6)  * configure Nagios's web server to allow wiki server to access without username/password
 * 7)  * remove table's background parameter from skin/monobook/main.css style sheet.
 * 8) Usage:
 * 9)  Use one section between -tags for each feed.
 * 10) Example:
 * 11)    status
 * 12)    hosts
 * 13)    services
 * 14)    host=10.0.0.1
 * 1)    hosts
 * 2)    services
 * 3)    host=10.0.0.1</NagiosStatus>

$wgExtensionFunctions[] = "wfNagiosStatusExtension"; function wfNagiosStatusExtension { global $wgParser; #install parser hook for  tags $wgParser->setHook( "NagiosStatus", "renderNagiosStatus" ); } function renderNagiosStatus( $input, $argv, &$parser ) { global $wgVersion, $wgTitle, $wgDBprefix, $wgOut, $wgUser, $wgRequest; // ###### DEFINE VARIABLES TO Nagios Server ###### # Root URL $Nagios_Web_Server = "https://nagios/"; # Nagios CGI-BIN Directory $Nagios_CGI_URL = "https://nagios/nagios/cgi-bin/"; // ###### INVALIDATE CACHE ###### $ts = mktime; $now = gmdate("YmdHis", $ts + 120); $ns = $wgTitle->getNamespace; $ti = wfStrencode($wgTitle->getDBkey); $version = preg_replace("/^([1-9]).([1-9]).*/", "\\1\\2", $wgVersion); if ($version>14) $sql = "UPDATE $wgDBprefix"."page SET page_touched='$now' WHERE page_namespace=$ns AND page_title='$ti'"; else            $sql = "UPDATE $wgDBprefix"."cur SET cur_touched='$now' WHERE cur_namespace=$ns AND cur_title='$ti'"; wfQuery($sql, DB_WRITE, ""); // ###### LOAD PAGE ###### $URL = $Nagios_CGI_URL. "status.cgi"; $aParams = explode("\n", $input); if (preg_match("/host=/i",$aParams[0])) { $URL = $URL. "?" . $aParams[0]; } $loadpage =  file_get_contents($URL); $loadpage = preg_replace("/<A /","<A target=_new ",$loadpage); $loadpage = preg_replace("/<a /","<a target=_new ",$loadpage); $loadpage = preg_replace("/HREF='http:\/\/www.nagios.org/","autoref='http://www.nagios.org",$loadpage); $loadpage = preg_replace("/IMG SRC='\//","IMG SRC='$Nagios_Web_Server",$loadpage); $loadpage = preg_replace("/img src='\//","IMG SRC='$Nagios_Web_Server",$loadpage); $loadpage = preg_replace("/href='\//","autoref='$Nagios_Web_Server",$loadpage); $loadpage = preg_replace("/href='/","autoref='$Nagios_CGI_URL",$loadpage); $loadpage = preg_replace("/HREF='\//","autoref='$Nagios_Web_Server",$loadpage); $loadpage = preg_replace("/HREF='/","autoref='$Nagios_CGI_URL",$loadpage); $loadpage = preg_replace("/autoref/","HREF",$loadpage); $loadpage = preg_replace("/<\/head>/","",$loadpage); $loadpage = preg_replace("/\(null\)/","all",$loadpage); $elements = explode("\n",$loadpage); $inbody = 0;
 * 1) install extension hook
 * 1) extension hook callback function
 * 1) parser hook callback function

// ###### PARSE PARAMETERS ###### foreach($aParams as $sParam) { if (preg_match("/host=/i",$sParam)) { $sParam = "status"; }   switch ($sParam) { case 'status': foreach ($elements as $element) { if (preg_match("/LINK REL='stylesheet'/",$element)) { $output = $output. $element. "\n"; }         if ($inbody) { if (preg_match("/<\/body>/",$element)) { $inbody = 0; } else { $output = $output. $element. "\n"; }         } else { if (preg_match("/Service Status Details/",$element)) { $inbody = 1; $output = $output. $element. "\n"; }         }        }        break; case 'hosts': foreach ($elements as $element) { if (preg_match("/LINK REL='stylesheet'/",$element)) { $output = $output. $element. "\n"; }         if ($inbody) { if (preg_match("/<\/DIV>/",$element)) { $inbody = 0; } else { $output = $output. $element. "\n"; }         } else { if (preg_match("/<DIV CLASS='hostTotals'>Host Status Totals<\/DIV>/",$element)) { $inbody = 1; }         }        }        break; case 'services': foreach ($elements as $element) { if (preg_match("/LINK REL='stylesheet'/",$element)) { $output = $output. $element. "\n"; }         if ($inbody) { if (preg_match("/<\/DIV/",$element)) { $inbody = 0; } else { $output = $output. $element. "\n"; }         } else { if (preg_match("/<DIV CLASS='serviceTotals'>Service Status Totals<\/DIV>/",$element)) { $inbody = 1; }         }        }        break; } }  $output = "<span class=\"plainlinks\">". $output. " "; # Remove Pad Locks
 * 1)           if (preg_match("/<body CLASS='status'>/",$element)) {

return $output; } ?>
 * 1)  $localParser = new Parser;
 * 2)  $output = $localParser->parse("Hello", $parser->mTitle, $parser->mOptions,true,false);
 * 3)  $text = $output->getText;

If you have Nagios configured with authentication
I was able to get partial success with following change in NagiosStatus.php:

$Nagios_CGI_URL = "http://username:password@server/nagios/cgi-bin/";
 * 1) Nagios CGI-BIN Directory

Firefox asks for a user and a password, but page is displayed correctly. I get one error in the http log file for each page access. Maybe someone has an idea.

Here is the log error: Dec 12 11:20:50 2006] [error] [client 171.30.9.14] PHP Notice: Undefined variable: output in /var/www/mwiki/extensions/NagiosStatus.php on line 89, referer: http://server/mwiki/index.php/Main_Page

My Nagios http config file just for referance: <Directory /usr/lib/nagios/cgi/> Options ExecCGI AllowOverride None order deny,allow allow from all AuthType Basic AuthUserFile /etc/nagios/htpasswd.users AuthName "Nagios Access" Require valid-user </Directory>

Ivica 02:59, 12 December 2006 (UTC)