[Nagiosplug-devel] bug with "-e" argument to check_disk [patc h included]
sean finney
seanius at seanius.net
Sun Jun 6 08:15:00 CEST 2004
hi there,
On Tue, Jun 01, 2004 at 01:32:53PM +0100, Voon, Ton wrote:
> Sean,
>
> Which version of the plugins are you using? It looks like 1.3.1.
yeah, this was off of 1.3.1, sorry for not specifying that. is 1.3.1
still being maintained, or will fixes only make their way into 1.4?
> Does this exist in 1.4? If so, can you provide a patch against CVS HEAD and
> I'll apply it.
the specific problem doesn't seem to be there any longer, but now there
seems to be something else:
gingko[~/nagios-plugins-HEAD-200406040514/plugins]12:01:24$ ./check_disk -w 20% -c 15% -e
DISK OK - free space:| /=246MB;358;380;0;448 /dev/shm=504MB;403;428;0;504 /boot=62MB;76;80;0;95 /home=15705MB;28079;29834;0;35099 /usr=9411MB;9660;10263;0;12075 /usr/local=5470MB;18721;19891;0;23402 /tmp=211MB;181;192;0;227 /var=1606MB;1877;1994;0;2347 /mnt=224MB;192;204;0;241
-e is only supposed to show the partitions/devices with errors, and here
it is listing all of them. if i bump the warning level to something
that triggers an error:
gingko[~/nagios-plugins-HEAD-200406040514/plugins]12:01:32$ ./check_disk -w 30% -c 15% -e
DISK WARNING - free space: /usr/local 5471 MB (23%);| /=246MB;313;380;0;448 /dev/shm=504MB;352;428;0;504 /boot=62MB;66;80;0;95 /home=15705MB;24569;29834;0;35099 /usr=9411MB;8452;10263;0;12075 /usr/local=5470MB;16381;19891;0;23402 /tmp=211MB;158;192;0;227 /var=1606MB;1642;1994;0;2347 /mnt=224MB;168;204;0;241
it looks good all the way up to the "|". looking at the src and the
output of the first command it looks like the " - free space" is being
initialized to something and printed regardless of whether or not there
are errors, and everything after the "|" is printed regardless of
whether or not -v was specified. or maybe this is intentional?
the reason why this is not ideal for me is that these error messages
are sent to an email->pager/sms gateway at my work, and these have a
hard limit on the amount of text in any single message, and they are
also limited to the amount of text they can display at any given time.
i've attached a patch which does the following:
- if "-v" is not specified and "-e" is, the "perf" data (the stuff after
the "|") is not asprintf'd or later printed. i'm trying to make this
the least intrusive possible, so if you think it makes sense to only
print this information when -v is specified, feel free to patch my
patch :)
- if "-e" is specified and there are no errors, the " - free space: "
string is not displayed, as it doesn't make much sense
if this "perf" data is required output or the plugins now have some
form of output syntax which they're expected to follow that this patch
breaks, i'd be happy to find another way to work around the issue,
just let me know. otherwise, here it is!
thanks,
sean
-------------- next part --------------
--- check_disk.c.old 2004-06-04 14:35:04.000000000 -0400
+++ check_disk.c 2004-06-04 14:35:16.000000000 -0400
@@ -150,7 +150,7 @@
struct fs_usage fsp;
struct name_list *temp_list;
- output = strdup (" - free space:");
+ output = strdup ("");
details = strdup ("");
perf = strdup ("");
@@ -189,13 +189,16 @@
disk_result = check_disk (usp, fsp.fsu_bavail * fsp.fsu_blocksize);
result = max_state (disk_result, result);
psize = fsp.fsu_blocks*fsp.fsu_blocksize/mult;
- asprintf (&perf, "%s %s", perf,
- perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
- fsp.fsu_bavail*fsp.fsu_blocksize/mult, units,
- TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)),
- TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)),
- TRUE, 0,
- TRUE, psize));
+ // if -e was specified without -v, don't collect or print this data
+ if(!erronly || verbose){
+ asprintf (&perf, "%s %s", perf,
+ perfdata ((!strcmp(file_system, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
+ fsp.fsu_bavail*fsp.fsu_blocksize/mult, units,
+ TRUE, min ((uintmax_t)psize-(uintmax_t)w_df, (uintmax_t)((1.0-w_dfp/100.0)*psize)),
+ TRUE, min ((uintmax_t)psize-(uintmax_t)c_df, (uintmax_t)((1.0-c_dfp/100.0)*psize)),
+ TRUE, 0,
+ TRUE, psize));
+ }
if (disk_result==STATE_OK && erronly && !verbose)
continue;
@@ -218,7 +221,16 @@
}
- asprintf (&output, "%s|%s", output, perf);
+ // if output has length > 0, there have been errors, so prefix if with
+ // the "free space" text
+ if(strlen(output)>0){
+ asprintf (&output, " - free space: %s", output);
+ }
+
+ // if the user has specified -e and not -v, don't affix the perf data
+ if(!erronly || verbose){
+ asprintf (&output, "%s|%s", output, perf);
+ }
if (verbose > 2)
asprintf (&output, "%s%s", output, details);
-------------- 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/20040606/58511b81/attachment.sig>
More information about the Devel
mailing list