Nagios is a piece of monitoring software tool Designed with scalability and flexibility in mind and its a very popular monitoring tool available in the industry. Using Nagios monitoring tool, we get instant awareness of our organisation’s mission-critical IT infrastructure. The Nagios monitoring can do Monitoring, Alerting, Response , Reporting, Maintenance and Planning for our IT infrastructure. Another advantage of Nagios is we can monitor Our Windows or Linux Based servers, Applications, Logs, Network devices, and SNMP.
Nagios vendors have different products in their line up related to monitoring. Few of them are Nagios XI, Nagios Log Server, Nagios Network Analyzer and Nagios Fusion. Top of that they published Nagios monitoring in Open source and its called by name “Nagios Core“. By design Nagios has a client-server architecture. Which means a Nagios server exists and Nagios client installed with Nagios Core Plugins is being monitored through a Nagios server.
The Nagios Core Plugins we use for a Windows is “Check_nt and nsclient++”. The one used for Linux servers are NRPE (Nagios Remote plug-in Executor) and NSCA plugins. The Nagios Server installed with Nagios core usually will have a GUI and from their we usually manage and monitor the Nagios Clients.
During these blog article we describes how to install Free OpenSouce Nagios Core 4.1.1 and Nagios Plugins 2.1.1 on Centos 7 minimal. The latest version available for Nagios core at this moment is 4.4.6. Feel free to use that latest package too or even in a Centos 8 system. The idea of installation is still the same. So Let get started.
Prior to starting our install, we need to disable SELinux.
Modify /etc/selinux/config and change enforcing to disabled.
We now need to install the programs that Core will need in order to function / install properly.
Now, let’s create a user and group for Nagios to use.
Download and Install Nagios
This is where we will download the required .tar.gz files for Nagios and Nagios Plugins.
Compile and Install Nagios.
Creating a password for nagiosadmin
We now need to create a password for the nagiosadmin user. This will be used to login to your core web GUI.
Install Nagios Plugins
Now that Nagios is installed, we need to install the plugins so that it can utilize them for checks.
If everything worked correctly prior to this, you will be able to start your Nagios Core service.
Now we should be able to access Nagios machine by navigating to http://SERVERIP/nagios/
Replace SERVERIP with our actual server IP address. A screenshot is attached for reference. Make sure port 80 is open in the server firewall.
NRPE – How To Install NRPE v3 From Source
Download the source.
Compile and Install
Update Services File
The /etc/services file is used by applications to translate human readable service names into port numbers when connecting to a machine across a network.
Open Port 5666 in the server firewall.
Open file /usr/local/nagios/etc/nrpe.cfg and make sure parameter “dont_blame_nrpe=1”.
Start the service using below command.
Now check that NRPE is listening and responding to requests.
You should see the output similar to the following:
If you get the NRPE version number (as shown above), NRPE is installed and configured correctly.
Now let’s perform the initial Nagios configuration. You only need to perform this section once, on your Nagios server.
Organize Nagios Configuration
Open the main Nagios configuration file in your favourite text editor. We’ll use vi to edit the file:
Now find and remove the comment of this line by deleting the #:
Save and exit.
Now create the directory that will store the configuration file for each server that you will monitor:
Configure check_nrpe Command
Let’s add a new command to our Nagios configuration:
Monitor a Remote CentOS 7 Host with NRPE
In this section, we’ll show you how to add a new host to Nagios, so it will be monitored.
On a server that you want to monitor, install the EPEL repository:
Now install Nagios Plugins and NRPE:
Now, let’s update the NRPE configuration file. Open it in your favorite editor (we’re using vi):
Find the allowed_hosts directive, and add the public IP address of nagios server to the comma-delimited list (substitute it in place of the highlighted example):
Save and exit. This configures NRPE to accept requests from your Nagios server, via its private IP address.
Restart NRPE to put the change into effect:
Make sure port 5666 is open in the server firewall.
Add Host to Nagios Server Configuration
On your Nagios server, create a new configuration file for each of the remote hosts that you want to monitor in /usr/local/nagios/etc/servers/. Replace the highlighted word, “yourhost”, with the name of your host:
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 public IP address of the remote client host.
With the configuration file above, Nagios will only monitor if the host is up or down. If this is sufficient for you, save and exit then restart Nagios. Make sure the client server IP will accept ICMP ping requests other wise the host will show as down.
If you want to monitor particular services, Add any of these service blocks for services you want to monitor. Note that the value of check_command determines what will be monitored, including status threshold values. Here are some examples that you can add to your host’s configuration file:
use generic-service means, it is simply inheriting the values of a service template called “generic-service” that is defined by default.
Now save and quit. Reload your Nagios configuration to put any changes into effect:
Now lets configure the NRPE to monitor resource usage like disk usage of Nagios Client.
Open file /etc/nagios/nrpe.cfg in Nagios client using vi editer. By default you will see command arguments like below are allowed in the Nagios Client server.
Due to this the Nagios server is allowed to verify above commands remotely using NRPE service.
We can test this by logging in to the Nagios server and issue command like below, we will get the Nagios Client Server Status.
Now in order to allow above Nagios service check, add below entries in the Nagios Server Configuration file /usr/local/nagios/etc/servers/yourhost.cfg
Now let’s say we need to add more resource usage check of Nagios Client in which the the corresponding commands are not defined by default on file /etc/nagios/nrpe.cfg
Add entries like below, which will add command line to monitor mailq and MySQL status in the Nagios Client.
Restart NRPE service using below command
Add below entries in the Nagios Server configuration file /usr/local/nagios/etc/servers/yourhost.cfg
Restart nagios service using below command
This concluded the Nagios Core install and monitor a Nagios client using NRPE service.
How to Install NRPE on Ubuntu 16.04
NRPE is available under default apt repositories of Ubuntu systems. Execute the following command to install it
The rest of steps for configuring NRPC in Nagios Client is same as that we done it on Centos 7 based Nagios Client.
Monitoring Windows host with Nagios
We will explain how to monitor remote windows machine and the various service running on the windows server using nagios monitoring server. Which means monitor Windows machines “private” services such as CPU load, Disk usage, Memory usage, etc. For this, we required to install an NSClient++ addon on the Windows machine. The addon acts a proxy between the Windows machine and Nagios and monitors actual services by communicating with the check_nt plugin. NSClient++ will also support check_nrpe plugin.
Download the latest version of NSClient++ from http://nsclient.org/download/
Run the NSClient++ installer package to start the installation. The welcome screen will appear. Click Next to continue to the next step.
Select Generic and click Next to continue.
Click the Typical button.
Enter the IP address(s) of the Nagios Core Server in the Allowed hosts box, separated by a comma
Enter a password in the Password box that is required for communication between the Nagios server and the Windows machine (used by check_nt plugin).
Enable common check plugins = Checked
Enable nsclient server (check_nt) = Checked
Enable NRPE Server ( check_nrpe) = Checked
Click Install button and we will see the installation completes automatically.
The NSClient++ agent will now be running as a service. Make sure port 12489 and 5666 are opened in the server firewall
Additionally open nslicent.ini file located in C:\Program Files\NSClient++\ and make sure below parameters are enabled.
Now go the Nagios server and Open file /usr/local/nagios/etc/objects/commands.cfg and make sure below entries are there
Replace -s password argument with your own check_nt password set during NsClient++ install step.
Open file /usr/local/nagios/etc/objects/templates.cfg and make sure below entries are there
Open File /usr/local/nagios/etc/objects/hostgroups.cfg and make sure below entries are there.
Suppose if the file is not present. Create a new one and add below entry in the file /usr/local/nagios/etc/nagios.cfg
Verify the Nagios Configuration and restart the service
Now lets create windows host cfg file under the folder /usr/local/nagios/etc/servers
Add below entries.
Restart the Nagios service
Now we will see screenshot like below in the nagios web interface.
Now let’s Enable Custom Scripts in with NSClient++ and use check_nrpe for nagios monitoring.
Ensure the “NRPE settings” are configured in the “nsclient.ini” file in the client machines
Ensure that arguments are allowed in “[/settings/external scripts]” in the “nsclient.ini” file in the client machines
Ensure the file “nsclient.ini” in the client machine contains the option “CheckExternalScripts=enabled” in the [/modules] section
We can also achieve this by running below commands
Now go the folderC:\Program Files\NSClient++\scripts folder and create a file named check_dummy.bat
Add below entries and save file.
Update nsclient.ini Configuration File
Open the file C:\Program Files\NSClient++\nsclient.ini in Notepad.
Find this section in the file:[/settings/external scripts/scripts]
If it doesn’t exist then add it to the end of the file.
Under this section add the following line:
Save the file and then use services.msc to restart the NSClient++ service.
Now lets Test Script From Nagios Server. SSH in to the Nagios server and issue command like below.
The output should look like this:
Now lets add this script in the Nagios server configuration file for monitoring.
Open file /usr/local/nagios/etc/servers/winhost.cfg and below entry.
Reload the nagios service. The new service check will show in the nagios panel. This concludes the install and settings up an nagios system. Leave your thoughts at the comment box available below.
Leave A Comment