How I can check for exact amount of space left (MB or GB) in Nagios using check_nt command instead of percentage value?

Currently I'm using this command:

 check_command           check_nt!USEDDISKSPACE!-l c -w 90 -c 95

but this is checking for percentage value of used disk space and I want to receive notification when I will have exact amount of GB left on some drive (for example warning when there will be 10GB left and critical when there will be only 5GB left).

Thank you

link|improve this question

76% accept rate
feedback

1 Answer

up vote 4 down vote accepted

check_nt!USEDDISKSPACE returns the both of size and percentage of disk usage. But thresholds are percentage.

If you want to receive alert based on size, you can write a wrapper shell script for check_nt command, e.g check_disk_by_size:

#!/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%)
link|improve this answer
Thank you. It is working just as I wanted – GrZeCh Sep 10 '11 at 13:22
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.