Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 5 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%)

You can add it to Nagios like this:

"check_disk_by_size.sh".

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

define service{
        use                     generic-service
        host_name               fileserver1
        service_description     Drive Space fileserver1: L:
        check_command           check_disk_by_size!-l L -w 4096 -c 2048
        notifications_enabled   1
        }
share|improve this answer
    
Thank you. It is working just as I wanted –  GrZeCh Sep 10 '11 at 13:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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