Nagios: setup monitoring via WMI

Nagios: setup monitoring via WMI

Nagios: setup monitoring via WMI 150 150 Roderick Derks

Download the Zenoss WMI library, compile and install.

wget http://dev.zenoss.org/svn/trunk/inst/externallibs/wmi-1.3.16.tar.bz2
tar xvjf wmi-1.3.16.tar.bz2
cd wmi-1.3.16
 

 

First, download the latest version and untar it. Copy both check_wmi_plus.pl and the check_wmi_plus.d folder to Nagios’ libexec folder.

  • For me, this is /usr/local/nagios/libexec.
  • I renamed the script to check_wmi_plus… I find it cleaner when Nagios plugins don’t have file extensions.

Make the script executable.

sudo chmod a+x /usr/local/nagios/libexec/check_wmi_plus

The WMI client

Check WMI Plus depends on wmic, the Linux WMI client. Previously, one would simply install the wmi-client package from apt and be on their way. However, this package is now unavailable for newer releases due to licensing issues.

So we compile from source!

First, make sure you’ve got what it takes.

sudo apt-get install build-essential

Now, download the latest version of wmi from here. Untar the archive.

Open GNUmakefile, in the wmi-1.X.XX folder. We need to make a few mods so that everything compiles smoothly.

Delete or comment out (by adding a pound sign) the following lines (line numbers may vary slightly for you):

ZENOSS_BINDIR     = $(ZENHOME)/bin # Line 20

    ZENPYTHON         = $(ZENOSS_BINDIR)/python # Line 21

    USE_BREAKPAD =1# Line 73

    $(call check,directory,$(ZENHOME),"ZENHOME")# Line 111

    $(call check,directory,$(ZENHOME),"ZENHOME")# Line 130

And change line 22 (where the PYTHON variable is declared) to this:

PYTHON           ?=/usr/bin/python

If necessary, substitute the path above for the path to python on your system.

which python

Save and close GNUmakefile.

Enter the WMI directory, if you aren’t already there.

cd wmi-1.X.XX

And compile WMI.

make

Copy the WMI client binary to your bin folder.

cp Samba/source/bin/wmic /bin

Now try running wmic.

$ wmic

    Usage:[-?|--help][--usage][-d|--debuglevel DEBUGLEVEL][--debug-stderr]

            [-s|--configfile CONFIGFILE][--option=name=value]

            [-l|--log-basename LOGFILEBASE][--leak-report][--leak-report-full]

            [-R|--name-resolve NAME-RESOLVE-ORDER]

            [-O|--socket-options SOCKETOPTIONS][-n|--netbiosname NETBIOSNAME]

            [-W|--workgroup WORKGROUP][--realm=REALM][-i|--scope SCOPE]

            [-m|--maxprotocol MAXPROTOCOL][-U|--user [DOMAIN\]USERNAME[%PASSWORD]]

            [-N|--no-pass][--password=STRING][-A|--authentication-file FILE]

            [-S|--signing on|off|required][-P|--machine-pass]

            [--simple-bind-dn=STRING][-k|--kerberos STRING]

            [--use-security-mechanisms=STRING][-V|--version][--namespace=STRING]

            [--delimiter=STRING]

            //host query

Example: wmic -U [domain/]adminuser%password //host "select * from Win32_ComputerSystem"

     

Congrats! The WMI client is now installed on your system. You may delete the WMI source directory, now.

cd ../

    rm -r wmi-1*

Perl Modules

Certain Perl modules are also required for the plugin to work as intended.

sudo cpan Data::DumperGetopt::LongDateTimeScalar::UtilStorable

Plugin Configuration

Finally, we need to configure the plugin so that it knows where certain files are located.

Open the check_wmi_plus script and change these lines with the appropriate paths (line numbers may vary slightly for you):

my $conf_file='/usr/local/nagios/libexec/check_wmi_plus.d/check_wmi_plus.conf';# Line 30

    use lib "/usr/local/nagios/libexec";# Line 45

    our $base_dir='/usr/local/nagios/libexec/check_wmi_plus.d';# Line 116

And open the check_wmi_plus.conf file, located in the check_wmi_plus.d folder, and change these lines with the appropriate paths (line numbers may, again, vary slightly for you):

use lib "/usr/local/nagios/libexec";#  Line 15

    $wmic_command="/usr/bin/wmic";#  Line 24

    $wmi_ini_file="$base_dir/check_wmi_plus.ini";#  Line 31

    $wmi_ini_dir="$base_dir";# Line 37

Save and close the file.

Try it out

By now, you should have a working check_wmi_plus script residing in Nagios’ libexec folder.

Here are just two example commands you can try. This checks CPU usage:

/usr/local/nagios/libexec/check_wmi_plus -H windowsserver -u domain/user -p userpassword -m checkcpu

OK (SamplePeriod7 sec)-Average CPU Utilisation2.82%|'Avg CPU Utilisation'=2.82%;

And this checks the CPU usage of a particular process:

/usr/local/nagios/libexec/check_wmi_plus -H terminalserver -u domain/user -p userpassword -m checkproc -s cpu  -a msaccess

OK (SamplePeriod602 sec)-Found7Instance(s) of "msaccess" running. CPU_MSACCESS(PID=7996)=0.0%   CPU_MSACCESS(PID=14124)=0.0%   CPU_MSACCESS(PID=9704)=0.0%   CPU_MSACCESS(PID=15020)=0.0%   CPU_MSACCESS(PID=10856)=0.0%   CPU_MSACCESS(PID=10036)=0.0%   CPU_MSACCESS(PID=12996)=0.0%   |'Process Count'=7;'Avg Utilisation CPU_MSACCESS'=0.0%;'Avg Utilisation CPU_MSACCESS'=0.0%;'Avg Utilisation CPU_MSACCESS'=0.0%;'Avg Utilisation CPU_MSACCESS'=0.0%;'Avg Utilisation CPU_MSACCESS'=0.0%;'Avg Utilisation CPU_MSACCESS'=0.0%;'Avg Utilisation CPU_MSACCESS'=0.0%;

Now, all that’s left for you to do is to read all the documentation on this plugin and discover all its options and possibilities and how awesome it really is.

Alot of help is actually bundled with the plugin..

/usr/local/nagios/libexec/check_wmi_plus --help | less

 

Check_wmi_plus.pl plugin info can be found here.

cd /tmp
wget http://edcint.co.nz/checkwmiplus/sites/default/files/check_wmi_plus.v1.52.tar.gz
cd /usr/local/nagios/libexec/360viewpoint
tar xvzf /tmp/check_wmi_plus.v1.52.tar.gz

cpan install ExtUtils::MakeMaker
cpan install Perl::OSType
cpan install Module::Build::Compat
cpan install Config::IniFiles

Check the versions of the installed perl modules:
./check_wmi_plus.pl -d -d | head -n 20

cpan install Data::Dumper
cpan install Scalar::Util
cpan install Storable
cpan install Getopt::Long

Roderick Derks

Liefhebber van fietsen, van het oplossen van IT puzzels, en van het delen van informatie om anderen te helpen.

All stories by:Roderick Derks

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Your Name (required)

    Your Email (required)

    Subject

    Your Message

      Your Name (required)

      Your Email (required)

      Subject

      Your Message