5. Monitoring Slave from Master using NRPE

NRPE (Nagios Remote Plugin Executor) allows the Nagios Master server to monitor services on remote Linux servers (Slave).


Step 1: Configure NRPE Daemon (Slave Server)

NRPE configuration file location depends on installation type. Usually:

/usr/local/nagios/etc/nrpe.cfg

Open the file:

nano /usr/local/nagios/etc/nrpe.cfg

Find and edit allowed_hosts:

allowed_hosts=127.0.0.1,192.168.1.10

Add your Nagios Master IP address.

Restart NRPE service:

sudo systemctl restart nrpe

Step 2: Verify Connection from Master Server

Run this command from Nagios Master server:

/usr/local/nagios/plugins/check_nrpe -H <Slave_IP_Address>

This verifies communication between Master and Slave.


Step 3: Define Slave Host on Master Server

Create file:

/usr/local/nagios/etc/objects/slave.cfg

Add the following configuration:

define host{
    use                     linux-server   
    host_name               Slave-Server-01
    alias                   My Remote Linux Host
    address                 <Slave_IP_Address> 
    max_check_attempts      5
    check_period            24x7
    notification_interval   30
    notification_period     24x7
    contact_groups          admins
    register                1
}

Step 4: Define Services to Monitor

Add service definitions in the same file:

# Check CPU Load
define service{
    use                     generic-service
    host_name               Slave-Server-01
    service_description     CPU Load
    check_command           check_nrpe!check_load
}

# Check Current Users
define service{
    use                     generic-service
    host_name               Slave-Server-01
    service_description     Current Users
    check_command           check_nrpe!check_users
}

# Check Root Disk Space
define service{
    use                     generic-service
    host_name               Slave-Server-01
    service_description     Root Disk Space
    check_command           check_nrpe!check_disk
}

check_nrpe sends the request from Master to Slave.
check_load, check_users, check_disk are commands executed on Slave.


Step 5: Enable Configuration and Restart Nagios

Edit main configuration file:

/usr/local/nagios/etc/nagios.cfg

Add:

cfg_file=/usr/local/nagios/etc/objects/slave.cfg

Restart Nagios:

sudo systemctl restart nagios

6. Configure Email Notifications in Nagios Core

Step 1: Install Mail Service

Nagios uses a Mail Transfer Agent like Postfix or Sendmail.

Test email:

echo "Test" | mail -s "Test Email" user@example.com

Step 2: Define Contact

Edit contacts.cfg:

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

Add:

define contact {
    contact_name                shanmugananthan
    use                         generic-contact
    alias                       shan
    email                       shan@example.com
    service_notification_period 24x7
    host_notification_period    24x7
    service_notification_options w,u,c,r,f,s
    host_notification_options   d,u,r,f,s
    service_notification_commands notify-service-by-email
    host_notification_commands  notify-host-by-email
}

Step 3: Add Contact to Contact Group

define contactgroup{
    contactgroup_name admins
    alias             Nagios Administrators
    members           nagiosadmin,shanmugananthan
}

Step 4: Apply Contact Group to Host

define host {
    use             linux-server
    host_name       web-server-01
    alias           Web Server
    address         192.168.1.10
    contact_groups  admins
}

Step 5: Verify and Restart Nagios

Verify configuration:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Restart Nagios:

sudo systemctl restart nagios

Summary