官术网_书友最值得收藏!

Installing a plugin

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

Getting ready

You should have a Nagios Core 4.0 or newer server running with a few hosts and services configured already, and you should have found an appropriate plugin that is to be installed to solve a 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 https://exchange.nagios.org/directory/Plugins/Network-Protocols/Rsync/check_rsync/details.

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

This example will also include directly testing a server running an rsync(1) daemon, called troy.example.net.

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, as shown in the following screenshot:
  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 in a file called check_rsync. It's important to surround the URL with single quotes:
    # wget 'https://exchange.nagios.org/components/com_mtree/attachment.php?link_id=307&cf_id=29' -O check_rsync
    
  4. Make the plugin executable using chmod(1) and chown(1):
    # chown root.nagios check_rsync
    # chmod 0770 check_rsync
    
  5. Run the plugin directly with no arguments to verify that it runs and to get usage instructions. It's a good idea to test it as the nagios user using su(8) or sudo(8):
    # 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(1) to check whether it works and reports a status:
    $ ./check_rsync -H troy.example.net
    

The 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 works correctly.

How it works...

Because Nagios Core plugins are programs themselves, installing a plugin really 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 in 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, perhaps, for the fact that its return values are defined in a hash called %ERRORS, and the return values it chooses depends on what happens when it tries to check the rsync(1) 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 command. Rather than simply being saved into a directory and made executable, these sort 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 final step of make install will often be to install the compiled plugin in the appropriate directory for us. In general, if instructions are included with the plugin, it pays to read them to see how best to install the plugin.

See also

  • The Finding a plugin section in this chapter
  • The Removing a plugin section in this chapter
  • The Creating a new command section in this chapter
主站蜘蛛池模板: 黄浦区| 密云县| 新沂市| 霍山县| 广东省| 屯昌县| 绥滨县| 泸溪县| 泸定县| 阳朔县| 关岭| 秭归县| 广南县| 长葛市| 米脂县| 宝坻区| 天峨县| 达日县| 广饶县| 景谷| 临沭县| 九江县| 五河县| 陆丰市| 米泉市| 遂川县| 兴安县| 甘洛县| 武威市| 萝北县| 横峰县| 仪陇县| 额尔古纳市| 琼结县| 新疆| 淮滨县| 砚山县| 保康县| 静乐县| 广水市| 彭山县|