check_swap: Make check_swap work without thresholds

This commit is contained in:
Lorenz Kästle 2024-11-10 01:58:41 +01:00
parent 4b7977b25b
commit 651925dffc
3 changed files with 9 additions and 12 deletions

View file

@ -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

View file

@ -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;

View file

@ -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