From 4966b920a2392484a6ae83a4a499c24a2942c832 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 1 Aug 2025 14:29:08 +0200 Subject: General smal improvements to the lib logic --- lib/utils_base.c | 15 ++++++++------- lib/utils_base.h | 5 +++-- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/utils_base.c b/lib/utils_base.c index c49a473f..60103614 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c @@ -25,6 +25,7 @@ *****************************************************************************/ #include "../plugins/common.h" +#include "states.h" #include #include "utils_base.h" #include @@ -256,21 +257,21 @@ bool check_range(double value, range *my_range) { yes = false; } - if (my_range->end_infinity == false && my_range->start_infinity == false) { + if (!my_range->end_infinity&& !my_range->start_infinity) { if ((my_range->start <= value) && (value <= my_range->end)) { return no; } return yes; } - if (my_range->start_infinity == false && my_range->end_infinity == true) { + if (!my_range->start_infinity && my_range->end_infinity) { if (my_range->start <= value) { return no; } return yes; } - if (my_range->start_infinity == true && my_range->end_infinity == false) { + if (my_range->start_infinity && !my_range->end_infinity ) { if (value <= my_range->end) { return no; } @@ -280,14 +281,14 @@ bool check_range(double value, range *my_range) { } /* Returns status */ -int get_status(double value, thresholds *my_thresholds) { +mp_state_enum get_status(double value, thresholds *my_thresholds) { if (my_thresholds->critical != NULL) { - if (check_range(value, my_thresholds->critical) == true) { + if (check_range(value, my_thresholds->critical)) { return STATE_CRITICAL; } } if (my_thresholds->warning != NULL) { - if (check_range(value, my_thresholds->warning) == true) { + if (check_range(value, my_thresholds->warning)) { return STATE_WARNING; } } @@ -395,7 +396,7 @@ char *np_extract_value(const char *varlist, const char *name, char sep) { return value; } -const char *state_text(int result) { +const char *state_text(mp_state_enum result) { switch (result) { case STATE_OK: return "OK"; diff --git a/lib/utils_base.h b/lib/utils_base.h index 123066f8..8fb114c2 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h @@ -7,6 +7,7 @@ #include "./perfdata.h" #include "./thresholds.h" +#include "states.h" #ifndef USE_OPENSSL @@ -55,7 +56,7 @@ void set_thresholds(thresholds **, char *, char *); void print_thresholds(const char *, thresholds *); bool check_range(double, range *); bool mp_check_range(mp_perfdata_value, mp_range); -int get_status(double, thresholds *); +mp_state_enum get_status(double, thresholds *); /* Handle timeouts */ extern int timeout_state; @@ -107,6 +108,6 @@ void np_state_write_string(time_t, char *); void np_init(char *, int argc, char **argv); void np_set_args(int argc, char **argv); void np_cleanup(void); -const char *state_text(int); +const char *state_text(mp_state_enum); #endif /* _UTILS_BASE_ */ -- cgit v1.2.3-74-g34f1 From aaff3aa9da27ff7666d2a776d524c784b76eb3d7 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Fri, 12 Sep 2025 16:36:48 +0200 Subject: lib: some formatting + remove some unnecessary stuff --- lib/perfdata.h | 46 +++++++++++++++++++++++----------------------- lib/thresholds.h | 4 ++-- 2 files changed, 25 insertions(+), 25 deletions(-) (limited to 'lib') diff --git a/lib/perfdata.h b/lib/perfdata.h index c5d4a61d..e51ef5fd 100644 --- a/lib/perfdata.h +++ b/lib/perfdata.h @@ -28,7 +28,7 @@ typedef struct { /* * New range type with generic numerical values */ -typedef struct mp_range_struct { +typedef struct { mp_perfdata_value start; bool start_infinity; /* false (default) or true */ @@ -41,7 +41,7 @@ typedef struct mp_range_struct { /* * Old range type with floating point values */ -typedef struct range_struct { +typedef struct { double start; bool start_infinity; double end; @@ -53,7 +53,7 @@ typedef struct range_struct { /* * Perfdata type for storing perfdata output */ -typedef struct perfdata_struct { +typedef struct { char *label; char *uom; mp_perfdata_value value; @@ -131,15 +131,15 @@ mp_range_parsed mp_parse_range_string(const char * /*input*/); */ void pd_list_append(pd_list[1], mp_perfdata); -#define mp_set_pd_value(P, V) \ - _Generic((V), \ - float: mp_set_pd_value_float, \ - double: mp_set_pd_value_double, \ - int: mp_set_pd_value_int, \ - unsigned int: mp_set_pd_value_u_int, \ - long: mp_set_pd_value_long, \ - unsigned long: mp_set_pd_value_u_long, \ - long long: mp_set_pd_value_long_long, \ +#define mp_set_pd_value(P, V) \ + _Generic((V), \ + float: mp_set_pd_value_float, \ + double: mp_set_pd_value_double, \ + int: mp_set_pd_value_int, \ + unsigned int: mp_set_pd_value_u_int, \ + long: mp_set_pd_value_long, \ + unsigned long: mp_set_pd_value_u_long, \ + long long: mp_set_pd_value_long_long, \ unsigned long long: mp_set_pd_value_u_long_long)(P, V) mp_perfdata mp_set_pd_value_float(mp_perfdata, float); @@ -151,17 +151,17 @@ mp_perfdata mp_set_pd_value_u_long(mp_perfdata, unsigned long); mp_perfdata mp_set_pd_value_long_long(mp_perfdata, long long); mp_perfdata mp_set_pd_value_u_long_long(mp_perfdata, unsigned long long); -#define mp_create_pd_value(V) \ - _Generic((V), \ - float: mp_create_pd_value_float, \ - double: mp_create_pd_value_double, \ - char: mp_create_pd_value_char, \ - unsigned char: mp_create_pd_value_u_char, \ - int: mp_create_pd_value_int, \ - unsigned int: mp_create_pd_value_u_int, \ - long: mp_create_pd_value_long, \ - unsigned long: mp_create_pd_value_u_long, \ - long long: mp_create_pd_value_long_long, \ +#define mp_create_pd_value(V) \ + _Generic((V), \ + float: mp_create_pd_value_float, \ + double: mp_create_pd_value_double, \ + char: mp_create_pd_value_char, \ + unsigned char: mp_create_pd_value_u_char, \ + int: mp_create_pd_value_int, \ + unsigned int: mp_create_pd_value_u_int, \ + long: mp_create_pd_value_long, \ + unsigned long: mp_create_pd_value_u_long, \ + long long: mp_create_pd_value_long_long, \ unsigned long long: mp_create_pd_value_u_long_long)(V) mp_perfdata_value mp_create_pd_value_float(float); diff --git a/lib/thresholds.h b/lib/thresholds.h index 5f9f9247..f8647681 100644 --- a/lib/thresholds.h +++ b/lib/thresholds.h @@ -6,12 +6,12 @@ /* * Old threshold type using the old range type */ -typedef struct thresholds_struct { +typedef struct { range *warning; range *critical; } thresholds; -typedef struct mp_thresholds_struct { +typedef struct { bool warning_is_set; mp_range warning; bool critical_is_set; -- cgit v1.2.3-74-g34f1