Monitoring Windows Mount Points with Nagios

I needed to monitor some volumes on some Windows Server 2016 machines with Nagios, including some volumes with mount points rather than drive letters.  The Check WMI Plus plugin got me close, but it was only able to natively monitor drives with letters assigned.   Luckily, Check WMI Plus allows for custom checks using ini files, so I set up a custom ini file in /etc/check_wmi_plus/check_wmi_plus.d:

[myStorage diskUsed]
# this help is displayed only when -m MODE or -m MODE -s SUBMODE are specified AND --inihelp is used on the command line
inihelp=<<EOT
Get disk percentage used.  arg1 is path to the mount point.   Example: C:   or  E:\DB\DB1\
EOT
 
query=Select Name,Capacity,FreeSpace from Win32_Volume where name = "{_arg1}"
 
# Calculate percent full
customfield=PercentFree,percent,FreeSpace,Capacity,%.1f,
customfield=PercentUsed,basicmaths,100,-,PercentFree,%.1f,
 
# allow warning/critical for PercentFull
test=PercentUsed
 
display=_DisplayMsg||~|~| - ||
display=PercentUsed

My nagios check looks like this:

define service{
    use                         snmp-disk-service
    host_name                   exchange3
    service_description         disk used EX3-JDB-01
    contact_groups              exchange-admins
    check_command               check_wmi_disk!C:\\\\Mount Point\\\\!90!95
}

The slashes in the path needs to be escaped twice because (I assume) the string is being interpreted by the check_wmi_plus.pl script and the wmic utility.

The check_wmi_disk definition is:

# Check disk used using WMI
# Arguments are: Mount point, warning percentage, critical percentage
#
define command {
	command_name	check_wmi_disk
	command_line	/usr/bin/perl $USER1$/wmi/check_wmi_plus.pl -H $HOSTADDRESS$ -u [Domain]/[Service Account Username] -p [Service Account Password] --IgnoreMyOutDatedPerlModuleVersions -m myStorage -s diskUsed -a '$ARG1$' -w $ARG2 -c $ARG3$
}

Leave a Reply

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