Nagios: monitoring virtual Windows servers

I would like to propose one of the ways of monitoring of OS Windows server, which is installed on a Linux server as a virtual one. For this purpose, we will use Nagios and the program for Windows – NSClient++.

First of all we need to install program NSClient++ on the virtual machine. During the installation you have to set a password for access to data which the program provides on demand. This is a good idea not to set any allowed hosts to access. It will allow to avoid the problem when you do not know what a server will have Nagios to monitor . And, secondly, if you change Nagios server address you won’t need to make changes on all virtual Windows. Anyway, you can change it in the configuration file NSC.ini.

After program installation you will need to check the file C:Program FilesNSClient++NSC.ini and make sure that the following modules are uncommented:

[Modules]
FileLogger.dll – logs events in the log
CheckSystem.dll – allows you to check system settings, CPU, memory etc.
CheckDisk.dll – test drive for free space
NSClientListener.dll – allows the utility to listen on port

All necessary shortcuts are stored under the system menu. Now you can run a check and if everything is fine and no errors appeared, you can run the service NSClient++. You need to restart the service after modifying program configuration file.

And now you can configure the firewall of the host-server. Add a rule to forward packets to the internal network on port 12489. This port is used by program NSClient++ by default. Pay attention to the used protocol, it should be TCP. Also, the following rules should be inserted into the top of the table, because if you add the rules as usually they will be at the bottom of the table and other rules can overlap it. It is very important in the case of virtual machines, since the implementation of any of the schemes of virtualization will always have enough large number of rules added to the firewall of the host-server.

EXT_IP – IP of the host server on which Nagios will make requests
INT_IP – IP virtual Windows, which is located on the internal network

iptables -t nat -I PREROUTING 1 -d EXT_IP -p tcp --dport 12489 -j DNAT --to-destination INT_IP:12489
iptables -t nat -I POSTROUTING 1 -s INT_IP -p tcp --sport 12489 -j SNAT --to-source EXT_IP:12489
iptables -I FORWARD 1-p tcp --dport 12489 -j ACCEPT

Do not forget to run iptables-save to save rules, otherwise they will be lost after the first restart.

Now you can proceed to configure the service in Nagios.
First, setup the plugin for Nagios nagios-plugins-nt on the host-server, if it was not done before.
Second, before setting up the service in Nagios, make sure that everything works correctly. To do it you can run from the command line:

[Root @ host-server ~] # /usr/lib64/nagios/plugins/check_nt -H EXT_IP -p 12489 -s pass -v USEDDISKSPACE -w 30 -c 40 -d SHOWALL -l c
c: - total: 49.90 Gb - used: 29.63 Gb (59%) - free 20.27 Gb (41%) | 'c: Used Space' = 29.63Gb; 14.97; 19.96; 0.00; 49.90

It’s an example of free space check on disk C:. If everything goes well, you can proceed configuring services in Nagios.

In Nagios has quite a lot of pre-configured services to work with NSClient++. The configuration file windows.cfg contains many entries like:

define service {
use generic-service
host_name winserver
service_description NSClient + + Version
check_command check_nt! CLIENTVERSION
}

As you can see here we use check_nt, which we ran from the command line earlier. In the configuration file commands.cfg command check_nt is defined as follows:

# 'Check_nt' command definition
define command {
command_name check_nt
command_line $ USER1 $ / check_nt-H $ HOSTADDRESS $-p 12 489-v $ ARG1 $ $ ARG2 $
}

Thus, pre-configured services will be enough to cover most of the parameters on the virtual Windows. More complex tests that can get some parameters look as follows:

define service {
use generic-service
host_name winserver
service_description CPU Load
check_command check_nt! CPULOAD!-l 5,80,90
}

So that’s all you need to setup a convenient monitoring of virtual machines based on Windows.

Didn’t find the answer to your question? Ask it our administrators to reply we will publish on website.

Leave a Reply

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