Adding agentless Windows WMI monitoring to Nagios

There are a couple of well documented methods to monitor Windows machines from Nagios. The most popular of these seems to be NRPE. This method works very well, but the biggest downside for me was the need to install a client on every machine that needed to be monitored. WMI seemed to be the best bet in being able to remotely monitor windows machines without needing to install an agent on the monitored machine. During my research, I cam across wmic, a bash shell wmi client capable of querying for WMI values remotely.


Installing WMI was a breeze thanks to a pre-prepared packages in the atomic repository. First we add the repository:

wget -q -O – | sh

Then it’s simply a yum wmic to install the client on a centos machine.

Preparing the target machine

We need to ensure that WMI is installed on the target machine. This also includes making sure the WMI service is started and running. The WMI service has a couple of dependencies, the most important of which is the RPC service, so we must make sure that those services are themselves started. You can view a service’s dependencies from the services console > right click on a service > properties > dependencies tab

Also check for any windows firewalls or other firewalls that will need a rule exception to allow WMI traffic. Have a look at this link for more information

Writing bash scripts using WMIC

This is where most of the work comes in. First, familiarize yourself with the available WMI classes. This basically gives you an indication of what can be monitored through WMI. The best documentation I’ve found to this end is Microsoft’s technet, here:

In a nutshell, the ones I’ve found most useful were:

CPU monitoring: PercentProcessorTime from the Win32_PerfFormattedData_PerfOS_Processor class

Memory monitoringAvailableMBytes from the Win32_PerfFormattedData_PerfOS_Memory class

Process monitoring: ThreadCount from the Win32_PerfFormattedData_PerfProc_Process class

Service monitoring: Status from the Win32_Service class

The following link will download a tar file that contains sample scripts for each of the above mentioned monitoring scenarios. They include outputting perdata for graphing. I have not include much in the way of documenting the scripts, but they are pretty self explanatory. Just note the variable that are defined in the beginning of each script so you can follow the script’s logic.

Link to scripts