[Nagiosplug-devel] check_disk inconsistency

Earl C. Ruby III earl at switchmanagement.com
Wed Apr 23 12:13:16 CEST 2003


I am trying to use check disk to send me a critical warning when I have both 
less than 5% free space AND less than 1GB free on a volume. If I use the 
command:

check_disk -w 10%,1500000 -c 5%,1000000

This works on small partitions that have more than 5% free space AND less than 
1GB free. In these cases the volume is shown as OK:

# ./check_disk -w 10%,1500000 -c 5%,1000000 -p /dev/sda1
DISK OK [92204 kB (91%) free on /dev/sda1]

If I reverse the order of the % and KB:

# ./check_disk -w 1500000,10% -c 1000000,5% -p /dev/sda1
DISK CRITICAL [92204 kB (91%) free on /dev/sda1]

Looking at the source code I see that the parameter parsing only works if you 
pass KB,% -- it only grabs the percentage if you pass %,KB.

Also looking at the source code I see:

int
check_disk (usp, free_disk)
{
        int result = STATE_UNKNOWN;
        /* check the percent used space against thresholds */
        if (usp >= 0 && usp >= (100.0 - c_dfp))
                result = STATE_CRITICAL;
        else if (c_df >= 0 && free_disk <= c_df)
                result = STATE_CRITICAL;
        else if (usp >= 0 && usp >= (100.0 - w_dfp))
                result = STATE_WARNING;
        else if (w_df >= 0 && free_disk <= w_df)
                result = STATE_WARNING;
        else if (usp >= 0.0)
                result = STATE_OK;
        return result;
}

This results in an OR condition being applied to % free and KB free, which is 
not what you want for checking disks. For checking disks you want an AND 
condition, like so:

int
check_disk (usp, free_disk)
{
        int result = STATE_UNKNOWN;
        /* check the percent used space against thresholds */
        if (usp >= 0 && c_dfp >= 0 && c_df < 0 && usp >= (100.0 - c_dfp))
                result = STATE_CRITICAL;
        else if (c_df >= 0 && c_dfp < 0 && free_disk <= c_df)
                result = STATE_CRITICAL;
        else if (usp >= 0 && c_dfp >= 0 && usp >= (100.0 - c_dfp) && c_df >= 0 
&& free_disk <= c_df)
                result = STATE_CRITICAL;
        else if (usp >= 0 && w_dfp >= 0 && w_df < 0 && usp >= (100.0 - w_dfp))
                result = STATE_WARNING;
        else if (w_df >= 0 && w_dfp < 0 && free_disk <= w_df)
                result = STATE_WARNING;
        else if (usp >= 0 && w_dfp >= 0 && usp >= (100.0 - w_dfp) && w_df >= 0 
&& free_disk <= w_df)
                result = STATE_WARNING;
        else if (usp >= 0.0)
                result = STATE_OK;
        return result;
}


Then it would correctly apply AND conditions and give you applicable results 
for both very small and very large disk volumes.

Unfortunately I'm having problems compiling the source for the plugins "as is" 
without any modifications. :-(

-- 
Earl C. Ruby III <earl at switchmanagement.com>
Senior System Engineer / Developer
Switch Management




More information about the Devel mailing list