From 152cdcf3e425e11224b3c52cf0863b6825ae0874 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Sun, 10 Nov 2024 10:42:17 +0100 Subject: check_swap: change threshold handling again --- plugins/check_swap.c | 35 ++++++++++++++++++++--------------- plugins/check_swap.d/check_swap.h | 3 ++- plugins/check_swap.d/swap.c | 4 ++-- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/plugins/check_swap.c b/plugins/check_swap.c index e0c246db..bc90a90b 100644 --- a/plugins/check_swap.c +++ b/plugins/check_swap.c @@ -114,24 +114,29 @@ int main(int argc, char **argv) { crit_print = config.crit.value * (data.metrics.total / HUNDRED_PERCENT); } - char *perfdata = perfdata_uint64("swap", data.metrics.free, "B", true, warn_print, true, crit_print, true, 0, true, data.metrics.total); + char *perfdata = perfdata_uint64("swap", data.metrics.free, "B", config.warn_is_set, warn_print, config.crit_is_set, crit_print, true, + 0, true, data.metrics.total); - if (verbose > 1) { - printf("Warn threshold value: %" PRIu64 "\n", config.warn.value); - } + if (config.warn_is_set) { + if (verbose > 1) { + printf("Warn threshold value: %" PRIu64 "\n", config.warn.value); + } - if ((config.warn.is_percentage && (percent_used >= (double)(HUNDRED_PERCENT - config.warn.value))) || - config.warn.value >= data.metrics.free) { - data.statusCode = max_state(data.statusCode, STATE_WARNING); + if ((config.warn.is_percentage && (percent_used >= (double)(HUNDRED_PERCENT - config.warn.value))) || + config.warn.value >= data.metrics.free) { + data.statusCode = max_state(data.statusCode, STATE_WARNING); + } } - if (verbose > 1) { - printf("Crit threshold value: %" PRIu64 "\n", config.crit.value); - } + if (config.crit_is_set) { + if (verbose > 1) { + printf("Crit threshold value: %" PRIu64 "\n", config.crit.value); + } - if ((config.crit.is_percentage && (percent_used >= (double)(HUNDRED_PERCENT - config.crit.value))) || - config.crit.value >= data.metrics.free) { - data.statusCode = max_state(data.statusCode, STATE_CRITICAL); + if ((config.crit.is_percentage && (percent_used >= (double)(HUNDRED_PERCENT - config.crit.value))) || + config.crit.value >= data.metrics.free) { + data.statusCode = max_state(data.statusCode, STATE_CRITICAL); + } } printf(_("SWAP %s - %g%% free (%lluMiB out of %lluMiB) %s|%s\n"), state_text(data.statusCode), (HUNDRED_PERCENT - percent_used), @@ -196,7 +201,7 @@ swap_config_wrapper process_arguments(int argc, char **argv) { */ size_t length; length = strlen(optarg); - conf_wrapper.config.warn.is_set = true; + conf_wrapper.config.warn_is_set = true; if (optarg[length - 1] == '%') { /* It's percentage */ @@ -226,7 +231,7 @@ swap_config_wrapper process_arguments(int argc, char **argv) { */ size_t length; length = strlen(optarg); - conf_wrapper.config.crit.is_set = true; + conf_wrapper.config.crit_is_set = true; if (optarg[length - 1] == '%') { /* It's percentage */ diff --git a/plugins/check_swap.d/check_swap.h b/plugins/check_swap.d/check_swap.h index e3e350c5..5d878989 100644 --- a/plugins/check_swap.d/check_swap.h +++ b/plugins/check_swap.d/check_swap.h @@ -8,7 +8,6 @@ #endif typedef struct { - bool is_set; bool is_percentage; uint64_t value; } check_swap_threshold; @@ -28,7 +27,9 @@ typedef struct { typedef struct { bool allswaps; int no_swap_state; + bool warn_is_set; check_swap_threshold warn; + bool crit_is_set; check_swap_threshold crit; bool on_aix; int conversion_factor; diff --git a/plugins/check_swap.d/swap.c b/plugins/check_swap.d/swap.c index 6c94b33a..354efdbf 100644 --- a/plugins/check_swap.d/swap.c +++ b/plugins/check_swap.d/swap.c @@ -11,8 +11,8 @@ 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; + tmp.warn_is_set = false; + tmp.crit_is_set = false; #ifdef _AIX tmp.on_aix = true; -- cgit v1.2.3-74-g34f1