Nagios NRPE setup on Ubuntu 8.04

Here is a step by step walkthrough that I developed recently for setting up the Nagios NRPE plugin to monitor remote hosts. This setup was performed on a host running Ubuntu Server 8.04.1. This walkthrough is based on the official nagios documentation and will result in a NRPE plugin installed from source since the latest version of nagios and its plugins are not available in the Ubuntu 8.04 repositories.

On the remote host (machine to be monitored)

1. Become root. This just makes it easier so you don’t have to keep typing sudo.
# sudo -s

2. Create nagios user and set password
$ /usr/sbin/useradd nagios
$ passwd nagios

3. Install the OpenSSL development libraries required to compile the NRPE plugin
$ apt-get install libssl-dev openssl

4. Download source tarball of Nagios plugins (http://www.nagios.org/download)
$ wget <nagios-plugins, latest stable version>

5. Extract the tarball
$ tar xzf <nagios-plugins...>.tar.gz
$ cd <nagios-plugins...>

5a. (optional) Install additional libraries required for any plugins that you will need. See the REQUIREMENTS document included with nagios plugins source code for any dependencies necessary for specific plugins.

6. Compile and install the plugins
$ ./configure
$ make
$ make install

7. Fix the permissions on the plugin directory and the plugins
$ chown nagios:nagios /usr/local/nagios
$ chown -R nagios:nagios /usr/local/nagios/libexec

8. Install xinetd
$ apt-get install xinetd

9. Install the NRPE daemon, download the source tarball for NRPE from http://www.nagios.org/download
$ wget <nrpe, latest stable version>
$ tar xzf <nrpe...>.tar.gz
$ cd <nrpe...>
$ ./configure
$ make all

$ make install-plugin
$ make install-daemon
$ make install-daemon-config
$ make install-xinetd

10. Edit /etc/xinetd.d/nrpe and add the IP address of the monitoring server to the only_from directive. This directive can contain multiple IP addresses provided in a space separated list. This example will allow access from the Nagios monitoring server as well as the localhost.
$ vi /etc/xinetd.d/nrpe

. . .

only_from =xxx.xxx.xxx.xxx 127.0.0.1

11. Edit /etc/services to add the NRPE port definition
$ vi /etc/services

. . .

nrpe 5666/tcp # NRPE

12. Restart xinetd
$ /etc/init.d/xinetd restart

13. Test the NRPE daemon locally

First, use netstat to make sure that it is running under xinetd
$ netstat -at | grep nrpe
should produce this output:
tcp 0 0 *:nrpe *:* LISTEN

Now give it a test using the Nagios check_nrpe plugin:
$ /usr/local/nagios/libexec/check_nrpe -H localhost
You should see this output (with the appropriate version number of course)
NRPE v2.12

14. At this point you should be able to access the Nagios NRPE daemon on this host from the monitoring server to execute plugins locally. Make sure to modify your firewall rules to allow access on port 5666 to the NRPE daemon. The commands that are to be executed by the NRPE plugin can be customized in /usr/local/nagios/etc/nrpe.cfg.

On the monitoring host (machine running nagios)

1. Become root
$ sudo -s

2. Download and install the check_nrpe plugin (http://www.nagios.org/download)
$ wget <nrpe, latest stable version>
$ tar xzf <nrpe...>.tar.gz
$ cd <nrpe...>
$ ./configure
$ make all
$ make install-plugin

3. Test communication with remote NRPE daemon
$ /usr/local/nagios/libexec/check_nrpe -H <hostname>
Your output should look like this if everything is successful (with the proper version number again).
NRPE v2.12

4. Create the NRPE command definition wherever in your configuration files you have commands defined.
$ vi /usr/local/nagios/etc/objects/commands.cfg

. . .

define command{
    command_name check_nrpe
    command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

5. Now you can create host and service definitions for the remote host and begin monitoring local services through the NRPE plugin and daemon.
SAMPLE:
define service{
    use generic-service
    host_name remotehost
    service_description Current Users
    check_command check_nrpe!check_users
}
; check_nrpe tells the remote nrpe daemon to execute
; the check_users command as defined in nrpe.cfg

6. Verify your configuration and restart the Nagios daemon to begin monitoring the remote host.
Verify your nagios configuration:
$ /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If everything checks out, restart the Nagios daemon:
$ /etc/init.d/nagios restart

Leave a Reply