Nagios Core Administrators Cookbook
上QQ阅读APP看书,第一时间看更新

Installing a plugin

In this recipe, we'll install a custom plugin that we retrieved from Nagios Exchange onto a Nagios Core server, so that we can use it as a Nagios Core command and hence check a service with it.

Getting ready

You should have a Nagios Core 3.0 or newer server running with a few hosts and services configured already, and have found an appropriate plugin to install, to solve some particular monitoring need. Your Nagios Core server should have internet connectivity to allow you to download the plugin directly from the website.

In this example we'll use check_rsync, which is available on the Web at http://exchange.nagios.org/directory/Plugins/Network-Protocols/Rsync/check_rsync/details.

This particular plugin is quite simple, consisting of a single Perl script with very basic dependencies. If you want to install this script as an example, then the server will also need to have a Perl interpreter installed; it's installed in /usr/bin/perl on many systems.

This example will also include directly testing a server running an rsync daemon called troy.naginet.

How to do it...

We can download and install a new plugin as follows:

  1. Copy the URL for the download link for the most recent version of the check_rsync plugin:
    How to do it...
  2. Navigate to the plugins directory for the Nagios Core server. The default location is /usr/local/nagios/libexec:
    # cd /usr/local/nagios/libexec
    
  3. Download the plugin using wget into a file called check_rsync. It's important to surround the URL in quotes:
    # wget 'http://exchange.nagios.org/components/com_mtree/attachment.php?link_id=307&cf_id=29' -O check_rsync
    
  4. Make the plugin executable using chmod and chown:
    # chown nagios.nagios check_rsync
    # chmod 0770 check_rsync
    
  5. Run the plugin directly with no arguments to check that it runs, and to get usage instructions. It's a good idea to test it as the nagios user using su or sudo:
    # sudo -s -u nagios
    $ ./check_rsync
    Usage: check_rsync -H <host> [-p <port>] [-m <module>[,<user>,<password>] [-m <module>[,<user>,<password>]...]]
    
  6. Try running the plugin directly against a host running rsync, to see if it works and reports a status:
    $ ./check_rsync -H troy.naginet
    Output normally starts with the status determined, with any extra information after a colon:
    OK: Rsync is up
    

If all of this works, then the plugin is now installed and working correctly.

How it works...

Because Nagios Core plugins are programs in themselves, installing a plugin amounts to saving a program or script into an appropriate directory; in this case, /usr/local/nagios/libexec, where all the other plugins live. It's then available to be used the same way as any other plugin.

The next step once the plugin is working is defining a command in the Nagios Core configuration for it, so that it can be used to monitor hosts and/or services. This can be done with the Creating a new command recipe in this chapter.

There's more...

If we inspect the Perl script, we can see a little bit of how it works. It works like any other Perl script, except for the fact that its return values are defined in a hash table called %ERRORS, and the return values it chooses depend on what happens when it tries to check the rsync process. This is the most important part of implementing a plugin for Nagios Core.

Installation procedures for different plugins vary. In particular, many plugins are written in languages such as C, and hence need be compiled. One such plugin is the popular check_nrpe. Rather than simply being saved into a directory and made executable, these sorts of plugins often follow the usual pattern of configuration, compilation, and installation:

$ ./configure
$ make
# make install

For many plugins that are built in this style, the last step in that process will often install the compiled plugin into the appropriate directory for us. In general, if instructions are included with the plugin, then it pays to read them so that we can ensure we install it correctly.

See also

  • The Finding a plugin, Removing a plugin, and Creating a new command recipes in this chapter