The following WSF/VBScript was written for Nagios/NRPE, and queries Windows WMI and makes a Software Version Check with optional validation against minimum version, with a mismatch allowance.
The things I do to improve my Nagios Server. I had to learn VBScript for this...
Nagios Setup
Command:
I use a custom command for this, as it takes arguments from the service. I also needed to increase the timeout here (as well as in the Nagios/NRPE/NSClient++ configs) because WMI calls can take some time.
define command {
command_name check_nt_software
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -t 300 -c $ARG1$ -a $ARG2$ $ARG3$ $ARG4$
}
Service:
You'll need a service per package, and I'll use a strict check of Flash Player for my example. (I always tend to give the allowance argument, even though it's not technically required when doing a strict check. I use 0 in these cases.)
define service {
use INSERT-TEMPLATE-HERE
host_name INSERT-HOSTNAME-HERE
service_description check_flash_player
display_name Check Flash Player Version
contact_groups INSERT-GROUPS-HERE
check_command check_nt_software!check_software_ver!%flash%player%!11.1.102.62!0
check_interval 10080
notification_interval 10080
}
Client Requirements:
Windows obviously. (2000 and upwards.)
WMI installed and the Win32_Product Class available. (To check, go to an admin command prompt and type "wmic product". If you see a list of software, it's working.)
NSClient++ (or similar)
Arguments allowed for NRPE.
nsc.ini (If using NSClient++)
Ensure the following are set.
[NRPE]
allow_arguments=1
command_timeout=290
[NRPE Handlers]
check_software_ver=cscript.exe //NoLogo //T:280 "check_software_ver.wsf" $ARG1$ $ARG2$ $ARG3$
Notes:
It requires one argument (Package Name - $ARG1$), and you can feed it two optional arguments of a version ($ARG2$) for comparison, and a mismatch allowance ($ARG3$) defining how many figures - starting from the right- can be ignored.
If only $ARG1$ is provided it just returns the Software/Version. ($ARG1$ can use % as a wildcard for matching.)
If only $ARG1$ and $ARG2$ are provided it also makes a strict version check.
If $ARG3$ is also provided it makes a version check according to the leeway provided by the argument. (Number must be 1 less that the component count in version number provided by $ARG2$. Special Cases are "0", meaning strict check, and 99 meaning any later version is OK.)
This will only report software that registers itself with WMI. (All MSI Installations should do this.)
Return Codes:
The following are returned;
Unknown: (3)
Software Package(s) not found.
$ARG3$ Allowance exceeds 3.
Critical: (2)
$ARG1$ missing or blank.
$ARG1$ is literally "$ARG1$" (You've got a Nagios/NRPE/NSClient config problem somewhere.)
Version Check with unsuccessful strict match.
Software found, but Version Allowance equals or exceeds number of components in the Version given in $ARG2$.
Warning: (1)
Version Check with unsuccessful match with Allowance
OK: (0)
Version Report Only
Version Check with successful Strict match
Version Check with successful match with Allowance
Other Execution Examples;
(check_command)
1. Report All Adobe Software Versions
check_nt_software!check_software_ver!%adobe%
2. Check All Flash Player Levels using strict versioning.
check_nt_software!check_software_ver!%Flash%Player%!11.0.1.152
3. Check VMWare Workstation Level ignoring build figure
check_nt_software!check_software_ver!%VMWare%Workstation%!7.1.5.19539!1
4. Check VMWare Workstation Level, using specific major version
check_nt_software!check_software_ver!%VMWare%Workstation%!7.0!1
5. Check Minimum VMWare Workstation Level, also allowing any higher major version
check_nt_software!check_software_ver!%VMWare%Workstation%!7!99
The future:
I might increase the capabilities to be able to query remote machines, and to specify what field I want to query with $ARG1$. (Vendor is a good one I think.)
Of course this means increasing my knowledge of VBScript, and at the moment I just want to avoid said platform. :D
Script/Code
check_software_ver.wsf [1.0.0.0]
Checks WMI for Software Version, with optional validation against minimum version plus mismatch allowance.
Example: cscript //nologo check_software_ver.wsf "%VMWare%Workstation%" "6.0" 99