summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-09-15 10:13:33 +0200
committerGitHub <noreply@github.com>2025-09-15 10:13:33 +0200
commita3cf9041af810770daf5d9b83f1906fa9bb0dd11 (patch)
tree9b9b45a6a611c4f37cf5dd447b37f74e48d56c14 /lib
parentf69aba3129d672b88f5bae187fb971fc0ac228ed (diff)
parent5a2c1b2c3aeb99e7a703b0c5f6fe1a21d29b3be4 (diff)
downloadmonitoring-plugins-a3cf9041af810770daf5d9b83f1906fa9bb0dd11.tar.gz
Merge pull request #2085 from RincewindsHat/refactor/check_curl
Refactor/check curl and introduce new output formatting
Diffstat (limited to 'lib')
-rw-r--r--lib/perfdata.h46
-rw-r--r--lib/thresholds.h4
-rw-r--r--lib/utils_base.c9
-rw-r--r--lib/utils_base.h5
4 files changed, 33 insertions, 31 deletions
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 {
28/* 28/*
29 * New range type with generic numerical values 29 * New range type with generic numerical values
30 */ 30 */
31typedef struct mp_range_struct { 31typedef struct {
32 mp_perfdata_value start; 32 mp_perfdata_value start;
33 bool start_infinity; /* false (default) or true */ 33 bool start_infinity; /* false (default) or true */
34 34
@@ -41,7 +41,7 @@ typedef struct mp_range_struct {
41/* 41/*
42 * Old range type with floating point values 42 * Old range type with floating point values
43 */ 43 */
44typedef struct range_struct { 44typedef struct {
45 double start; 45 double start;
46 bool start_infinity; 46 bool start_infinity;
47 double end; 47 double end;
@@ -53,7 +53,7 @@ typedef struct range_struct {
53/* 53/*
54 * Perfdata type for storing perfdata output 54 * Perfdata type for storing perfdata output
55 */ 55 */
56typedef struct perfdata_struct { 56typedef struct {
57 char *label; 57 char *label;
58 char *uom; 58 char *uom;
59 mp_perfdata_value value; 59 mp_perfdata_value value;
@@ -131,15 +131,15 @@ mp_range_parsed mp_parse_range_string(const char * /*input*/);
131 */ 131 */
132void pd_list_append(pd_list[1], mp_perfdata); 132void pd_list_append(pd_list[1], mp_perfdata);
133 133
134#define mp_set_pd_value(P, V) \ 134#define mp_set_pd_value(P, V) \
135 _Generic((V), \ 135 _Generic((V), \
136 float: mp_set_pd_value_float, \ 136 float: mp_set_pd_value_float, \
137 double: mp_set_pd_value_double, \ 137 double: mp_set_pd_value_double, \
138 int: mp_set_pd_value_int, \ 138 int: mp_set_pd_value_int, \
139 unsigned int: mp_set_pd_value_u_int, \ 139 unsigned int: mp_set_pd_value_u_int, \
140 long: mp_set_pd_value_long, \ 140 long: mp_set_pd_value_long, \
141 unsigned long: mp_set_pd_value_u_long, \ 141 unsigned long: mp_set_pd_value_u_long, \
142 long long: mp_set_pd_value_long_long, \ 142 long long: mp_set_pd_value_long_long, \
143 unsigned long long: mp_set_pd_value_u_long_long)(P, V) 143 unsigned long long: mp_set_pd_value_u_long_long)(P, V)
144 144
145mp_perfdata mp_set_pd_value_float(mp_perfdata, float); 145mp_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);
151mp_perfdata mp_set_pd_value_long_long(mp_perfdata, long long); 151mp_perfdata mp_set_pd_value_long_long(mp_perfdata, long long);
152mp_perfdata mp_set_pd_value_u_long_long(mp_perfdata, unsigned long long); 152mp_perfdata mp_set_pd_value_u_long_long(mp_perfdata, unsigned long long);
153 153
154#define mp_create_pd_value(V) \ 154#define mp_create_pd_value(V) \
155 _Generic((V), \ 155 _Generic((V), \
156 float: mp_create_pd_value_float, \ 156 float: mp_create_pd_value_float, \
157 double: mp_create_pd_value_double, \ 157 double: mp_create_pd_value_double, \
158 char: mp_create_pd_value_char, \ 158 char: mp_create_pd_value_char, \
159 unsigned char: mp_create_pd_value_u_char, \ 159 unsigned char: mp_create_pd_value_u_char, \
160 int: mp_create_pd_value_int, \ 160 int: mp_create_pd_value_int, \
161 unsigned int: mp_create_pd_value_u_int, \ 161 unsigned int: mp_create_pd_value_u_int, \
162 long: mp_create_pd_value_long, \ 162 long: mp_create_pd_value_long, \
163 unsigned long: mp_create_pd_value_u_long, \ 163 unsigned long: mp_create_pd_value_u_long, \
164 long long: mp_create_pd_value_long_long, \ 164 long long: mp_create_pd_value_long_long, \
165 unsigned long long: mp_create_pd_value_u_long_long)(V) 165 unsigned long long: mp_create_pd_value_u_long_long)(V)
166 166
167mp_perfdata_value mp_create_pd_value_float(float); 167mp_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 @@
6/* 6/*
7 * Old threshold type using the old range type 7 * Old threshold type using the old range type
8 */ 8 */
9typedef struct thresholds_struct { 9typedef struct {
10 range *warning; 10 range *warning;
11 range *critical; 11 range *critical;
12} thresholds; 12} thresholds;
13 13
14typedef struct mp_thresholds_struct { 14typedef struct {
15 bool warning_is_set; 15 bool warning_is_set;
16 mp_range warning; 16 mp_range warning;
17 bool critical_is_set; 17 bool critical_is_set;
diff --git a/lib/utils_base.c b/lib/utils_base.c
index 29b393d0..e95eeaf0 100644
--- a/lib/utils_base.c
+++ b/lib/utils_base.c
@@ -25,6 +25,7 @@
25 *****************************************************************************/ 25 *****************************************************************************/
26 26
27#include "../plugins/common.h" 27#include "../plugins/common.h"
28#include "states.h"
28#include <stdarg.h> 29#include <stdarg.h>
29#include "utils_base.h" 30#include "utils_base.h"
30#include <ctype.h> 31#include <ctype.h>
@@ -253,7 +254,7 @@ bool check_range(double value, range *my_range) {
253 yes = false; 254 yes = false;
254 } 255 }
255 256
256 if (!my_range->end_infinity && !my_range->start_infinity) { 257 if (!my_range->end_infinity&& !my_range->start_infinity) {
257 if ((my_range->start <= value) && (value <= my_range->end)) { 258 if ((my_range->start <= value) && (value <= my_range->end)) {
258 return no; 259 return no;
259 } 260 }
@@ -267,7 +268,7 @@ bool check_range(double value, range *my_range) {
267 return yes; 268 return yes;
268 } 269 }
269 270
270 if (my_range->start_infinity && !my_range->end_infinity) { 271 if (my_range->start_infinity && !my_range->end_infinity ) {
271 if (value <= my_range->end) { 272 if (value <= my_range->end) {
272 return no; 273 return no;
273 } 274 }
@@ -277,7 +278,7 @@ bool check_range(double value, range *my_range) {
277} 278}
278 279
279/* Returns status */ 280/* Returns status */
280int get_status(double value, thresholds *my_thresholds) { 281mp_state_enum get_status(double value, thresholds *my_thresholds) {
281 if (my_thresholds->critical != NULL) { 282 if (my_thresholds->critical != NULL) {
282 if (check_range(value, my_thresholds->critical)) { 283 if (check_range(value, my_thresholds->critical)) {
283 return STATE_CRITICAL; 284 return STATE_CRITICAL;
@@ -393,7 +394,7 @@ char *np_extract_value(const char *varlist, const char *name, char sep) {
393 return value; 394 return value;
394} 395}
395 396
396const char *state_text(int result) { 397const char *state_text(mp_state_enum result) {
397 switch (result) { 398 switch (result) {
398 case STATE_OK: 399 case STATE_OK:
399 return "OK"; 400 return "OK";
diff --git a/lib/utils_base.h b/lib/utils_base.h
index f1c99a54..f31299c4 100644
--- a/lib/utils_base.h
+++ b/lib/utils_base.h
@@ -7,6 +7,7 @@
7 7
8#include "./perfdata.h" 8#include "./perfdata.h"
9#include "./thresholds.h" 9#include "./thresholds.h"
10#include "states.h"
10 11
11#ifndef USE_OPENSSL 12#ifndef USE_OPENSSL
12# include "sha256.h" 13# include "sha256.h"
@@ -37,7 +38,7 @@ void set_thresholds(thresholds **, char *, char *);
37void print_thresholds(const char *, thresholds *); 38void print_thresholds(const char *, thresholds *);
38bool check_range(double, range *); 39bool check_range(double, range *);
39bool mp_check_range(mp_perfdata_value, mp_range); 40bool mp_check_range(mp_perfdata_value, mp_range);
40int get_status(double, thresholds *); 41mp_state_enum get_status(double, thresholds *);
41 42
42/* Handle timeouts */ 43/* Handle timeouts */
43extern int timeout_state; 44extern int timeout_state;
@@ -85,6 +86,6 @@ int mp_translate_state(char *);
85void np_init(char *, int argc, char **argv); 86void np_init(char *, int argc, char **argv);
86void np_set_args(int argc, char **argv); 87void np_set_args(int argc, char **argv);
87void np_cleanup(void); 88void np_cleanup(void);
88const char *state_text(int); 89const char *state_text(mp_state_enum);
89 90
90#endif /* _UTILS_BASE_ */ 91#endif /* _UTILS_BASE_ */