Monthly Archives: April 2015

NRPE Installation and Configuration on the client machine

1) Install the required packages in preparation to install NRPE.
[root@MACHINE1 ~]# yum install -y gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel

2) Add nagios username and update the password.
[root@MACHINE1 ~]# useradd nagios
[root@MACHINE1 ~]# passwd nagios
Changing password for user nagios.
New password: mypassword
Retype new password: mypassword
passwd: all authentication tokens updated successfully.

3) Create nagios directory to store the downloaded packages.

[root@MACHINE1 ~]# mkdir /root/nagios
[root@MACHINE1 ~]# cd /root/nagios

4) Download/extract the nagios-plugins-2.0.3.tar.gz or the latest installer.
[root@MACHINE1 nagios]# wget https://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
[root@MACHINE1 nagios]# tar -zxvf nagios-plugins-2.0.3.tar.gz

5) Compile nagios plugin.

[root@MACHINE1 nagios]# cd nagios-plugins-2.0.3
[root@MACHINE1 nagios-plugins-2.0.3]# ./configure
[root@MACHINE1 nagios-plugins-2.0.3]# make
[root@MACHINE1 nagios-plugins-2.0.3]# make install

6) Change ownership on nagios installation directory to “nagios.nagios”.

[root@MACHINE1 nagios-plugins-2.0.3]# chown nagios.nagios /usr/local/nagios
[root@MACHINE1 nagios-plugins-2.0.3]# chown -R nagios.nagios /usr/local/nagios/libexec

7) Install xinetd.
[root@MACHINE1 nagios-plugins-2.0.3]# yum install xinetd

8) Download and compile NRPE installer.
[root@MACHINE1 nagios-plugins-2.0.3]# cd /root/nagios
[root@MACHINE1 nagios]# wget http://liquidtelecom.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
[root@MACHINE1 nagios]# tar -zxvf nrpe-2.15.tar.gz
[root@MACHINE1 nagios]# cd nrpe-2.15
[root@MACHINE1 nrpe-2.15]# ./configure
[root@MACHINE1 nrpe-2.15]# make all
[root@MACHINE1 nrpe-2.15]# make install-plugin
[root@MACHINE1 nrpe-2.15]# make install-daemon
[root@MACHINE1 nrpe-2.15]# make install-daemon-config
[root@MACHINE1 nrpe-2.15]# make install-xinetd
[root@MACHINE1 nrpe-2.15]# vi /etc/xinetd.d/nrpe
#Change localhost ip to 192.168.168.92 which is the Nagios server.
only_from       = 192.168.168.92

9) Add the line at the most bottom part of /etc/services.

[root@MACHINE1 nrpe-2.15]# vi /etc/services
nrpe            5666/tcp                # NRPE

10) Restart xinetd.

[root@MACHINE1 nrpe-2.15]# service xinetd restart

11) Check if nrpe is listening after restarting xinetd.

[root@MACHINE1 nrpe-2.15]# netstat -at | grep nrpe
tcp        0      0 *:nrpe                      *:*                         LISTEN

12) Test if it works. If you encounter the error “Could not complete SSL handshake”. Please proceed to step 13.

[root@MACHINE1 nrpe-2.15]# /usr/local/nagios/libexec/check_nrpe -H 192.168.168.92
CHECK_NRPE: Error – Could not complete SSL handshake.

13) Add tcp port 5666 to iptables/firewall.

[root@MACHINE1 nrpe-2.15]# iptables -A INPUT -p tcp -m tcp –dport 5666 -j ACCEPT

[root@MACHINE1 nrpe-2.15]# service iptables save

14) Define the services that you want to monitor in NRPE.

[root@MACHINE1 nrpe-2.15]# vi /usr/local/nagios/etc/nrpe.cfg

#####################################################################################
#Hard Disk Resources
command[check_root]=/usr/local/nagios/libexec/check_disk -w 30% -c 20% -p /dev/sda2
command[check_var_log]=/usr/local/nagios/libexec/check_disk -w 30% -c 20% -p /dev/sdc1
command[check_home]=/usr/local/nagios/libexec/check_disk -w 30% -c 20% -p /dev/sdb2

#Sample Services
command[check_heartbeat]=/usr/local/nagios/libexec/check_ps.sh  -p heartbeat
command[check_postfix]=/usr/local/nagios/libexec/check_ps.sh -p postfix
command[check_dovecot]=/usr/local/nagios/libexec/check_ps.sh -p dovecot
######################################################################################

15) SSH your Nagios Server and add the line to nagios.cfg.

[root@NAGIOS]# vi /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/MACHINE1.cfg

16) Edit and insert the following code below to MACHINE1.cfg
vi /usr/local/nagios/etc/objects/MACHINE1.cfg

define service {
use                             generic-service
host_name                       MACHINE1
service_description             Heartbeat Service
check_command                   check_nrpe2!192.168.168.10!check_heartbeat
contact_groups                  common

define service {
use                             generic-service
host_name                       MACHINE1
service_description             Heartbeat Service
check_command                   check_nrpe2!192.168.168.10!check_postfix
contact_groups                  common

define service {
use                             generic-service
host_name                       MACHINE1
service_description             Heartbeat Service
check_command                   check_nrpe2!192.168.168.10!check_dovecot
contact_groups                  common

define service {
use                             generic-service
host_name                       MACHINE1
service_description             Root Partition
check_command                   check_nrpe2!192.168.168.10!check_root
contact_groups                  common
}

define service {
use                             generic-service
host_name                       MACHINE1
service_description             Home Partition
check_command                   check_nrpe2!192.168.168.10!check_home
contact_groups                  common
}
define service {
use                             generic-service
host_name                       MACHINE1
service_description             Log Partition
check_command                   check_nrpe2!192.168.168.10!check_var_log
contact_groups                  common
}

17) Wait for approximately 5 minutes and check via nagios web interface.

http://192.168.168.92/nagios/
Username: nagiosadmin
Password: mypassword

Nagios Installation

1) Install Required Dependencies

#yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp

2) Create Nagios User and Group

#useradd nagios
#groupadd nagcmd

3) Next, add both the nagios user and the apache user to the nagcmd group.

#usermod -G nagcmd Nagios
#usermod -G nagcmd apache

4) Create Nagios directory.

#mkdir /root/nagios
#cd /root/nagios

5) Download the latest Nagios and Plugin.

#wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.1.tar.gz
#wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz

6) Extract Nagios Core and its Plugins.

#tar -xvf nagios-4.0.1.tar.gz
#tar –xvf nagios-plugins-1.5.tar.gz

7) Configure Nagios

#cd nagios-4.0.1
#./configure –with-command-group=nagcmd

8) Compile and Install.

#make all
#make install
#make install-init
#make install-commandmode
#make install-config

9) Edit and add your email address in contacts.cfg.

#vi /usr/local/nagios/etc/objects/contacts.cfg

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                           nagios@webserverpage.com.com       ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}

10) Compile/install web configuration of Nagios.

#make install-webconf
#htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password: mypassword
Re-type new password: mypassword
Adding password for user nagiosadmin.

#service httpd start
#cd /root/Nagios
#cd nagios-plugins-1.5
#./configure –with-nagios-user=nagios –with-nagios-group=Nagios
#make
#make install
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# chkconfig –add nagios
# chkconfig –level 35 nagios on
# chkconfig –add httpd
# chkconfig –level 35 httpd on
# service nagios start

Continuation:

NRPE Installation and Configuration on the client machine