Problem scenario
You have Nagios core installed on a server in AWS. You want a new AWS RedHat Enterprise Linux server to have the NRPE agent. You want thorough directions for this process to potentially automate it. How do you install and configure the NRPE agent on a RHEL server and configure a Nagios core server to monitor it?
Solution
Prerequisites
- You need to know the internal IP address of 1) the Nagios core server; for RHEL 7.x, use ifconfig. 2) the server that will receive the NRPE agent.
- The AWS Security Group must have a certain rule configured for Nagios to perform ping tests. We suggest you go to Security Groups. Go to Inbound Rules and click "Edit." Click "Add Rule." For type use "ALL ICMP - IPv4." For "Source" keep it at Custom. For the blank field use this (where x.x.x.x is the internal IP address of the Nagios core server): x.x.x.x/32
Method
#1 (Done from Nagios client; the server destined to have the NRPE agent.) Below is the content of a script. You must change the x.x.x.x to the IP address of the Nagios core server. Then run the script below on the server that you want to have the NRPE agent installed and configured on. (To run it you might run a command like this sudo bash /tmp/install.sh
.)
# Script written by continualintegration.com
#!/bin/bash
yum -y update
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install nrpe nagios-plugins-users nagios-plugins-load nagios-plugins-swap nagios-plugins-disk nagios-plugins-procs
cd /etc/nagios
cp nrpe.cfg nrpe.cfg.bakcat nrpe.cfg.bak | sed -e 's/allowed_hosts=127.0.0.1,::1/allowed_hosts=x.x.x.x/g' > nrpe.cfg
# The old way of doing the above command required perl. Here it is:# perl -i -pe 's/.*/allowed_hosts=x.x.x.x/ if $.==81' nrpe.cfg
# /etc/nagios/nrpe.cfg has an allowed_hosts stanza
# This setting can support multiple Nagios core servers. The IP addresses should be separated by a comma if you have more than one.
systemctl restart nrpe
systemctl enable nrpe
# Last line of script
#2 (Done from Nagios core server) vi /usr/local/nagios/etc/servers/contint.cfg
The content below is what you'll need for this contint.cfg file. You just have to change three parts:
i) Replace y.y.y.y with the IP address printed at the end of the script of #3 (the internal IP address of the RHEL server to get the NRPE agent).
ii) Replace the "contint" in every spot below with the hostname found in step #3.
# RedHat Linux Host configuration file. (Largely taken from https://www.howtoforge.com/tutorial/ubuntu-nagios/)
# You can create other .cfg files with unique names in the same directory /usr/local/nagios/etc/servers/
define host {
use linux-server
host_name contint
alias contint
address y.y.y.y
register 1
}
define service {
host_name contint
service_description PING
check_command check_ping!100.0,20%!500.0,60%
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
define service {
host_name contint
service_description Check Users
check_command check_local_users!20!50
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
define service {
host_name contint
service_description Local Disk
check_command check_local_disk!20%!10%!/
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
define service {
host_name contint
service_description Check SSH
check_command check_ssh
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
define service {
host_name contint
service_description Total Process
check_command check_local_procs!250!400!RSZDT
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24x7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24x7
notifications_enabled 1
register 1
}
#3 (Done from Nagios core server)
Run this command:sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If an error is found in the output, correct the problem. If zero errors are found, proceed to step #4.
#4 (Done from Nagios client; the server destined to have the NRPE agent.)
Run these commands:
sudo systemctl restart nrpe
sudo systemctl enable nrpe
#5 (Done from Nagios core server)
Run these commands:
sudo systemctl restart httpd
sudo systemctl restart nagios