NRPE
June 6th, 2006Quick NRPE How-To On CentOS
By: Max Hetrick
Last updated:
05-07-2007 – Updated for latest Nagios Open Fusion Plugins examples at the end of guide
02-23-2007 – Improved installation instructions with version 2.5.2
06-20-2006
Already have Nagios up and running, but can’t quite figure out how to execute commands remotely? Here’s a very quick how-to for that. This assumes you already have Nagios up and running, and you have the third-party repo installed on your box. You may also get the source, and create your own, but that’s not how this explains things. Don’t fret, if you can’t do it this way, there is plenty of documentation available elsewhere to help you. Check the references. Make sure you are logged in as root or another privileged user.
A word about the installing RPMforge. If you want to make life easier on yourself down the road with updating and installing Nagios, then follow the instructions on the CentOS wiki for installing RPMforge repo where many extra RPMs are housed. It’s a snap, just follow these instructions:
http://wiki.centos.org/Repositories/RPMForge
System:
CentOS 4.4 (Again, will work for any RHEL/Fedora)
NRPE: version 2.5.2 (RPM from Dag’s Repo)
OpenFusion Plugins: 0.8.3
References:
- Nagios: http://www.nagios.org
- Nagios Wiki: http://www.nagioscommunity.org/wiki
- NRPE FAQs: http://www.nagios.org/faqs/
- Nagios Exchange: http://www.nagiosexchange.org
- Open Fusion Nagios: http://www.openfusion.com.au/labs/nagios
Packages/Dependencies:
RPM Packages:
nagios-nrpe-2.5.2-1.el4.rf
1) Installation:
[me@mymachine ~] yum install nagios-nrpe
After installing the above packages, NRPE is configured as a daemon. Configure the daemon to be on.
[me@mymachine ~] chkconfig nrpe on
2) Configuration:
After installation, the NRPE configuration file is located at /etc/nagios/nrpe.cfg. Also, the plugins that come with the packages you installed are located at /usr/lib/nagios/plugins.
How this all works is simply this: When the Nagios monitoring machine processes a check_nrpe check (however you have it set up on the monitoring machine), it sends the command to be issued over SSL to the remote machine. The remote machine accepts the SSL handshake, processes the request, and sends back the state of the check. Nagios then processes that information and displays normally on it’s CGI interface. If the plugin(s) to be executed are missing off the remote machine, an error will occur. The plugins must be physically on the remote machine.
Since you’re going to run the NRPE process as a daemon there is actually only one parameter in the configuration file you need to worry about. That would be the IP’s of the machines you are going to allow to run checks on your host. If you wish to not worry about this, simply skip. Uncomment the following line and enter the IP address(es) of the monitoring machines you want to allow to process remote checks.
[me@mymachine ~] vim /etc/nagios/nrpe.cfg allowed_hosts=127.0.0.1,192.168.0.100
Write the file out and now you can start the NRPE daemon.
[me@mymachine ~] service nrpe start
3) Test it out:
After you have the daemon fired up on the remote machine you want to run checks on, sign into the machine you wish to process these checks from (that would be your Nagios monitoring IP that you entered above:-P). Drop to a command line and test out the NRPE check on the remote machine.
On your Nagios machine, ensure the nagios-plugins-nrpe package is installed.
[me@mynagios ~] rpm -q nagios-plugins-nrpe
If it’s not installed:
[me@mynagios ~] yum install nagios-plugins-nrpe [me@mynagios ~] cd /usr/lib/nagios/plugins [me@mynagios ~] ./check_nrpe -H remote_machine -c check_users USERS OK - 1 users currently logged in |users=1;5;10;0
If everything is a go, you’ll get some output like above. I’m logged onto a command line on the remote machine, and since I’m the only user logged into that system, it displays 1 user currently logged on. If you get an error, verify that NRPE is running on the remote machine, andv that a firewall isn’t blocking you somewhere between the hosts.
You can use this to check whatever you want now, via Nagios, as long as the plugin(s) are located on the remote machine. I’ll show you how to use this for checking for updates from yum.
4) Using extra plugins from OpenFusion:
Get back to the remote machine now, remember the plugins have to be on the remote host. Download the example plugin set I reference to in the links above. This package is the OpenFusion Plugins pack, kindly provided by Open Fusion Business Solutions. The Nagios Exchange site has version 0.8.2. The version on the main Open Fusion website is 0.8.3. It’s up to you which version you want to use. After you download them, let’s get them in place.
[me@mymachine ~] wget http://www.openfusion.com.au/labs/dist/nagios-of-plugins-0.8.3-1.of.noarch.rpm [me@mymachine ~] rpm -ivh nagios-of-plugins-0.8.3-1.of.noarch.rpm [me@mymachine ~] perl -MCPAN -e 'install Nagios::Plugin' ....snip a ton of stuff as it downloads and builds modules.
Configure the plugin path in nrpe.cfg.
[me@mymachine ~] vim /etc/nagios/nrpe.cfgcommand [check_yum]=/usr/lib/nagios/plugins/check_yum [me@mymachine ~] service nrpe restart [me@mymachine ~] cd /usr/lib/nagios/plugins [me@mymachine ~] ./check_yum <--Check the update plugin YUM OK - all packages up to date> <-- Yay! I'm up2date!
Ok, now that you got it working locally, go back to your Nagios monitoring box and test it out from there.
[me@mynagios ~] /usr/lib/nagios/plugins/check_nrpe -H remote_machine -c check_yum YUM OK - all packages up to date <--Same as doing it from the localhost on the remote box
That’s about it for using extra plugins. The basic thing to remember is to copy or install the plugins on the remote machine, and then put the check line into /etc/nagios/nrpe.cfg, then restart NRPE. Always test the plugin locally to make sure it works before checking remotely. You can also write your own plugins, and they can be as simple as a one-liner to check uptime and such.
5) Configuring Nagios for NRPE checks:
The only thing left to do is to define the check command Nagios needs to use, and to define the service for our check_yum plugin. Obviously you can create whatever services you would like from this. For example, if you want to create a service for checking how many users are logged in. Create the service, based upon using the check_nrpe plugin. I’ll use the check_yum service as an example.
[me@mynagios ~] vim /etc/nagios/check_commands
# Check yum across NRPE
define command {
command_name check_yum
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_yum
}
Write and quit this file and move on to the next. I have a basic object defined that I leech off of from any new service, thus the reason for the “use basic-service” part. This isn’t a Nagios how-to, so please refer to the Nagios docs if you don’t undestand.
[me@mynagios ~] vim /etc/nagios/services.cfg
# check_yum service through check_nrpe
define service {
use basic-service
name check-yum
service_description Updates
notification_interval 0
check_command check_yum
host_name remote_machine}
That’s it. You now know how to use NRPE to execute plugins remotely on hosts around your network. I prefer to do most things through SNMP, but every now again this comes in useful. The yum check is a good example of that…there’s no other way that I’m aware of, to check that your systems are up to date with Nagios. Plus anything that you want to process remotely with plugins, NRPE will pretty much allow. Basically, the check_yum uses the yum check-update switch. If you need updates you’ll get a 100 response, if you don’t you get a 0. Check it out on the command line. Remember to echo $?, though, or you won’t actually see the numbers.







August 1st, 2006 at 3:04 am
great post. thanx for taking the time. you should include a link to the FAQ
http://www.nagios.org/faqs/index.php?section_id=4&expand=false&showdesc=true
February 13th, 2008 at 2:20 pm
Just like the nagios one, this was extremely helpful. Thank you.
January 20th, 2009 at 2:11 pm
Excellent work, thank you. You may omit the “host_name – remote_machine” line in the service description. It will work in Nagios 2.