Introduction
In our earlier articles on nagios we explained in detail how to install nagios core on the centos 6 system and configure it. In this article we will explain step by step how to monitor a remote machine with nagios core.
Prerequisites:
We will be installing the packages required for configuring nagios on a client machine using the EPEL repository therefore it must be enabled on the system. Please go through our article on how to enable the EPEL repository if you are unfamiliar about how to do so.
Install NRPE and nagios plugins
Now we will install the nrpe package along with nagios plugins using yum.
[ssuri@nagios-client:~] $ sudo yum install nrpe nagios-plugins-all Loaded plugins: rhnplugin, security This system is receiving updates from RHN Classic or RHN Satellite. Setting up Install Process ------------------------------------output truncated for brevity Installed: nagios-plugins-all.x86_64 0:2.2.1-4git.el6 Dependency Installed: fping.x86_64 0:2.4b2-10.el6 lgtonmc.x86_64 0:9.2.1.2-1 lm_sensors.x86_64 0:3.1.1-17.el6 nagios-plugins.x86_64 0:2.2.1-4git.el6 nagios-plugins-breeze.x86_64 0:2.2.1-4git.el6 nagios-plugins-by_ssh.x86_64 0:2.2.1-4git.el6 nagios-plugins-cluster.x86_64 0:2.2.1-4git.el6 nagios-plugins-dhcp.x86_64 0:2.2.1-4git.el6 nagios-plugins-dig.x86_64 0:2.2.1-4git.el6 nagios-plugins-disk.x86_64 0:2.2.1-4git.el6 nagios-plugins-disk_smb.x86_64 0:2.2.1-4git.el6 nagios-plugins-dns.x86_64 0:2.2.1-4git.el6 nagios-plugins-dummy.x86_64 0:2.2.1-4git.el6 nagios-plugins-file_age.x86_64 0:2.2.1-4git.el6 nagios-plugins-flexlm.x86_64 0:2.2.1-4git.el6 nagios-plugins-fping.x86_64 0:2.2.1-4git.el6 nagios-plugins-game.x86_64 0:2.2.1-4git.el6 nagios-plugins-hpjd.x86_64 0:2.2.1-4git.el6 nagios-plugins-http.x86_64 0:2.2.1-4git.el6 nagios-plugins-icmp.x86_64 0:2.2.1-4git.el6 nagios-plugins-ide_smart.x86_64 0:2.2.1-4git.el6 nagios-plugins-ircd.x86_64 0:2.2.1-4git.el6 nagios-plugins-ldap.x86_64 0:2.2.1-4git.el6 nagios-plugins-load.x86_64 0:2.2.1-4git.el6 nagios-plugins-log.x86_64 0:2.2.1-4git.el6 nagios-plugins-mailq.x86_64 0:2.2.1-4git.el6 nagios-plugins-mrtg.x86_64 0:2.2.1-4git.el6 nagios-plugins-mrtgtraf.x86_64 0:2.2.1-4git.el6 nagios-plugins-mysql.x86_64 0:2.2.1-4git.el6 nagios-plugins-nagios.x86_64 0:2.2.1-4git.el6 nagios-plugins-nt.x86_64 0:2.2.1-4git.el6 nagios-plugins-ntp.x86_64 0:2.2.1-4git.el6 nagios-plugins-ntp-perl.x86_64 0:2.2.1-4git.el6 nagios-plugins-nwstat.x86_64 0:2.2.1-4git.el6 nagios-plugins-oracle.x86_64 0:2.2.1-4git.el6 nagios-plugins-overcr.x86_64 0:2.2.1-4git.el6 nagios-plugins-perl.x86_64 0:2.2.1-4git.el6 nagios-plugins-pgsql.x86_64 0:2.2.1-4git.el6 nagios-plugins-ping.x86_64 0:2.2.1-4git.el6 nagios-plugins-procs.x86_64 0:2.2.1-4git.el6 nagios-plugins-real.x86_64 0:2.2.1-4git.el6 nagios-plugins-rpc.x86_64 0:2.2.1-4git.el6 nagios-plugins-sensors.x86_64 0:2.2.1-4git.el6 nagios-plugins-smtp.x86_64 0:2.2.1-4git.el6 nagios-plugins-snmp.x86_64 0:2.2.1-4git.el6 nagios-plugins-ssh.x86_64 0:2.2.1-4git.el6 nagios-plugins-swap.x86_64 0:2.2.1-4git.el6 nagios-plugins-tcp.x86_64 0:2.2.1-4git.el6 nagios-plugins-time.x86_64 0:2.2.1-4git.el6 nagios-plugins-ups.x86_64 0:2.2.1-4git.el6 nagios-plugins-users.x86_64 0:2.2.1-4git.el6 nagios-plugins-wave.x86_64 0:2.2.1-4git.el6 qstat.x86_64 0:2.11-9.20080912svn311.el6
Modify nrpe.cfg file:
Now that we have installed nrpe we need to tell nrpe the IP address of our nagios server so that nrpe allows active checks from it. For this we modify the allowed_hosts directive in the nrpe.cfg file which is generally located at the path /etc/nagios/nrpe.cfg.
[ssuri@nagios-client:~] $ grep allowed_hosts /etc/nagios/nrpe.cfg allowed_hosts=127.0.0.1, 192.168.87.134 [ssuri@nagios-client:~] $
Restart NRPE to put the change made in the nrpe.cfg file into effect and also enable the service to start on reboot.
sudo systemctl start nrpe.service sudo systemctl enable nrpe.service
Create a configuration file for the client on the nagios core server:
On our Nagios server, we will create a new configuration file for the remote host on which we installed nrpe and nagios plugins. We are creating our host configuration file in the directory /nagiosap/objects/servers. You could create configuration files for the remote hosts that you would like to monitor in a directory of your choice. Just be sure to mention it in the nagios.cfg file so that nagios is aware of the locations. Add in the following host definition, replacing the host_name value with your remote hostname, the alias value with a description of the host and the address value with the private IP address of the remote host.
We’ve named the file as nagios-client.cfg and added the below content in the file.
define host { use linux-server host_name nagios-client alias nagios-client Lab server address 10.22.128.28 contact_groups admins max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 }
What we defined above is referred to as a host definition. With the configuration file above, Nagios will only monitor if the host is up or down. In order to monitor any service on the remote host we need to add service definitions. We’ve added service definitions for the ping and SSH service in our host configuration file.
define service { use generic-service host_name nagios-client service_description PING check_command check_ping!100.0,20%!500.0,60% } define service { use generic-service host_name nagios-client service_description SSH check_command check_ssh notifications_enabled 0 }
The value of check_command determines what will be monitored, including status threshold values. We will discus host and service definitions in greater detail in a separate article.
After this reload the nagios service.
sudo systemctl reload nagios.service
Now we should be able to see the newly added node in nagios web interface.
Conclusion
This concludes our discussion on how to add a host to be monitored by nagios. Please note that what we’ve shown here is a very basic client configuration setup. We would be discussing remote host monitoring in greater detail in future articles.
Sahil Suri
Latest posts by Sahil Suri (see all)
- Google Cloud basics: Activate Cloud Shell - May 19, 2021
- Create persistent swap partition on Azure Linux VM - May 18, 2021
- DNF, YUM and RPM package manager comparison - May 17, 2021
- Introduction to the aptitude package manager for Ubuntu - March 26, 2021
- zypper package management tool examples for managing packages on SUSE Linux - March 26, 2021