Setup Nagios on RHEL 7.4:
Note:
Make sure EPEL repository is enabled on both server and client for installing packages:
sudo rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
Configuring the Nagios – Server
1.Install Nagios
sudo yum install nagios nagios-common nagios-plugins-all
-
Set the password for admin user nagiosadmin
sudo htpasswd -c /etc/nagios/passwd nagiosadmin
-
Start and enable httpd
sudo systemctl start httpd sudo systemctl enable httpd sudo systemctl enable nagios
-
Open the ports
sudo firewall-cmd --zone=public --add-port=80/tcp –permanent sudo firewall-cmd --zone=public --add-port=5666/tcp –permanent
-
Reload firewall
sudo firewall-cmd –reload
-
Install nrpe
sudo yum install nrpe
-
Start nrpe and make sure all services nagios,httpd,nrpe are in active state
service nrpe start
-
Add nrpe as service in the commands.cfg
path: /etc/nagios/objects/commands.cfg define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }
-
Validate the configuration using
sudo nagios -v /etc/nagios/nagios.cfg
and fix the errors if there are any
10 Check the status of nrpe daemon running on local and remote machine
./check_nrpe -H localhost
-
Restart nagios using
sudo service nagios restart
Nagios server can be accessed using URL
http://<Server>/nagios
username: nagiosadmin
password: nagiosadmin
localhost will be added as default, and some services like http/ssh/users/load will be monitored
Configuring the Client:
-
Install nrpe and plugins on the client
sudo yum install nrpe nagios-plugins-all
-
Allow the server to access the client by adding ip address of the server in the file /etc/nagios/nrpe.cfg
add ip of server to allow_hosts and change dont_blame_nrpe -> 1
-
Allow passing command line arguments by changing
dont_blame_me=0 to 1
-
Start nrpe service
sudo service nrpe start
-
Validate check_nrpe command from Nagios server using:
check_nrpe -H <nagios-client>
Adding the client to Server:
Login to Server
Create a directory
/etc/nagios/clients
In the file /etc/nagios/nagios.cfg add the below line
cfg_dir=etc/nagios/clients
Add below entry in the /etc/nagios/clients/clients.cfg for a specific host:
Example:
define host{
use linux-server
host_name host.xyz.com
alias host.xyz.com
address 10.0.0.4
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
contacts nagiosadmin
}
define service{
use generic-service
host_name host.xyz.com
service_description CPU Load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name host.xyz.com
service_description Current Users
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name host.xyz.com
service_description Zombie Processes
check_command check_nrpe!check_zombie_procs
}
define service{
use generic-service
host_name host.xyz.com
service_description Total Processes
check_command check_nrpe!check_total_procs
}
define service{
use generic-service
host_name host.xyz.com
service_description EDH Process
check_command check_nrpe!check_edh_process
}
-
Restart nrpe on client
Service nrpe restart
Adding customized plugins on the client:
Add the script in the below path on the client:
/usr/lib64/nagios/plugins
It can be a shell/perl/python/java script, all nagios cares about is the return code of the script
0 – Ok
1- Warning
2- Critical
3- Unknown
Example script:
[srcdvops@hostname plugins]$ cat check_fact
check_rmc.sh
#!/bin/bash
function check_rmc()
{
lssrc -s ctrmc | grep -w active;
if [ $? -eq 0 ]
then
return 0;
else
return 2;
fi
}
check_rmc
Define this as service in commands.cfg
define service{
use generic-service
host_name host.xyz.com
service_description check_rmc
check_command check_nrpe!check_total_procs
}