Nagios, check_nt-Abfrage in MB anstatt %

check_nt!USEDDISKSPACE gibt bei der Ausführung sowohl die Restmenge an Plattenplatz in Prozent und in MB zurück. Das Plugin selber arbeitet aber für die Schwellwerte nur mit den Prozentwerten, was bei grossen Festplattenpartitionen ungünstig sein kann.
Auf serverfault.com ist unter http://serverfault.com/questions/309913/how-i-can-check-for-exact-amount-of-space-mb-or-gb-in-nagios-using-check-nt-co ein Wrapper-Script aufgeführt, dass es erlaubt die Festplattenabfragen in MB in Nagios einzubinden.

Wrapper-Script

#!/bin/bash

FREESPACE=`/usr/local/nagios/libexec/check_nt -H $2 -p 12489 -s pa$word \
-v USEDDISKSPACE -l $4 | awk -F"- " '{ print $4 }' | awk -F "|" '{ print $1 }'`

SIZE=`echo $FREESPACE | awk '{ print $2 }'`
UNIT=`echo $FREESPACE | awk '{ print $3 }'`

if [ $UNIT == "Gb" ]; then
    SIZE=`echo $SIZE \* 1024 | bc`
fi

if [ `echo "$SIZE >= $6" | bc` -eq 1 ]; then
    echo "$4:\_Drive_Space OK - $FREESPACE"
    exit 0
elif [ `echo "$SIZE < $6" | bc` -eq 1 -a `echo "$SIZE > $8" | bc` -eq 1 ]; then
    echo "$4:\_Drive_Space WARNING - $FREESPACE"
    exit 1
elif [ `echo "$SIZE <= $8" | bc` -eq 1 ]; then
    echo "$4:\_Drive_Space CRITICAL - $FREESPACE"
    exit 2
fi

Testing

$ check_disk_by_size.sh -H 192.168.6.31 -l c -w 10240 -c 5120
c:\_Drive_Space OK - free 13.01 Gb (36%)

$ check_disk_by_size.sh -H 192.168.6.31 -l c -w 14240 -c 5120
c:\_Drive_Space WARNING - free 13.01 Gb (36%)

$ check_disk_by_size.sh -H 192.168.6.31 -l c -w 16240 -c 15120
c:\_Drive_Space CRITICAL - free 13.01 Gb (36%)

commands.cfg anpassen

# check_disk_by_size.sh
 define command {
    command_name    check_disk_by_size
    command_line    $USER1$/check_disk_by_size.sh -H $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$
 }

cfg-Datei des Hosts anpassen

 define service {
    use                    generic-service
    host_name              server1
    service_description    Laufwerk c:\
    check_command          check_disk_by_size!-l c -w 4096 -c 2048
 }

Überpüfen der Konfigurationsdateien

su - nagios -c '/usr/sbin/nagios -v /etc/nagios/nagios.cfg'

Reading configuration data...
   Read main config file okay...
...
Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

 Nagios neu starten

service nagios restart