diff options
author | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2014-01-29 03:40:11 -0500 |
---|---|---|
committer | Thomas Guyot-Sionnest <dermoth@aei.ca> | 2014-01-29 03:40:11 -0500 |
commit | 7afbca0b8c6f98bf6349bc8dc854d50e760ce8e1 (patch) | |
tree | a4f45b486f5a4d7403a4c1d1a4bcaf1d169038b8 /plugins/check_swap.c | |
parent | 8fc9e5ac4b3a699f8d6b78471829692f0c92d5fa (diff) | |
download | monitoring-plugins-7afbca0b8c6f98bf6349bc8dc854d50e760ce8e1.tar.gz |
check_swap: add supports for a configurable state when there is no swap
Check_swap used to allow no swap when thresholds were only specified in
percent. This is no longer the case and the state now must be specified
explicitly. The default is to always return CRITICAL when the swap is
absent regardless of thresholds.
Diffstat (limited to 'plugins/check_swap.c')
-rw-r--r-- | plugins/check_swap.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/plugins/check_swap.c b/plugins/check_swap.c index 04256adf..d8fc14f2 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c | |||
@@ -60,9 +60,10 @@ void print_help (void); | |||
60 | int warn_percent = 0; | 60 | int warn_percent = 0; |
61 | int crit_percent = 0; | 61 | int crit_percent = 0; |
62 | float warn_size_bytes = 0; | 62 | float warn_size_bytes = 0; |
63 | float crit_size_bytes= 0; | 63 | float crit_size_bytes = 0; |
64 | int verbose; | 64 | int verbose; |
65 | int allswaps; | 65 | int allswaps; |
66 | int no_swap_state = STATE_CRITICAL; | ||
66 | 67 | ||
67 | int | 68 | int |
68 | main (int argc, char **argv) | 69 | main (int argc, char **argv) |
@@ -372,6 +373,9 @@ main (int argc, char **argv) | |||
372 | int | 373 | int |
373 | check_swap (int usp, float free_swap_mb) | 374 | check_swap (int usp, float free_swap_mb) |
374 | { | 375 | { |
376 | |||
377 | if (!free_swap_mb) return no_swap_state; | ||
378 | |||
375 | int result = STATE_UNKNOWN; | 379 | int result = STATE_UNKNOWN; |
376 | float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ | 380 | float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */ |
377 | if (usp >= 0 && crit_percent != 0 && usp >= (100.0 - crit_percent)) | 381 | if (usp >= 0 && crit_percent != 0 && usp >= (100.0 - crit_percent)) |
@@ -400,6 +404,7 @@ process_arguments (int argc, char **argv) | |||
400 | {"warning", required_argument, 0, 'w'}, | 404 | {"warning", required_argument, 0, 'w'}, |
401 | {"critical", required_argument, 0, 'c'}, | 405 | {"critical", required_argument, 0, 'c'}, |
402 | {"allswaps", no_argument, 0, 'a'}, | 406 | {"allswaps", no_argument, 0, 'a'}, |
407 | {"no-swap", required_argument, 0, 'n'}, | ||
403 | {"verbose", no_argument, 0, 'v'}, | 408 | {"verbose", no_argument, 0, 'v'}, |
404 | {"version", no_argument, 0, 'V'}, | 409 | {"version", no_argument, 0, 'V'}, |
405 | {"help", no_argument, 0, 'h'}, | 410 | {"help", no_argument, 0, 'h'}, |
@@ -410,7 +415,7 @@ process_arguments (int argc, char **argv) | |||
410 | return ERROR; | 415 | return ERROR; |
411 | 416 | ||
412 | while (1) { | 417 | while (1) { |
413 | c = getopt_long (argc, argv, "+?Vvhac:w:", longopts, &option); | 418 | c = getopt_long (argc, argv, "+?Vvhac:w:n:", longopts, &option); |
414 | 419 | ||
415 | if (c == -1 || c == EOF) | 420 | if (c == -1 || c == EOF) |
416 | break; | 421 | break; |
@@ -455,6 +460,10 @@ process_arguments (int argc, char **argv) | |||
455 | case 'a': /* all swap */ | 460 | case 'a': /* all swap */ |
456 | allswaps = TRUE; | 461 | allswaps = TRUE; |
457 | break; | 462 | break; |
463 | case 'n': | ||
464 | if ((no_swap_state = mp_translate_state(optarg)) == ERROR) { | ||
465 | usage4 (_("no-swap result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3).")); | ||
466 | } | ||
458 | case 'v': /* verbose */ | 467 | case 'v': /* verbose */ |
459 | verbose++; | 468 | verbose++; |
460 | break; | 469 | break; |
@@ -541,6 +550,8 @@ print_help (void) | |||
541 | printf (" %s\n", _("Exit with CRITCAL status if less than PERCENT of swap space is free")); | 550 | printf (" %s\n", _("Exit with CRITCAL status if less than PERCENT of swap space is free")); |
542 | printf (" %s\n", "-a, --allswaps"); | 551 | printf (" %s\n", "-a, --allswaps"); |
543 | printf (" %s\n", _("Conduct comparisons for all swap partitions, one by one")); | 552 | printf (" %s\n", _("Conduct comparisons for all swap partitions, one by one")); |
553 | printf (" %s\n", "-n, --no-swap=<ok|warning|critical|unknown>"); | ||
554 | printf (" %s %s\n", _("Resulting state when there is no swap regardless of thresholds. Default:"), state_text(no_swap_state)); | ||
544 | printf (UT_VERBOSE); | 555 | printf (UT_VERBOSE); |
545 | 556 | ||
546 | printf ("\n"); | 557 | printf ("\n"); |