Extension:NagiosStatus

From MediaWiki.org
Jump to: navigation, search
MediaWiki extensions manual - list
Crystal Clear action run.png
NagiosStatus

Release status: unknown

MW-NagiosServicesView.png
Implementation Tag
Description Allows the wiki server to pull Nagios status information.
Author(s) Shannon McNaught (smcnaught)
License No license specified
Download see below
changelog

Check usage (experimental)

NagiosStatus is a MediaWiki extension allows the wiki server to pull the status page, the host summary, or the service summary from your Nagios server. This extension was designed so that the Nagios server could be located on a remote server.

Stay tuned as I may add additional views from Nagios to MediaWiki. (Add to WatchList)

Note: Most up to date version of this extension can be found at: http://www.chekmate.org/wiki/index.php/Projects

Contents

[edit] Change History

  • 02:59, 27 July 2006 (UTC) - Added <span class="plainlinks"> so that Pad Locks are not displayed. (Smcnaught)
  • 23:46, 24 July 2006 (MDT) - NagiosStatus.php published (Smcnaught)

[edit] Maintainer

Shannon McNaught (smcnaught) - I am also available on irc.chekmate.org #MediaWiki

[edit] Homepage

ChekMate Technical Focus Group

[edit] License

NagiosStatus.php 
  - Adds Nagios views to MediaWiki

Copyright (C) 2006  Shannon McNaught

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

[edit] Installation

[edit] Upload NagiosStatus.php to the extensions directory

[edit] Define NagiosStatus variables

Modify the following two variables:

 // ###### DEFINE VARIABLES TO Nagios Server ######

 # Root URL
 $Nagios_Web_Server = "http://YourNagiosServerHostName/";
 # Nagios CGI-BIN Directory
 $Nagios_CGI_URL = "http://YourNagiosServerHostName/nagios/cgi-bin/";

HTTPS has been tested as well and works. Although one user has reported issues with HTTPS.

[edit] Add to LocalSettings.php

Add the following to the end of LocalSettings.php:

include("extensions/NagiosStatus.php");

[edit] Configure Nagios's Web Server

The Wiki server must be able to pull the status page without any user authentication. This can be accomplished with apache by using "Allow from" and the "Satisfy Any" commands.

In my configuration, it is: (Note: Your configuration will likely be different)

ScriptAlias /nagios/cgi-bin "/usr/local/groundwork/apache2/cgi-bin/nagios"
<Directory "/usr/local/groundwork/apache2/cgi-bin/nagios">
    Allow from (IP Address of Wiki Server)
    Satisfy Any
    AuthType Basic
    require valid-user
    TKTAuthLoginURL http://NagiosServerIPAddress/monitor/login.php
    TKTAuthCookieName       nagios_auth_tkt
    PassEnv LD_LIBRARY_PATH
</Directory>

[edit] Modify /skins/monobook/main.css

Comment out backgound in the table style:

table {
/*      background: white; */
        font-size: 100%;
        color: black;
}

[edit] Usage

Add one of the three following to your wiki pages:

<NagiosStatus>status</NagiosStatus>

MW-NagiosServicesView.png

<NagiosStatus>hosts</NagiosStatus>

MW-NagiosHostsStatus.png

<NagiosStatus>services</NagiosStatus>

MW-NagiosServicesStatus.png

[edit] NagiosStatus.php

<?php
# NagiosStatus MediaWiki extension
#
# original by smcnaught 24.07.2005
# Installation:
#  * put this file (NagiosStatus.php) into the extension directory of your mediawiki installation
#  * change the variables located in the renderNagiosStatus function below
#  * add the following to the end of LocalSettings.php: include("extensions/NagiosStatus.php");
#  * configure Nagios's web server to allow wiki server to access without username/password
#  * remove table's background parameter from skin/monobook/main.css style sheet.
#
# Usage:
#  Use one section between <NagiosStatus>-tags for each feed.
#
# Example:
#    <NagiosStatus>status</NagiosStatus>
#    <NagiosStatus>hosts</NagiosStatus>
#    <NagiosStatus>services</NagiosStatus>
#

 
#install extension hook
$wgExtensionFunctions[] = "wfNagiosStatusExtension";
 
#extension hook callback function
function wfNagiosStatusExtension() {
  global $wgParser;
 
  #install parser hook for <NagiosStatus> tags
  $wgParser->setHook( "NagiosStatus", "renderNagiosStatus" );
}
 
#parser hook callback function
function renderNagiosStatus( $input ) {
  global $wgVersion, $wgTitle, $wgDBprefix;
 
  // ###### DEFINE VARIABLES TO Nagios Server ######
 
  # Root URL
  $Nagios_Web_Server = "http://YourNagiosServerHostName/";
  # Nagios CGI-BIN Directory
  $Nagios_CGI_URL = "http://YourNagiosServerHostName/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";
  $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;
 
 
  // ###### PARSE PARAMETERS ######
  $aParams = explode("\n", $input);
  foreach($aParams as $sParam) {
    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("/<body CLASS='status'>/",$element)) {
              $inbody = 1;
            }
          }
        }
        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. "</span>"; # Remove Pad Locks
  return $output;
}
 
?>

[edit] Other sites using this extension

Personal tools
Namespaces
Variants
Actions
Site
Support
Download
Development
Communication
Print/export
Toolbox