[Nagiosplug-devel] bug with "-e" argument to check_disk [patch included]

sean finney seanius at seanius.net
Tue Jun 1 05:13:06 CEST 2004


hi there,

i've been looking into getting disk space monitoring integrated into
the other nagios monitoring i'm already doing, and i think i've found
a bug with on of the command line options, "-e".  the description says:

 -e, --errors-only
     Display only devices/mountpoints with errors

when running on a system with no disk space errors:

cork[~]12:49:49$ /usr/local/sbin/check_disk -w 15% -c 10%
DISK OK [1247916 kB (63%) free on /dev/sda7] [25815 kB (26%) free on
/dev/sda2] [1931628 kB (100%) free on /dev/shm] [1768884 kB (52%) free
on /dev/sda6] [7517516 kB (76%) free on /dev/sda3] [9166460 kB (93%)
free on /dev/sda5] [16410780 kB (74%) free on /dev/emcpowerb6] [92890296
kB (78%) free on /dev/emcpowera1] [51267056 kB (43%) free on
/dev/emcpowera2] [22861384 kB (79%) free on /dev/emcpowerb3] [7366696 kB
(51%) free on /dev/emcpowerb5]

however, when running with -e

cork[~]12:50:05$ /usr/local/sbin/check_disk -w 15% -c 10% -e
Unable to read output
/bin/df -Pk 
/dev/emcpowerb5       15124868   6983988   7372576      49%
/usr/local/swat

very strange indeed!  even stranger, if you specify the run with the
-v option, the behaviour goes away:

cork[~]12:50:44$ /usr/local/sbin/check_disk -w 15% -c 10% -e -v
/bin/df -Pk  ==> DISK OK [1247900 kB (63%) free on /dev/sda7] [25815 kB
(26%) free on /dev/sda2] [1931628 kB (100%) free on /dev/shm] [1768884
kB (52%) free on /dev/sda6] [7517516 kB (76%) free on /dev/sda3]
[9166276 kB (93%) free on /dev/sda5] [16410760 kB (74%) free on
/dev/emcpowerb6] [92899616 kB (78%) free on /dev/emcpowera1] [51266780
kB (43%) free on /dev/emcpowera2] [22861368 kB (79%) free on
/dev/emcpowerb3] [7326368 kB (51%) free on /dev/emcpowerb5]

some investigation turned up what looks like a bug in the flow of
execution in the main while loop processing the output of df, which
causes the last processed line to always have result == STATE_UNKNOWN.
specifically, line 121-122:

if (disk_result==STATE_OK && erronly && !verbose)
	continue

result is not set to the value of disk_result (via calling max_state at
the end of the while loop, which is skipped by this continue statement),
and as such is still in STATE_UNKNOWN.

attached is a very short patch (diff -u) which i believe fixes the
problem.


	sean

ps - please cc me with any correspondance, i'm not subscribed to the
     list
-------------- next part --------------
--- check_disk.c.old	2004-05-31 12:04:37.000000000 -0400
+++ check_disk.c	2004-05-31 12:45:11.000000000 -0400
@@ -118,8 +118,10 @@
 			if (strcmp (file_system, "none") == 0)
 				strncpy (file_system, mntp, MAX_INPUT_BUFFER-1);
 
-			if (disk_result==STATE_OK && erronly && !verbose)
+			if (disk_result==STATE_OK && erronly && !verbose){
+				result = max_state (result, disk_result);
 				continue;
+			}
 
 			if (disk_result!=STATE_OK || verbose>=0) 
 				asprintf (&output, "%s [%.0f kB (%d%%) free on %s]", output,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://nagios-plugins.org/archive/devel/attachments/20040601/c9cb7c82/attachment.sig>


More information about the Devel mailing list