Category Archives: Nagios WMI

Nagios WMI 2 – Creating A Perl WMI Script

Nagios WMI 2 – Creating A Perl WMI Script

This section of the installation articles provides the information for creating a simple Perl script to interrogate whether a Windows Service is running over WMI from Nagios.

It is by no means an approved script by Nagios standards but is written using some of the guidelines found here.  The script does achieve the simple result of if the service is Running then it returns an OK to Nagios and for any other reason it returns a CRITICAL.

Of course it could be expanded out so that things like Starting are shown as a WARNING but for the purposes of this script a simple Running / Not Running result was required.

The script:
#!/usr/bin/perl
use strict;

use Getopt::Long;
use lib "/usr/lib64/nagios/plugins";
use utils qw (%ERRORS);

my ($opt_u, $opt_p, $opt_H, $opt_s);

Getopt::Long::Configure('bundling');
GetOptions (
        "u=s" => \$opt_u, "username" => \$opt_u,
        "p=s" => \$opt_p, "password" => \$opt_p,
        "H=s" => \$opt_H, "hostname" => \$opt_H,
        "s=s" => \$opt_s, "service" => \$opt_s);

my $cmd = `wmic -U wonderland/$opt_u%"$opt_p" //$opt_H "select DisplayName,State,StartMode FROM Win32_Service where DisplayName = '$opt_s'"`;
my $output = $cmd;

if (substr($output, 0, 20) ne "CLASS: Win32_Service")
        {
         print "ERROR: Cannot connect to WMI or service not found\n";
         exit $ERRORS{'CRITICAL'};
        }
my @result = split(/\n/, $output);

my @status = split(/\|/, $result[2]);

if (@status[3] ne "Running")
        {
         print "CRITICAL: " . $opt_s . " Is Not Running\n";
         exit $ERRORS{'CRITICAL'};
        }
else
        {
         print "OK: " . $opt_s . " Is Running\n";
         exit $ERRORS{'OK'};
        }

Nagios WMI 1 – Installing The WMI Client

Nagios WMI 1 – Installing The WMI Client

Adding WMI To The Linux Host

The first step in configuring Nagios to monitor a Remote Windows Server through WMI is to install the WMI client.  The following sections provide details on how to add the Atomic Repository, install the WMI client, and finally test that it is working and communicating with the Windows Server.

Adding The Atomic Repository

The first part of installing the WMI client on to the server is to add the Atomic repository repository to the server.  To add the Atomic repository to the server perform the following steps :-

  • In the command line execute the following command :-

wget -q -O – http://www.atomicorp.com/installers/atomic | sh

  • When prompted accept the agreement
  • When prompted select OK to install the package

Installing The WMI Client

The next part is to install the WMI client package from the Atomic Repository and to do this perform the step below :-

  • In the command prompt execute the following command :-

yum install wmi

  • When prompted select OK to install the package

Testing The WMI Client

To test that the WMI client is installed and working perform the following steps :-

  • In the command prompt execute the following command :-

wmic -U {Domain Name}/{Admin User}%{Admin Password //{Host} “select * from Win32_ComputerSystem”

E.G. wmic -U Example/Administrator%password //examplehost “select * from Win32_ComputerSystem”

  • Replace the {Domain Name}. {Admin User}, {Admin Password}, and {Host} with your relevant settings
  • The command will return a list of WMI information it can enumerate from the Win32_ComputerSystem Class on the host server.

Nagios WMI – Introduction And Pre-Requisites

Nagios WMI – Introduction And Pre-Requisites

This article explains how to set up basic monitoring of a Windows server through Nagios using WMI (Windows Management Instrumentation).

Using WMI has the advantage over using the NSClient++ Software as it requires no additional software to be installed on the Windows server in order for Nagios to monitor it.

A user account on the Windows Server or Domain is needed to allow Nagios to talk to WMI which can be configured but this is outside the scope of this article.

Pre-Requisites

In order to monitor a Windows server through Nagios using WMI the following pre-requisites must be met :-

  1. A configured and working Nagios server
  2. A user account on the Windows Server or Domain with rights to communicate with WMI

Nagios Technical Documentation

Nagios Technical Documentation

Current Articles

Archived Articles