From 651925dffce258bf71a6717fd3d4e0969f29b6a6 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 10 Nov 2024 01:58:41 +0100 Subject: check_swap: Make check_swap work without thresholds --- plugins/check_swap.c | 11 ++--------- plugins/check_swap.d/check_swap.h | 7 ++++--- plugins/check_swap.d/swap.c | 3 +++ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/plugins/check_swap.c b/plugins/check_swap.c index ef60ce1b..94f41a55 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -166,11 +166,6 @@ swap_config_wrapper process_arguments(int argc, char **argv) { swap_config_wrapper conf_wrapper = {.errorcode = OK}; conf_wrapper.config = swap_config_init(); - if (argc < 2) { - conf_wrapper.errorcode = ERROR; - return conf_wrapper; - } - static struct option longopts[] = {{"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'}, @@ -195,6 +190,7 @@ swap_config_wrapper process_arguments(int argc, char **argv) { */ size_t length; length = strlen(optarg); + conf_wrapper.config.warn.is_set = true; if (optarg[length - 1] == '%') { /* It's percentage */ @@ -224,6 +220,7 @@ swap_config_wrapper process_arguments(int argc, char **argv) { */ size_t length; length = strlen(optarg); + conf_wrapper.config.crit.is_set = true; if (optarg[length - 1] == '%') { /* It's percentage */ @@ -266,10 +263,6 @@ swap_config_wrapper process_arguments(int argc, char **argv) { } } - if (conf_wrapper.config.warn.value == 0 && conf_wrapper.config.crit.value == 0) { - conf_wrapper.errorcode = ERROR; - return conf_wrapper; - } if ((conf_wrapper.config.warn.is_percentage == conf_wrapper.config.crit.is_percentage) && (conf_wrapper.config.warn.value < conf_wrapper.config.crit.value)) { /* This is NOT triggered if warn and crit are different units, e.g warn diff --git a/plugins/check_swap.d/check_swap.h b/plugins/check_swap.d/check_swap.h index 9e8be75f..e3e350c5 100644 --- a/plugins/check_swap.d/check_swap.h +++ b/plugins/check_swap.d/check_swap.h @@ -8,9 +8,10 @@ #endif typedef struct { + bool is_set; bool is_percentage; uint64_t value; -} threshold; +} check_swap_threshold; typedef struct { unsigned long long free; // Free swap in Bytes! @@ -27,8 +28,8 @@ typedef struct { typedef struct { bool allswaps; int no_swap_state; - threshold warn; - threshold crit; + check_swap_threshold warn; + check_swap_threshold crit; bool on_aix; int conversion_factor; } swap_config; diff --git a/plugins/check_swap.d/swap.c b/plugins/check_swap.d/swap.c index 18db210c..293fdd71 100644 --- a/plugins/check_swap.d/swap.c +++ b/plugins/check_swap.d/swap.c @@ -10,6 +10,9 @@ swap_config swap_config_init(void) { tmp.no_swap_state = STATE_CRITICAL; tmp.conversion_factor = SWAP_CONVERSION; + tmp.warn.is_set = false; + tmp.crit.is_set = false; + #ifdef _AIX tmp.on_aix = true; #else -- cgit v1.2.3-74-g34f1