Adding Remote Linux Host to Nagios Server

Created - 06/11/2015

Last Tested - N/A

OS: Centos


Setup Guest Os

Install NRPE

apt-get install nagios-nrpe-server nagios-plugins

nano /etc/nagios/nrpe.cfg

allowed_hosts=127.0.0.1, 192.168.1.100

/etc/init.d/nagios-nrpe-server restart

http://tecadmin.net/monitor-remote-linux-host-using-nagios/


Setup Hosts / Services Files

You first need to create two new files called “hosts.cfg” and “services.cfg”

Command= cd /usr/local/nagios/etc/

Command= touch hosts.cfg

Command= touch services.cfg

Now add these two files to main Nagios configuration file.

Command= nano /usr/local/nagios/etc/nagios.cfg

Add the two newly created files as shown below. Find the following line.

#You can specify individual object config files as shown below:

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

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

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

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

cfg_file=/usr/local/nagios/etc/hosts.cfg

cfg_file=/usr/local/nagios/etc/services.cfg


Adding Guests

Open hosts.cfg file and add the default host template define remote hosts as shown below. Make sure to replace host_name, alias and address with your remote host server details.

Command= nano /usr/local/nagios/etc/hosts.cfg

define host{
name                            linux-box               ; 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
}
## Default
define host{
use                             linux-box               ; Inherit default values from a template
host_name                       tecmint		  ; The name we're giving to this server
alias                           CentOS 6                ; A longer name for the server
address                         5.175.142.66            ; IP address of Remote Linux host
}

Services To Monitor

Next open services.cfg file add the following services to be monitored.

Command= nano /usr/local/nagios/etc/services.cfg

define service{
        use                     generic-service
        host_name               tecmint
        service_description     CPU Load
        check_command           check_nrpe!check_load
        }
define service{
        use                     generic-service
        host_name               tecmint
        service_description     Total Processes
        check_command           check_nrpe!check_total_procs
        }
define service{
        use                     generic-service
        host_name               tecmint
        service_description     Current Users
        check_command           check_nrpe!check_users
        }
define service{
        use                     generic-service
        host_name               tecmint
        service_description     SSH Monitoring
        check_command           check_nrpe!check_ssh
        }
define service{
        use                     generic-service
        host_name               tecmint
        service_description     FTP Monitoring
        check_command           check_nrpe!check_ftp
        }

Extra Services


NRPE Commands

Now NRPE command definition needs to be created in commands.cfg file.

Command= nano /usr/local/nagios/etc/objects/commands.cfg

Add the following NRPE command definition at the bottom of the file.

###############################################################################
# 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$
        }

Checking Nagios Config

Finally, verify Nagios Configuration files for any errors run the following command. If you get the below output then your configs are correct!

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

Total Warnings: 0
Total Errors:   0

Restart Nagios

service nagios restart