January 13, 2014

Install Nagios Agent NRPE on RHEL 6 from EPEL Repository

Introduction

The Nagios Plugins are the components that do the actual monitoring work. They are all bash scripts and are located in:

$ ll /usr/lib64/nagios/plugins/

To make the plugins/agents talk with server/Nagios Core you use the NRPE (Nagios Remote Plugin Executor).

Agent/Client Installation

Install the EPEL (Extra Packages for Enterprise Linux) repository. [https://fedoraproject.org/wiki/EPEL]

$ rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Install NRPE and all Nagios plugins.

$ yum install nrpe nagios-plugins-all

Agent/Client Configuration

Add the Nagios Core server IP adress.

$ vi /etc/nagios/nrpe.cfg
...
allowed_hosts=127.0.0.1,192.168.122.93
...

Start the nrpe service or restart if you have previously started it, to let the new configuration take effects.

$ service nrpe restart

The NRPE is using port 5666 (see /etc/nagios/nrpe.cfg) to communicate with the server, so we need to open that port in the firewall. Below is the current settings in iptables for the client computer we are trying to monitor.

$ iptables -vnL --line-numbers
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
2    53027   71M ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
3        7   588 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           
4        1    60 ACCEPT     tcp  --  *      *       192.168.122.0/24     0.0.0.0/0           state NEW tcp dpt:22 
5        0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:21 
6        1    60 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0           LOG flags 0 level 4 
7        1    60 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-port-unreachable 

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           reject-with icmp-port-unreachable 

Chain OUTPUT (policy ACCEPT 31259 packets, 3978K bytes)
num   pkts bytes target     prot opt in     out     source               destination  

Open tcp port 5666 for incoming traffic.

$ iptables -I INPUT 6 -m state --state NEW -p tcp --dport 5666 -j ACCEPT

Nagios Core Server Configuration

Install the nagios nrpe plugin on the server.

$ yum install nagios-plugins-nrpe

Then we need to enable it. Add the below command to the end of the file.

$ vi /etc/nagios/objects/commands.cfg
...
define command{
    command_name check_nrpe
    command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Before we can proceed, we now need to understand how Nagios arrenge items in it's admin GUI.

If you look at the selected menu items to the right, I have selected:

  • Hosts
  • Services
  • Host Groups
  • Service Groups

Now if we open the main nagios configuration file, you will see a similiar structure of the configuration files.

$ vi /etc/nagios/nagios.cfg
...
# OBJECT CONFIGURATION FILE(S)
# These are the object configuration files in which you define hosts,
# host groups, contacts, contact groups, services, etc.
# You can split your object definitions across several config files
# if you wish (as shown below), or keep them all in a single config file.

# You can specify individual object config files as shown below:
cfg_file=/etc/nagios/objects/commands.cfg
cfg_file=/etc/nagios/objects/contacts.cfg
cfg_file=/etc/nagios/objects/timeperiods.cfg
cfg_file=/etc/nagios/objects/templates.cfg

# Definitions for monitoring the local (Linux) host
cfg_file=/etc/nagios/objects/localhost.cfg

# Definitions for monitoring a Windows machine
#cfg_file=/etc/nagios/objects/windows.cfg

# Definitions for monitoring a router/switch
#cfg_file=/etc/nagios/objects/switch.cfg

# Definitions for monitoring a network printer
#cfg_file=/etc/nagios/objects/printer.cfg


# You can also tell Nagios to process all config files (with a .cfg
# extension) in a particular directory by using the cfg_dir
# directive as shown below:

#cfg_dir=/etc/nagios/servers
#cfg_dir=/etc/nagios/printers
#cfg_dir=/etc/nagios/switches
#cfg_dir=/etc/nagios/routers

cfg_dir=/etc/nagios/conf.d
...

You can open the /etc/nagios/objects/localhost.cfg and compare how items are arrenged in the web admin GUI.

Now when we have got a basic understanding of the internal configuration structure we are going to put our new configuration file in /etc/nagios/conf.d/.

$ vi /etc/nagios/conf.d/virtual1.example.com.cfg

###############################################################################
#
# HOST DEFINITION
#
###############################################################################

# Define a host for the remote machine

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               virtual1.example.com
        alias                   virtual1.example.com
        address                 192.168.122.196
        }

###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       virtual1.example.com
        service_description             Current Load
        check_command                   check_nrpe!check_load
        }

Finally restart nagios service and watch you new Host and Service in the web admin GUI.

If you run into problems, open the default nagios log file.

$ less /var/log/nagios/nagios.log

And RHEL default log file. And also read mine previous blog how to configure iptables and logging. [http://magnus-k-karlsson.blogspot.se/2014/01/configure-iptables-for-ftp-server-vsftp.html]

$ less /var/log/messages

No comments: