Extension:Nagios

MediaWiki extensions manual
Nagios
Release status: unmaintained
Implementation Tag
Description Adds nagios tables to wiki pages
Author(s) Edward Quick (edwardquick@hotmail.com) (Quick73talk)
MediaWiki Tested on 1.24
PHP Tested on 5.5.20
Database changes No
License GNU General Public License 2.0
Download
Example http://linuxproblems.org/wiki/NagiosGallery
  • $wgNagiosRefresh
  • $wgNagiosLiveStatus
  • $wgNagiosPnp4Nagios
Nagios

The Nagios extension adds Nagios tables to MediaWiki pages. The information is pulled from a Nagios server and refreshed within the page at given intervals.

Introduction

edit

With this extension, MediaWiki provides a more configurable frontend for Nagios, and adds the ability to include realtime information in your documentation.

The Nagios extension lets users place one or more Nagios tables in a wiki page using <Nagios> tags. These tables are customised using the parameters provided to Nagios CGIs, and updated at regular intervals without having to refresh the page.

If combined with Check_MK and livestatus-slave, then realtime data is also presented when hovering over links in those tables. See an example at http://linuxproblems.org/wiki/NagiosGallery.

The nice thing about presenting Nagios in Mediawiki is that one can make use of templates to easily reuse the views or tables on other pages. Also <Nagios> tags can be placed in <div> tags and the monitor page styled however required.

Dependencies

edit

This extension requires a nagios backend server with read access. It has been tested with the Centos 6.5 version of Nagios 3.5.1. The graphs displayed in the example are produced by pnp4nagios.

The following are optional dependencies but help get the most out of this extension:

  • Configure Nagios with the livestatus broker module

Installation

edit
  • Download and place the file(s) in a directory called Nagios in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    require_once "$IP/extensions/Nagios/Nagios.php";
    
  •   Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Configuration Parameters

edit

The following variables can be tuned in LocalSettings.php.

$wgNagiosRefresh
default 60 (seconds). This is the interval at which to fetch data from Nagios.
$wgNagiosLiveStatus
default false. Change to true if livestatus-slave is set up.
$wgNagiosPnp4Nagios
default false. Set to true if PNP4Nagios is used.

Usage

edit

To insert a Nagios table, add the Nagios tag with the attributes mentioned below. Tables are imported using the parameters provided to status.cgi and extinfo.cgi in Nagios, for example the following url:

http://linuxproblems.org/nagios/cgi-bin/status.cgi?hostgroup=webhosts&style=hostdetail&hoststatustypes=2&hostprops=0

would be entered in a wiki page as:

<Nagios nagiosurl=http://linuxproblems.org/nagios/ hostgroup=webhosts style=hostdetail hoststatustypes=2 hostprops=0>Web Hosts</Nagios>

and this would display the following table:

 

There is limited online documentation about these parameters but perhaps the best resource is the icinga site at http://docs.icinga.org/latest/en/cgiparams.html#cgiparams_expl. Not all of them are included in the Nagios extension yet but will be if required.


Tag attributes

edit

The following attributes can be added to <Nagios> tags to construct a table and the table title is placed between the tags as so:

<Nagios --attributes-- >Title</Nagios>

nagiosurl
This is a mandatory attribute and should be the url of the nagios server with a trailing slash eg, http://www.mysite.com/nagios/
pnp4url
This is the url of the pnp4nagios server with a trailing slash eg, http://www.mysite.com/pnp4nagios/. If not specified it defaults to the same website running nagios.
extended
display extended information (default: false)
host
display all hosts or a specific host whose services should be displayed
hostgroup
display all hostgroups or one specific hostgroup whose hosts and services should be displayed
hoststatustypes
display hosts in a given state 1=Pending; 2=Up; 4=Down; 8=Unreachable
service
display all services or a specific service
servicegroup
display hosts and services for all servicegroups or one specific servicegroup
servicefilter
display services matching a given pattern
servicestatustypes
display state the services should be in 1=Pending; 2=OK, 4=Warning; 8=Unknown; 16=Critical
style
display overview; detail; summary; grid; hostdetail
type
hosts; hostgroups; services; servicegroups; contacts; contactgroups; timeperiods; commands; hostescalations; serviceescalations; hostdependencies; servicedependencies

If unsure about which attributes to use, the easiest way is to hover over a link to the required table in Nagios, and copy the parameters from that.

Examples

edit

Here are some examples to help get started. Note that the images below are just screenshots. For a real life example see http://linuxproblems.org/wiki/NagiosGallery.

Host Groups

edit
<Nagios nagiosurl=http://linuxproblems.org/nagios/ hostgroup=webhosts style=overview>Web hosts</Nagios>

 


Service Groups

edit
Overview
edit
<Nagios nagiosurl=http://linuxproblems.org/nagios/ servicegroup=chef-clients style=overview>Chef Clients</Nagios>

 


Detail
edit
<Nagios nagiosurl=http://linuxproblems.org/nagios/ servicegroup=backupfs style=detail>Filesystem Group for Backups</Nagios>

 


Extended Information

edit
Host
edit
<Nagios nagiosurl=http://linuxproblems.org/nagios/ extended=true type=1 host=www>Host www</Nagios>

 


