summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Guyot-Sionnest <dermoth@aei.ca>2014-01-29 08:40:11 (GMT)
committerThomas Guyot-Sionnest <dermoth@aei.ca>2014-01-29 08:40:11 (GMT)
commit7afbca0b8c6f98bf6349bc8dc854d50e760ce8e1 (patch)
treea4f45b486f5a4d7403a4c1d1a4bcaf1d169038b8
parent8fc9e5ac4b3a699f8d6b78471829692f0c92d5fa (diff)
downloadmonitoring-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.
-rw-r--r--NEWS3
-rw-r--r--plugins/check_swap.c15
2 files changed, 16 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 3a91d75..3ed9967 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ This file documents the major additions and syntax changes between releases.
4 ENHANCEMENTS 4 ENHANCEMENTS
5 check_ide_smart now defaults to plugin output, original output appended with -v 5 check_ide_smart now defaults to plugin output, original output appended with -v
6 Extra-Opts are now enabled by default 6 Extra-Opts are now enabled by default
7 check_swap now supports a configurable state when there is no swap
7 8
8 FIXES 9 FIXES
9 Don't let e.g. check_http's -C option reset SSL version if e.g. -S 1 -C 5 is specified 10 Don't let e.g. check_http's -C option reset SSL version if e.g. -S 1 -C 5 is specified
@@ -20,6 +21,8 @@ This file documents the major additions and syntax changes between releases.
20 been disabled because they were broken 21 been disabled because they were broken
21 State retention: the NAGIOS_PLUGIN_STATE_DIRECTORY environment variable has been 22 State retention: the NAGIOS_PLUGIN_STATE_DIRECTORY environment variable has been
22 renamed MP_STATE_DIRECTORY. The old variable will continue to work in v1.6.x 23 renamed MP_STATE_DIRECTORY. The old variable will continue to work in v1.6.x
24 check_swap used to allow returning OK on a system without swap when only percent thresholds
25 were used. This is no longer the case and one must now use -n/--no-swap=<state>
23 26
241.5 2nd October 2013 271.5 2nd October 2013
25 ENHANCEMENTS 28 ENHANCEMENTS
diff --git a/plugins/check_swap.c b/plugins/check_swap.c
index 04256ad..d8fc14f 100644
--- a/plugins/check_swap.c
+++ b/plugins/check_swap.c
@@ -60,9 +60,10 @@ void print_help (void);
60int warn_percent = 0; 60int warn_percent = 0;
61int crit_percent = 0; 61int crit_percent = 0;
62float warn_size_bytes = 0; 62float warn_size_bytes = 0;
63float crit_size_bytes= 0; 63float crit_size_bytes = 0;
64int verbose; 64int verbose;
65int allswaps; 65int allswaps;
66int no_swap_state = STATE_CRITICAL;
66 67
67int 68int
68main (int argc, char **argv) 69main (int argc, char **argv)
@@ -372,6 +373,9 @@ main (int argc, char **argv)
372int 373int
373check_swap (int usp, float free_swap_mb) 374check_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");