How to add Windows and Linux Hosts to Nagios

In this tutorial, we will learn how to add Windows and Linux Hosts in Nagios Monitoring Tool. Before start, I  will recommend you to read my previous blog Easy Way to Install Nagios Monitoring Tool on AWS.

In the above previous Turorial, we have already learned to Install Nagios Monitoring Tool, now we will add Windows and Linux hosts to Nagios Monitoring Tool for monitoring purpose.

Also Read: How to achieve A Grade SSL Certificate on IIS

&& Install Redis on Linux from source

In order to add Windows and Linux hosts in the Nagios Monitoring tool, follow the below steps:

Check Nagios Configuration path

Login to Nagios Server. Use the following command to check the Nagios configuration path.

$ ps -ef | grep nagios

In the above screenshot, you can see the Nagios configuration file as /etc/Nagios/nagios.cfg.

Now suppose we have one Windows server and one Linux Server in our network and we need to monitor these two servers and their services using Nagios monitoring tool.

Create config files for Windows and Linux host

  • Create a directory, say montitorhosts in /etc/nagios/objects/

 $ mkdir /etc/nagios/objects/monitorhosts

  • Create two directories, say linuxhosts and windowshosts in /etc/nagios/objects/monitorhosts/

  $ mkdir /etc/nagios/objects/monitorhosts/windowshosts

 

$ mkdir /etc/nagios/objects/monitorhosts/linuxhosts

  • Create two config files , windowsserver.cfg and linuxserver.cfg in newly created directories  windowshosts and linuxhosts respectively.To create above files , you need to copy the already existing files /etc/nagios/objects/windows.cfg and /etc/nagios/objects/localhost.cfg as /etc/nagios/objects/monitorhosts/windowshosts/windowsserver.cfg  and /etc/nagios/objects/monitorhosts/linuxhosts/linuxserver.cfg respectively.

 $  cp /etc/nagios/objects/windows.cfg  /etc/nagios/objects/monitorhosts/windowshosts/windowsserver.cfg

 

  $ cp /etc/nagios/objects/localhost.cfg  /etc/nagios/objects/monitorhosts/linuxhosts/linuxserver.cfg

Change the configuration of windowsserver.cfg and linuxserver.cfg files

Open windowsserver.cfg file.I am using nano editor to open the files here.

$ nano /etc/nagios/objects/monitorhosts/windowshosts/windowsserver.cfg

Search for  host_name and address in windowsserver.cfg . Change the Value of host_name as webserver(or any other name that you want)  and put the IP address of Windows Server as the value of the address.

In my case, the IP Address of  Windows Server is 172.31.28.185.

Make sure to change the value of host_name as winserver everywhere in the windowsserver.cfg file.

Now open linuxserver.cfg file with nano editor.

$ nano /etc/nagios/objects/monitorhosts/linuxhosts/linuxserver.cfg

Search for  host_name and address in linuxserver.cfg. Change the Value of host_name as linuxserver (or any other name that you want) and put the IP address of Linux Server as the value of the address.

In my case, the IP Address of  Linux Server is 172.31.25.189

Make sure to change the value of host_name as linuxserver everywhere in linuxserver.cfg file.

Also, change the hostgroup_name as linux-servers1 or anything that you want.

 

Change in nagios.cfg

Now open /etc/nagios/nagios.cfg file and add below entry.

  $ nano /etc/nagios/nagios.cfg

cfg_dir=/etc/nagios/objects/monitorhosts

Check the Nagios Configuration

 $ /usr/sbin/nagios  -v /etc/nagios/nagios.cfg

If you get zero warnings and zero Errors as a result, you are ok to restart the Nagios service.

Restart Nagios Service

$ service nagios restart

Configuration in Linux host

Login to  Linux Server and Install nrpe plugin.

   $ sudo yum install nrpe  -y

Open nrpe config file

$ nano /etc/nagios/nrpe.cfg

Put the IP address of Nagios Server in allowed_hosts in nrpe.cfg.

Restart nrpe service

We are now all done in Linux Server.

Configuration in Windows host

Log in to your Windows  Server and download nsclient++ and install it. You can use the following link to download the nsclient++ for windows.

http://nsclient.org/download/

Install Nsclient++ in your Windows Server.

Select Generic

Select Typical

Enter Nagios Server IP Address in Allowed Hosts and tick mark the modules as mentioned in the below screenshot.

Click on Finish

nsclient.ini settings

Now open the following file as run as administrator in your Windows Server

C:Program FilesNSClient++nsclient.ini

CheckExternalScripts = enabled

CheckHelpers = enabled

CheckEventLog = enabled

CheckNSCP = enabled

CheckDisk = enabled

CheckSystem = enabled

NSClientServer = enabled

NRPEServer = enabled

After changes restart the nsclient++ service in services.

We are now all done in our Windows Server.

AWS Security Group Configuration for Windows and  Linux Server

Open Security Group for Windows Server and allow port 5666 and 12489 and ICMP for Nagios Server IP.

Open Security Group for Linux Server and allow port 5666 and ICMP port for Nagios Server IP.

Note: If your servers are not in the AWS environment, you can allow these ports in the local firewall of both the servers.

Monitor Windows and Linux Host

Now your both Linux and Windows Servers are ready to Monitor. You can monitor your servers using the following URL.

http://NagiosServerPublicIP/nagios

Default Username: nagiosadmin

Default Password : nagiosadmin

 

I hope you enjoyed this tutorial and learned to add Windows and Linux Host in Nagios Monitoring Tool. If you think this is really helpful, please do share my website https://devopsmyway.com to others as well. Also, please give your valuable feedback in the comment box.

If you think we helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter

You may also like…

Leave a Reply

Your email address will not be published. Required fields are marked *