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.

Nagios monitoring tool installation and configuration


Nagios is an open source computer system monitor, network monitoring and infrastructure monitoring software applications. Nagios offers monitoring and alerting for servers, switches, applications, and services.

It alerts users when things go wrong and alerts them again when the problem has been resolved.

Nagios was originally designed to run under Linux, but also runs well on other Unix variants and can monitor Windows, Linux/Unix/BSD, Netware and network devices.

It is a free software licensed under the term of the GNS General Public License verstion 2.

Before going for installation, please make sure your Apache and Postfix servers are up and running.

Prerequisites

Verify whether gcc is installed

[root@server.local ~]# rpm -qa | grep gcc
gcc-3.4.6-8
compat-gcc-32-3.2.3-47.3
libgcc-3.4.6-8
compat-libgcc-296-2.96-132.7.2
compat-gcc-32-c++-3.2.3-47.3
gcc-c++-3.4.6-8

•Verify whether GD is installed

[root@server.local ~]# rpm -qa gd
gd-2.0.28-5.4E

Step 1: Create user and group for nagios

[root@server.local ~]# useradd nagios
[root@server.local ~]# passwd nagios
[root@server.local ~]# groupadd nagcmd
[root@server.local ~]# usermod -G nagcmd nagios
[root@server.local ~]# usermod -G nagcmd apache

Step 2: Install nagios

[root@server.local ~]# tar xvf nagios-3.5.1.tar.gz
[root@server.local ~]# cd nagios-3.5.1
[root@server.local ~]# ./configure --with-command-group=nagcmd
[root@server.local ~]# make all
[root@server.local ~]# make install
[root@server.local ~]# make install-init
[root@server.local ~]# make install-config
[root@server.local ~]# make install-commandmode

Following are some additional parameters that you can pass to ./configure to customize your installation. I used only –with-command-group as shown above.

--prefix /opt/nagios Where to put the Nagios files
--with-cgiurl /nagios/cgi-bin Web server url where the cgi's will be available
--with-htmurl /nagios Web server url where nagios will be available
--with-nagios-user nagios user account under which Nagios will run
--with-nagios-group nagios group account under which Nagios will run
--with-command-group nagcmd group account which will allow the apache user to submit commands to Nagios

At the end of the configure output, it will display a summary as shown below:

*** Configuration summary for nagios 3.5.1 05-28-2012 ***:

General Options:
-------------------------
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagcmd
Embedded Perl: no
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Lock file: ${prefix}/var/nagios.lock
Check result directory: ${prefix}/var/spool/checkresults
Init directory: /etc/rc.d/init.d
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /bin/mail
Host OS: linux-gnu

Web Interface Options:
------------------------
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /bin/traceroute

Step 3: Configure the web interface

[root@server.local ~]# make install-webconf
[root@server.local ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

Step 4: Compile and install nagios plugins

[root@server.local ~]# tar xvf nagios-plugins-1.4.11.tar.gz
[root@server.local ~]# cd nagios-plugins-1.4.11
[root@server.local ~]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@server.local ~]# make
[root@server.local ~]# make install

if you get redhat-pthread-workaround error then enter the below command

[root@server.local ~]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround

Step 4: Start Nagios daemon

[root@server.local ~]# chkconfig --add nagios
[root@server.local ~]# chkconfig nagios on

Verify to make sure there are no errors in the nagios configuration file

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

Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check

Start the nagios

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

Step 5: Login to web interface

Nagios Web URL: http://localhost/nagios/

Use the userid, password that was created from step#3 above.

Step 6: Mail id configuration

The first configuration to modify is to change the default value of email address in /usr/local/nagios/etc/objects/contacts.cfg file to your email address.

define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email yourname@yourdomainname.com ; CHANGE THIS TO YOUR EMAIL ADDRESS
}

Now reload your nagios to apply changes by command

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