diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2024-11-10 01:58:41 +0100 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2024-11-10 01:58:41 +0100 |
commit | 651925dffce258bf71a6717fd3d4e0969f29b6a6 (patch) | |
tree | a4f36840dfc454b3e9a03810cbe560813efa56de | |
parent | 4b7977b25bda44a9a781d53011b73e71f7167c02 (diff) | |
download | monitoring-plugins-651925dffce258bf71a6717fd3d4e0969f29b6a6.tar.gz |
check_swap: Make check_swap work without thresholds
-rw-r--r-- | plugins/check_swap.c | 11 | ||||
-rw-r--r-- | plugins/check_swap.d/check_swap.h | 7 | ||||
-rw-r--r-- | 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) { | |||
166 | swap_config_wrapper conf_wrapper = {.errorcode = OK}; | 166 | swap_config_wrapper conf_wrapper = {.errorcode = OK}; |
167 | conf_wrapper.config = swap_config_init(); | 167 | conf_wrapper.config = swap_config_init(); |
168 | 168 | ||
169 | if (argc < 2) { | ||
170 | conf_wrapper.errorcode = ERROR; | ||
171 | return conf_wrapper; | ||
172 | } | ||
173 | |||
174 | static struct option longopts[] = {{"warning", required_argument, 0, 'w'}, {"critical", required_argument, 0, 'c'}, | 169 | static struct option longopts[] = {{"warning", required_argument, 0, 'w'}, {"critical", required_argument, 0, 'c'}, |
175 | {"allswaps", no_argument, 0, 'a'}, {"no-swap", required_argument, 0, 'n'}, | 170 | {"allswaps", no_argument, 0, 'a'}, {"no-swap", required_argument, 0, 'n'}, |
176 | {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, | 171 | {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, |
@@ -195,6 +190,7 @@ swap_config_wrapper process_arguments(int argc, char **argv) { | |||
195 | */ | 190 | */ |
196 | size_t length; | 191 | size_t length; |
197 | length = strlen(optarg); | 192 | length = strlen(optarg); |
193 | conf_wrapper.config.warn.is_set = true; | ||
198 | 194 | ||
199 | if (optarg[length - 1] == '%') { | 195 | if (optarg[length - 1] == '%') { |
200 | /* It's percentage */ | 196 | /* It's percentage */ |
@@ -224,6 +220,7 @@ swap_config_wrapper process_arguments(int argc, char **argv) { | |||
224 | */ | 220 | */ |
225 | size_t length; | 221 | size_t length; |
226 | length = strlen(optarg); | 222 | length = strlen(optarg); |
223 | conf_wrapper.config.crit.is_set = true; | ||
227 | 224 | ||
228 | if (optarg[length - 1] == '%') { | 225 | if (optarg[length - 1] == '%') { |
229 | /* It's percentage */ | 226 | /* It's percentage */ |
@@ -266,10 +263,6 @@ swap_config_wrapper process_arguments(int argc, char **argv) { | |||
266 | } | 263 | } |
267 | } | 264 | } |
268 | 265 | ||
269 | if (conf_wrapper.config.warn.value == 0 && conf_wrapper.config.crit.value == 0) { | ||
270 | conf_wrapper.errorcode = ERROR; | ||
271 | return conf_wrapper; | ||
272 | } | ||
273 | if ((conf_wrapper.config.warn.is_percentage == conf_wrapper.config.crit.is_percentage) && | 266 | if ((conf_wrapper.config.warn.is_percentage == conf_wrapper.config.crit.is_percentage) && |
274 | (conf_wrapper.config.warn.value < conf_wrapper.config.crit.value)) { | 267 | (conf_wrapper.config.warn.value < conf_wrapper.config.crit.value)) { |
275 | /* This is NOT triggered if warn and crit are different units, e.g warn | 268 | /* 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 @@ | |||
8 | #endif | 8 | #endif |
9 | 9 | ||
10 | typedef struct { | 10 | typedef struct { |
11 | bool is_set; | ||
11 | bool is_percentage; | 12 | bool is_percentage; |
12 | uint64_t value; | 13 | uint64_t value; |
13 | } threshold; | 14 | } check_swap_threshold; |
14 | 15 | ||
15 | typedef struct { | 16 | typedef struct { |
16 | unsigned long long free; // Free swap in Bytes! | 17 | unsigned long long free; // Free swap in Bytes! |
@@ -27,8 +28,8 @@ typedef struct { | |||
27 | typedef struct { | 28 | typedef struct { |
28 | bool allswaps; | 29 | bool allswaps; |
29 | int no_swap_state; | 30 | int no_swap_state; |
30 | threshold warn; | 31 | check_swap_threshold warn; |
31 | threshold crit; | 32 | check_swap_threshold crit; |
32 | bool on_aix; | 33 | bool on_aix; |
33 | int conversion_factor; | 34 | int conversion_factor; |
34 | } swap_config; | 35 | } 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) { | |||
10 | tmp.no_swap_state = STATE_CRITICAL; | 10 | tmp.no_swap_state = STATE_CRITICAL; |
11 | tmp.conversion_factor = SWAP_CONVERSION; | 11 | tmp.conversion_factor = SWAP_CONVERSION; |
12 | 12 | ||
13 | tmp.warn.is_set = false; | ||
14 | tmp.crit.is_set = false; | ||
15 | |||
13 | #ifdef _AIX | 16 | #ifdef _AIX |
14 | tmp.on_aix = true; | 17 | tmp.on_aix = true; |
15 | #else | 18 | #else |