NRPE(Nagios Remote Plugin Executor) Installation and Setup


Nagios Server:

Hostname: server.local
IP Address: 192.168.1.5

Nagios Client:

Hostname: client.local
IP Address: 192.168.1.6

Step 1: Create Nagios user account on remote server to be monitored

[root@client.local ~]# useradd nagios
[root@client.local ~]# passwd nagios

Step 2: Download and Install Nagios Plugins

[root@client.local ~]# mkdir -p /opt/Nagios/Nagios_Plugins
[root@client.local ~]# cd /opt/Nagios/Nagios_Plugins
[root@client.local ~]# tar xzf nagios-plugins-1.4.13.tar.gz
[root@client.local ~]# cd nagios-plugins-1.4.13

Compile and Configure Nagios Plugins

** You need the openssl-devel package installed to compile plugins with ssl support. **

[root@client.local ~]# yum -y install openssl-devel

Step 3: Install Plugins

[root@client.local ~]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@client.local ~]# make
[root@client.local ~]# make install

The permissions on the plugin directory and the plugins will need to be changed to nagios user

[root@client.local ~]# chown nagios.nagios /usr/local/nagios
[root@client.local ~]# chown -R nagios.nagios /usr/local/nagios/libexec
[root@client.local ~]# yum install xinetd

Step 4: Download and Install NRPE Daemon

[root@client.local ~]# mkdir -p /opt/Nagios/Nagios_NRPE
[root@client.local ~]# cd /opt/Nagios/Nagios_NRPE
[root@client.local ~]# tar -xzf nrpe-2.12.tar.gz
[root@client.local ~]# cd nrpe-2.12
[root@client.local ~]# ./configure --enable-ssl --enable-command-args

[enable ssl is to ensure data can be send on ssl port and command args enables nrpe daemon to receive arguments from Nagios server]

[root@client.local ~]# ./configure --enable-command-args

[disable ssl and command args enables nrpe daemon to receive arguments from Nagios server]

General Options:
-------------------------
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios

[root@client.local ~]# make all
[root@client.local ~]# make install-plugin
[root@client.local ~]# make install-daemon
[root@client.local ~]# make install-daemon-config
[root@client.local ~]# make install-xinetd

Step 5: Post NRPE Configuration

Edit Xinetd NRPE entry

[root@client.local ~]# vi /etc/xinetd.d/nrpe

only_from = 127.0.0.1

Edit services file entry

Add entry for nrpe daemon

[root@client.local ~]# vi /usr/local/nagios/etc/nrpe.cfg

allowed_host = 127.0.0.1

dont_blame_nrpe = 1 [this is to enable args passing to nrpe from nagios server]

Add the below lines in EOF

command[check_ping]=/usr/local/nagios/libexec/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p $ARG3$
command[check_users]=/usr/local/nagios/libexec/check_users -w $ARG1$ -c $ARG2$
command[check_cpu]=/usr/local/nagios/libexec/check_linux_stats.pl -C -w $ARG1$ -c $ARG2$ -s $ARG3$
command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$
command[check_mem]=/usr/local/nagios/libexec/check_linux_stats.pl -M -w $ARG1$ -c $ARG2$
command[check_disk]=/usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
command[check_diskio]=/usr/local/nagios/libexec/check_linux_stats.pl -I -w $ARG1$ -c $ARG2$ -p $ARG3$
command[check_network]=/usr/local/nagios/libexec/check_linux_stats.pl -N -w $ARG1$ -c $ARG2$ -p $ARG3$

[root@client.local ~]# vi /etc/services

Add this line in EOF

nrpe 5666/tcp # NRPE

[root@client.local ~]# chkconfig xinetd on
[root@client.local ~]# /etc/init.d/xinetd restart

Step 6: Test NRPE Daemon running and listening on port 5666

[root@client.local ~]# netstat -at |grep nrpe

Output should be:

tcp 0 0 *:nrpe *.* LISTEN

[root@client.local ~]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12

Open Port 5666 on Firewall

Make sure to open port 5666 on the firewall of the remote server so that the Nagios monitoring server can access the NRPE daemon.

[root@client.local ~]# iptables -I RH-Firewall-1-INPUT -p tcp -m tcp --dport 5666 -j ACCEPT

Save the new iptables rule so it will survive machine reboots.

[root@client.local ~]# /etc/init.d/iptables save

Step 7: Nagios Monitoring Host Server Setup

From here onwards, we need to work on Nagios server (server.local/192.168.1.5)

[root@server.local ~]# tar -xzf nrpe-2.12.tar.gz
[root@server.local ~]# cd nrpe-2.12
[root@server.local ~]# ./configure
[root@server.local ~]# make all
[root@server.local ~]# make install-plugin

Step 8: Test Connection to NRPE daemon on Remote Server

[root@server.local ~]# /usr/local/nagios/libexec/check_nrpe -H
NRPE v2.12

Step 9: Create NRPE Command Definition

[root@server.local ~]# vi /usr/local/nagios/etc/objects/commands.cfg

Add the following:

###############################################################################
# NRPE CHECK COMMAND
#
# Command to use NRPE to check remote host systems
###############################################################################

define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$ $ARG7$ $ARG8$ $ARG9$ $ARG10$ $ARG11$
}

###############################################################################
# Service CHECK COMMAND
#
# Command to use NRPE to check remote host systems
###############################################################################

define command{
command_name check_ping
command_line /usr/local/nagios/libexec/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p $ARG3$
}

define command{
command_name check_users
command_line /usr/local/nagios/libexec/check_users -w $ARG1$ -c $ARG2$
}

define command{
command_name check_cpu
command_line /usr/local/nagios/libexec/check_linux_stats.pl -C -w $ARG1$ -c $ARG2$ -s $ARG3$
}

define command{
command_name check_load
command_line /usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$
}

define command{
command_name check_mem
command_line /usr/local/nagios/libexec/check_linux_stats.pl -M -w $ARG1$ -c $ARG2$
}

define command{
command_name check_disk
command_line /usr/local/nagios/libexec/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
}

define command{
command_name check_diskio
command_line /usr/local/nagios/libexec/check_linux_stats.pl -I -w $ARG1$ -c $ARG2$ -p $ARG3$
}

define command{
command_name check_network
command_line /usr/local/nagios/libexec/check_linux_stats.pl -N -w $ARG1$ -c $ARG2$ -p $ARG3$
}

Step 10: Create Linux Object template

In order to be able to add the remote linux machine to Nagios we need to create an object template file adn add some object definitions.

Create new linux-server object template file:

[root@server.local ~]# vi /usr/local/nagios/etc/objects/linux-server.cfg

Add the following and replace the values “host_name” “alias” “address” with the values that match your setup:

** The “host_name” you set for the “define_host” section must match the “host_name” in the “define_service” section **

define host{
name linux-server ; Name of this template
use generic-host ; Inherit default values
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period 24x7
notification_interval 30
notification_options d,r
contact_groups admins
register 0 ; DONT REGISTER THIS - ITS A TEMPLATE
}

define host{
use linux-server ; Inherit default values from a template
host_name client.local ; The name we're giving to this server
alias Test Server ; A longer name for the server
address 192.168.1.6 ; IP address of the server
}
define service{
use generic-service
host_name client.local
service_description Current Users
check_command check_nrpe!check_users!10!15
}
define service{
use generic-service
host_name client.local
service_description CPU Average
check_command check_nrpe!check_cpu!90!100!5
}
define service{
use generic-service
host_name client.local
service_description Load Average
check_command check_nrpe!check_load!4.0,3.0,2.0!7.0,6.0,5.0
}
define service{
use generic-service
host_name client.local
service_description Memory Average
check_command check_nrpe!check_mem!99,50!100,50
}
define service{
use generic-service
host_name client.local
service_description Disk Usage
check_command check_nrpe!check_disk!80%!90%!/
}
define service{
use generic-service
host_name client.local
service_description Disk IO Stats
check_command check_nrpe!check_diskio!100,70!150,100!sda3
}
define service{
use generic-service
host_name client.local
service_description N/w Bandwidth
check_command check_nrpe!check_network!30000!45000!eth1
}

Step 11: Activate the linux-box-remote.cfg template

[root@server.local ~]# vi /usr/local/nagios/etc/nagios.cfg

And add:

cfg_file=/usr/local/nagios/etc/objects/linux-server.cfg

Change the ownership for the new cfg file

[root@server.local ~]#chown nagios:nagios linux-server.cfg

Verify Nagios Configuration Files:

[root@server.local ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Total Warnings: 0
Total Errors: 0
Restart Nagios:

[root@server.local ~]# /etc/init.d/nagios reload

Check Nagios Monitoring server that the remote linux box was added and is being monitored.

Leave a comment

Leave a comment