Skip to content

Learning Nagios (NRPE for Linux Boxes) contd – 4

November 1, 2011

OPEN THE FIREWALL RULES

So, as far as our environment is concerned, I don’t think I need to open any Firewall rules as such because of a couple of reasons:
1) We have these boxes in the HP datacenter and none of the boxes have iptables running on them
2) All of these boxes are able to communicate with each other with nothing blocking the connections between them.
Having said this, if we would have had to monitor, say for example, a host on the Amazon environment from our HP data center, we might have to look at the firewall rules but as of now, we are good to go. But, if you do need to open some of the rules, please follow the instructions as mentioned in the NRPE.pdf on the nagios website.

CUSTOMIZE NRPE COMMANDS
We can configure or write custom nrpe command definitions in /usr/local/nagios/etc/nrpe.cfg file but I am not going to do that as of now.

SETTING UP THE MONITORING HOST

Step 1:
First step would be to install the nrpe-plugin on the monitoring host (xxx-vm109)
sudo to root on xxx-vm109 which is the monitoring host on which the nagios server is running
cd /home/nagios/
mkdir downloads
cd downloads/
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
tar xvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin

Now, to make sure the check_nrpe plugin is installed correctly on the monitoring host and that both the hosts are able to communicate with each other, run the below command and you should see an output like the one below:
[root@xxx-vm109 nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H <hip>
NRPE v2.12

Here, sip is the monitoring host and hip is the linux host being monitored remotely. So, everything looks okay so far.

Step 2:
Now, we need to add a command definition in the /usr/local/nagios/etc/objects/commands.cfg file on the monitoring host for the ‘check_nrpe’ command.
so, su – nagios
vi /usr/local/nagios/etc/objects/commands.cfg
Add the following definition to the file:
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Step 3:
Final step would be to create nagios host and service definitions for monitoring the remote host. All this should be done on the nagios server which is the monitoring host which is xxx-vm109 in our case. The config files are found at /usr/local/nagios/etc/objects Now, I dont have to create a separate config file as specified in the guide for linux-box because I already have a file ‘linux.cfg’ configured for linux servers. I just need to add the host definition for the remote host in that file as below:

define host{
use linux-server ; Name of host template to use ; This host definition will inherit all variables that are defined ; in (or inherited by) the linux-server host template definition.
host_name xxx-vm066
alias HP Amazon Tools Box
address <hip> }

Also, I am just going to add this host as a member in the hostgroup as mentioned below along with the host axway-vm109 which was already there:

define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup alias Linux Servers ; Long name of the group
members xxx-vm109, xxx-vm066 ; Comma separated list of hosts that belong to this group
}

Finally, I need to add some service definitions to be monitored on the remote host for the host xxx-vm066 as mentioned below:
# The following service will monitor the CPU load on the remote host. The “check_load” argument that is passed to
# the check_nrpe command definition tells the NRPE daemon to run the “check_load” command as defined in the
# nrpe.cfg file.
define service{
use generic-service
host_name xxx-vm066
service_description CPU Load
check_command check_nrpe!check_load
}

# The following service will monitor the the number of currently logged in users on the remote host.
define service{
use generic-service
host_name xxx-vm066
service_description Current Users
check_command check_nrpe!check_users
}

# The following service will monitor the free drive space on /dev/hda1 on the remote host.
define service{
use generic-service
host_name xxx-vm066
service_description /dev/hda1 Free Space
check_command check_nrpe!check_hda1
}

# The following service will monitor the total number of processes on the remote host.
define service{
use generic-service
host_name xxx-vm066
service_description Total Processes
check_command check_nrpe!check_total_procs
}

# The following service will monitor the number of zombie processes on the remote host.
define service{
use generic-service
host_name xxx-vm066
service_description Zombie Processes
check_command check_nrpe!check_zombie_procs
}

Step 4:
We need to restart Nagios now to make sure the changes that we made are in effect.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
exit to root and /etc/init.d/nagios restart

Step 5:
For customizing or adding more services to monitor on the remote host from the monitoring host, we need to perform 2 steps:
1) Add a new command definition to the nrpe.cfg file on the remote host.
2) Add a new service definition to your Nagios configuration on the monitoring host.

Example: We want to monitor the swap usage on the remote host. We already have a plugin check_swap installed on the remote host so we can just use that. the command to create an alert if the swap free space is less than 10% and a warning if free space is less than 20% is:
./check_swap -w 20% -c 10%
Now, add this command to the /usr/local/nagios/etc/nrpe.cfg file like this:
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%

Now, if the NRPE daemon is running as a standalone daemon, you might want to restart it. If its running under the inetd/xinetd superserver, you don’t have to do anything.

Now, comes the monitoring host. We need to add the service definition for the check_swap plugin. So, edit the config file that you have been using to add services for the remote host and add the below service:
define service{
use generic-service
host_name xxx-vm066
service_description Swap Usage
check_command check_nrpe!check_swap
}

Dont forget to restart nagios from root.

UPGRADING NRPE
Its pretty simple to do it on the Monitoring Host. We need to install the plugin.
Just download the latest nrpe plugin, untar it, cd to its folder.
Run ./configure and do make all.
After this, do make install-plugin and you are done.

For the remote hosts, we need to upgrade the NRPE daemons on all the remote hosts. So, all the steps are pretty much the same here as above except the make install-daemon command instead of make install-plugin.
make sure before installing the new daemon, there are no old daemons running. Kill em all!

THATS IT FOR THE NRPE PLUGIN. I am now going to research and try to implement Chef so that all the hosts can be configured with the NRPE addon automatically rather than me having do it manually.
This is exciting!
NAGIOS+CHEF = I love it!

Advertisements

From → Monitoring

3 Comments
  1. Hey nice post. you might also want to try zabbix or zenoss they provide quiet good solution.

  2. Ok, I’m now installing Nagios on my little Ubuntu Netbook. that’s pretty awesome…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: