aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Thomas Guyot-Sionnest <dermoth@aei.ca> 2014-01-29 03:40:11 -0500
committerGravatar Thomas Guyot-Sionnest <dermoth@aei.ca> 2014-01-29 03:40:11 -0500
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 3a91d75d..3ed99670 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ This file documents the major additions and syntax changes between releases.
ENHANCEMENTS
check_ide_smart now defaults to plugin output, original output appended with -v
Extra-Opts are now enabled by default
+ check_swap now supports a configurable state when there is no swap
FIXES
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.
been disabled because they were broken
State retention: the NAGIOS_PLUGIN_STATE_DIRECTORY environment variable has been
renamed MP_STATE_DIRECTORY. The old variable will continue to work in v1.6.x
+ check_swap used to allow returning OK on a system without swap when only percent thresholds
+ were used. This is no longer the case and one must now use -n/--no-swap=<state>
1.5 2nd October 2013
ENHANCEMENTS
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);
int warn_percent = 0;
int crit_percent = 0;
float warn_size_bytes = 0;
-float crit_size_bytes= 0;
+float crit_size_bytes = 0;
int verbose;
int allswaps;
+int no_swap_state = STATE_CRITICAL;
int
main (int argc, char **argv)
@@ -372,6 +373,9 @@ main (int argc, char **argv)
int
check_swap (int usp, float free_swap_mb)
{
+
+ if (!free_swap_mb) return no_swap_state;
+
int result = STATE_UNKNOWN;
float free_swap = free_swap_mb * (1024 * 1024); /* Convert back to bytes as warn and crit specified in bytes */
if (usp >= 0 && crit_percent != 0 && usp >= (100.0 - crit_percent))
@@ -400,6 +404,7 @@ process_arguments (int argc, char **argv)
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
{"allswaps", no_argument, 0, 'a'},
+ {"no-swap", required_argument, 0, 'n'},
{"verbose", no_argument, 0, 'v'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
@@ -410,7 +415,7 @@ process_arguments (int argc, char **argv)
return ERROR;
while (1) {
- c = getopt_long (argc, argv, "+?Vvhac:w:", longopts, &option);
+ c = getopt_long (argc, argv, "+?Vvhac:w:n:", longopts, &option);
if (c == -1 || c == EOF)
break;
@@ -455,6 +460,10 @@ process_arguments (int argc, char **argv)
case 'a': /* all swap */
allswaps = TRUE;
break;
+ case 'n':
+ if ((no_swap_state = mp_translate_state(optarg)) == ERROR) {
+ usage4 (_("no-swap result must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
+ }
case 'v': /* verbose */
verbose++;
break;
@@ -541,6 +550,8 @@ print_help (void)
printf (" %s\n", _("Exit with CRITCAL status if less than PERCENT of swap space is free"));
printf (" %s\n", "-a, --allswaps");
printf (" %s\n", _("Conduct comparisons for all swap partitions, one by one"));
+ printf (" %s\n", "-n, --no-swap=<ok|warning|critical|unknown>");
+ printf (" %s %s\n", _("Resulting state when there is no swap regardless of thresholds. Default:"), state_text(no_swap_state));
printf (UT_VERBOSE);
printf ("\n");