Service
edit
<Nagios nagiosurl=http://linuxproblems.org/nagios/ extended=true type=2 host=centos service="CPU+load">CPU Load on Centos Host</Nagios>

 


Customised Views

edit
<Nagios nagiosurl=http://linuxproblems.org/nagios/ host=all servicestatustypes=29 serviceprops=10>All non-OK services which are neither in downtime nor acknowledged</Nagios>

 

Styling

edit

There are all sorts of ways to style Nagios tables on MediaWiki pages so this is just one example to demonstrate the idea. Here there are 3 tables grouped together on the same row. They are wrapped within a div tag, and the style applied to the div.

<div id='hostgroups' style='width: 80%; display: flex; justify-content: space-around;'>
<Nagios nagiosurl=http://linuxproblems.org/nagios/ hostgroup=webhosts style=overview>Web hosts</Nagios>

<Nagios nagiosurl=http://linuxproblems.org/nagios/ hostgroup=physicals style=overview>Physical hosts</Nagios>

<Nagios nagiosurl=http://linuxproblems.org/nagios/ hostgroup=virtuals style=overview>Virtual hosts</Nagios>
</div>

 

Templating

edit

In terms of the Nagios Extension, Templates could be aligned to a hostgroup, or servicegroup. For example, imagine a wiki page such as Template:DMZWebHosts, then add a nagios table that filters out the DMZ Web hostsgroup. Now when it comes to documenting pages for DMZ applications, there's an easy way to display the web hosts by adding {{DMZWebHosts}}.

Authentication

edit

The Nagios extension is not designed for administration, but does require read access. Refer to the documentation on authenticating to the Nagios CGIs at http://nagios.sourceforge.net/docs/3_0/cgiauth.html

If authentication is required, the nagiosurl can be specified as follows:

nagiosurl=http://rouser:ropass@linuxproblems.org/nagios/

The obvious downside there being that the password is then in the wiki page.

Authentication on the Nagios Apache server can be configured to handle requests without requiring a password. There are some helpful notes on the NagVis Extension page about authentication

Here are two possible workarounds. In both cases a read-only user is configured in the Nagios cgi.cfg file as shown below.

# READ-ONLY USERS
# A comma-delimited list of usernames that have read-only rights in
# the CGIs.  This will block any service or host commands normally shown
# on the extinfo CGI pages.  It will also block comments from being shown
# to read-only users.

authorized_for_read_only=rouser

Method 1

edit

In this method, the Nagios web server gives read access by default to any users on the internal network 192.168.1.0\24.

ScriptAlias /nagios/cgi-bin/ "/usr/lib64/nagios/cgi-bin/"

<Directory "/usr/lib64/nagios/cgi-bin/">
   Options ExecCGI
   AllowOverride None

   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /etc/nagios/passwd
   Require valid-user
   Order allow,deny
   Allow from 192.168.1
   SetEnvIf Remote_Addr 192.168.1 REMOTE_USER=rouser
   Satisfy Any
</Directory>

Alias /nagios "/usr/share/nagios/html"

<Directory "/usr/share/nagios/html">
   Options None
   AllowOverride None
   AuthName "Nagios Access"
   AuthType Basic
   AuthUserFile /etc/nagios/passwd
   Require valid-user
   Order allow,deny
   Allow from 192.168.1
   SetEnvIf Remote_Addr 192.168.1 REMOTE_USER=rouser
   Satisfy Any
</Directory>


Method 2

edit

This method provides an entry point with read access for all users. It adds a local proxy on port 5080 to the nagios web server and forwards all requests with an authorization header so it appears as if the user is already authenticated. Obviously choose a different port if 5080 is already in use.

Determine the authorization header value for the read-only user. One way to do that (on Linux) is passing the username:password through base64, but you could just as easily retrieve it from Fiddler or Firebug doing a network capture.

-bash-4.1$ echo "rouser:rouser" | base64 | xargs -I{} echo "Basic {}="
Basic cm91c2VyOnJvdXNlcgo==

Add a VirtualHost container that listens on port 5080 as shown below, to the nagios configuration in Apache. Replace the authorization header value with your own read-only user.

[root@centos conf.d]# cat /etc/httpd/conf.d/nagios.conf

Listen 5080
<VirtualHost _default_:5080>
   ProxyPass /nagios http://127.0.0.1/nagios
   ProxyPassReverse /nagios http://127.0.0.1/nagios
   ProxyPass /pnp4nagios http://127.0.0.1/pnp4nagios
   ProxyPassReverse /pnp4nagios http://127.0.0.1/pnp4nagios
   RequestHeader set authorization "Basic cm91c2VyOnJvdXNlcg=="
</VirtualHost>

ScriptAlias /nagios/cgi-bin/ "/usr/lib64/nagios/cgi-bin/"
...

Now in the wiki page, specify the urls on port 5080.

<Nagios nagiosurl=http://192.168.1.20:5080/nagios/ pnp4url=http://192.168.1.20:5080/pnp4nagios/ hostgroup=allhosts style=overview>All hosts</Nagios>

Credits

edit

This extension was inspired by Extension:NagVis and uses the following software:

Pretty Powerful Tooltips at http://qtip2.com/

PHP Simple HTML DOM Parser at http://simplehtmldom.sourceforge.net/