diff options
author | Oliver Skibbe <oliskibbe@gmail.com> | 2016-11-04 11:35:12 +0100 |
---|---|---|
committer | Oliver Skibbe <oliskibbe@gmail.com> | 2016-11-04 11:35:12 +0100 |
commit | 5663b037170da16802918eb57e73c6fb27a825f3 (patch) | |
tree | 7c0d8eafae535267821c1d2ed6645ec34c16931e /plugins/check_disk.c | |
parent | 8672529b37fc73fbcc15cb2b2ba9b677f37dac5e (diff) | |
download | monitoring-plugins-5663b037170da16802918eb57e73c6fb27a825f3.tar.gz |
check_disk - show all disks if state is ok and option error only is used
This fix changes output of check_disk in case of --error-only/-e option
is used and state is ok
- Old output: DISK OK
- New output: DISK OK - free space: / 159731 MB (83% inode=61%);
/dev/shm 2926 MB (100% inode=99%); /boot 58 MB (32% inode=99%);
Resolves: #1420
Diffstat (limited to 'plugins/check_disk.c')
-rw-r--r-- | plugins/check_disk.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 874a0ee0..8e793c94 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c | |||
@@ -168,6 +168,7 @@ main (int argc, char **argv) | |||
168 | int result = STATE_UNKNOWN; | 168 | int result = STATE_UNKNOWN; |
169 | int disk_result = STATE_UNKNOWN; | 169 | int disk_result = STATE_UNKNOWN; |
170 | char *output; | 170 | char *output; |
171 | char *ko_output; | ||
171 | char *details; | 172 | char *details; |
172 | char *perf; | 173 | char *perf; |
173 | char *preamble; | 174 | char *preamble; |
@@ -187,6 +188,7 @@ main (int argc, char **argv) | |||
187 | 188 | ||
188 | preamble = strdup (" - free space:"); | 189 | preamble = strdup (" - free space:"); |
189 | output = strdup (""); | 190 | output = strdup (""); |
191 | ko_output = strdup (""); | ||
190 | details = strdup (""); | 192 | details = strdup (""); |
191 | perf = strdup (""); | 193 | perf = strdup (""); |
192 | stat_buf = malloc(sizeof *stat_buf); | 194 | stat_buf = malloc(sizeof *stat_buf); |
@@ -351,9 +353,6 @@ main (int argc, char **argv) | |||
351 | TRUE, 0, | 353 | TRUE, 0, |
352 | TRUE, path->dtotal_units)); | 354 | TRUE, path->dtotal_units)); |
353 | 355 | ||
354 | if (disk_result==STATE_OK && erronly && !verbose) | ||
355 | continue; | ||
356 | |||
357 | if(disk_result && verbose >= 1) { | 356 | if(disk_result && verbose >= 1) { |
358 | xasprintf(&flag_header, " %s [", state_text (disk_result)); | 357 | xasprintf(&flag_header, " %s [", state_text (disk_result)); |
359 | } else { | 358 | } else { |
@@ -379,15 +378,27 @@ main (int argc, char **argv) | |||
379 | (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); | 378 | (unsigned long)w_df, (unsigned long)c_df, w_dfp, c_dfp); |
380 | */ | 379 | */ |
381 | 380 | ||
381 | /* OS: #1420 save all not ok paths to different output, but only in case of error only option */ | ||
382 | if (disk_result!=STATE_OK && erronly) { | ||
383 | xasprintf (&ko_output, "%s%s %s %.0f %s (%.0f%%", | ||
384 | ko_output, flag_header, | ||
385 | (!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir, | ||
386 | path->dfree_units, | ||
387 | units, | ||
388 | path->dfree_pct); | ||
389 | } | ||
390 | |||
382 | } | 391 | } |
383 | 392 | ||
393 | /* OS: #1420 only show offending paths if error only option is set, but show all paths if everything is ok */ | ||
394 | output = (erronly && result!=STATE_OK) ? ko_output : output; | ||
384 | } | 395 | } |
385 | 396 | ||
386 | if (verbose >= 2) | 397 | if (verbose >= 2) |
387 | xasprintf (&output, "%s%s", output, details); | 398 | xasprintf (&output, "%s%s", output, details); |
388 | 399 | ||
389 | 400 | ||
390 | printf ("DISK %s%s%s|%s\n", state_text (result), (erronly && result==STATE_OK) ? "" : preamble, output, perf); | 401 | printf ("DISK %s%s%s|%s\n", state_text (result), preamble, output, perf); |
391 | return result; | 402 | return result; |
392 | } | 403 | } |
393 | 404 | ||