In our previous post we have successfully installed and configured Nagios core in our Ubuntu server.
Now, let us add some clients to monitor by Nagios server.
To do that we have to install nrpe and nagios-plugins in our monitoring targets.
On CentOS/RHEL
Add EPEL repository in your CentOS/RHEL 6.x or 7 clients to install nrpe package.
To install EPEL on CentOS 7, run the following command:
yum install epel-release
Adding EPEL Repository to RHEL / CentOS / Scientific Linux 6.x
wget http://epel.mirror.net.in/epel/6/i386/epel-release-6-8.noarch.rpm rpm -Uvh epel-release-6-8.noarch.rpm
Adding EPEL Repository to RHEL / CentOS / Scientific Linux 5.x
wget http://epel.mirror.net.in/epel/5/i386/epel-release-5-4.noarch.rpm rpm -Uvh epel-release-5-4.noarch.rpm
On Debian/Ubuntu clients:
apt-get update apt-get install nagios-nrpe-server nagios-plugins
Configure Monitoring targets
Edit /etc/nagios/nrpe.cfg file
vi /etc/nagios/nrpe.cfg
Find the allowed_hosts directive, and add the private IP address of your Nagios server to the comma-delimited list.
allowed_hosts=127.0.0.1,112.142.224.168
Save and exit. This configures NRPE to accept requests from your Nagios server,
Start nrpe service on CentOS clients:
systemctl start nrpe chkconfig nrpe on
CentOS 6.x:
service nrpe start chkconfig nrpe on
For Debian/Ubuntu Clients, start nrpe service as shown below:
/etc/init.d/nagios-nrpe-server restart
Go back to your Nagios server, and add the clients in the configuration file.
vi /usr/local/nagios/etc/nagios.cfg
uncomment the following line
cfg_dir=/usr/local/nagios/etc/servers
Create a directory called “servers” under “/usr/local/nagios/etc/”.
mkdir /usr/local/nagios/etc/servers
Create config file to the monitoring target (client):
vi /usr/local/nagios/etc/servers/server1.cfg
Add the following lines:
define host { use linux-server host_name server1.hon.com alias Server 1 address 10.132.234.52 max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 }
Here, 10.132.234.52 is my nagios client IP address and server1.hon.com is the client system’s hostname.
Finally, restart nagios service.
/etc/init.d/nagios restart OR service nagios restart
Wait for few seconds, and refresh nagios admin console in the browser and navigate to “Hosts” section in the left pane. Now, You will see the newly added client will be visible there. Click on the host to see if there is anything wrong or any alerts it has.
Similarly, you can define more clients by creating a separate config files in
“/usr/local/nagios/etc/servers” directory for each client.
Define Services
We have just defined the monitoring host. Now, let us add some services of the monitoring host.
For example, to monitor the ssh service, edit the client configuration file.
vi /usr/local/nagios/etc/servers/server1.cfg
add the following lines for SSH service.
define service { use generic-service host_name yourhost service_description SSH check_command check_ssh notifications_enabled 0 }
For PING
define service { use generic-service host_name yourhost service_description PING check_command check_ping!100.0,20%!500.0,60% }
Wait for few seconds (90 seconds by default), and check for the added services (i.e SSH and PING) in the nagios web interface. Navigate to Services section on the left side bar, you’ll see the services there.