Problem scenario
You want the Nagios Core server to monitor another AWS server. How do you install and configure the NRPE agent on Ubuntu?
Solution
Follow these step-by-step directions if you are using AWS. If the servers are not in AWS, the directions below may still work. These directions assume that the Nagios core server is running on Ubuntu in AWS. (If you want to know how to set up Nagios core on Ubuntu, see this posting.) These directions also assume you have root access to the Ubuntu servers in AWS.
#1 (Done from Nagios core server) Obtain the internal IP address of the Nagios core server. You do this by going to the back end of the Nagios server and issuing ifconfig.
#2 (Done from Nagios client; the server destined to have the NRPE agent.) Run this command on the Ubuntu server you want to be monitored by the Nagios core server:
sudo su -
#3 (Done from Nagios client; the server destined to have the NRPE agent.) Launch a script with this as the content where x.x.x.x is the IP address obtained in step #1.
apt-get -y update
apt-get -y install nagios-nrpe-server nagios-plugins
cd /etc/nagios/
cp nrpe.cfg nrpe.cfg.bak
cat nrpe.cfg.bak | sed -e 's/allowed_hosts=127.0.0.1/allowed_hosts=x.x.x.x/g' > nrpe.cfg
# The line above used to require perl as shown below:
#perl -i -pe 's/.*/server_address=x.x.x.x/ if $.==44' 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.
service nagios-nrpe-server restart
i=$(ifconfig | grep Bcast | awk '{FS=":"; print $2}' | grep -o '[.,0-9]*')
echo "Go back to the Nagios core server to monitor $i."
h=$(hostname)
echo "Also know that the hostname of this server to get the NRPE agent is $h"
#4 (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 Ubuntu server that will be monitored).
ii) Replace the "contint" in every spot below with the hostname found in step #3.
# Ubuntu Host configuration file. (Largely taken from https://www.howtoforge.com/tutorial/ubuntu-nagios/)
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
}
#5 (Done from Nagios core server)
Run this command:
/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 #6.
#6 (Done from Nagios client; the server destined to have the NRPE agent.)
Run this command:sudo service nagios-nrpe-server restart
#7 (Done from Nagios core server)
Run these commands:sudo service apache2 restart
sudo service nagios restart
#8 Open a web browser, go to this address (where x.x.x.x is either the external IP address or the FQDN of the Nagios server):
http://x.x.x.x/nagios
You will be challenged for credentials via a pop-up. For the username, use "nagiosadmin" with no quotes. For the password, enter the password you entered when it was installing.