diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-02-18 21:58:34 +0100 |
---|---|---|
committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-02-18 21:58:34 +0100 |
commit | 0645c9fc2c7f801ba3c7d68a17c137a63ada299f (patch) | |
tree | ce222906f546f03301defba9ce81ba57591a8eb3 /lib/thresholds.c | |
parent | 39680498ee0987a5e0eb203a2c0539aa1fa94d39 (diff) | |
download | monitoring-plugins-0645c9fc2c7f801ba3c7d68a17c137a63ada299f.tar.gz |
Implement new output functionality
Diffstat (limited to 'lib/thresholds.c')
-rw-r--r-- | lib/thresholds.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/thresholds.c b/lib/thresholds.c new file mode 100644 index 00000000..ddefae37 --- /dev/null +++ b/lib/thresholds.c | |||
@@ -0,0 +1,59 @@ | |||
1 | #include "./thresholds.h" | ||
2 | #include "./utils_base.h" | ||
3 | #include "perfdata.h" | ||
4 | |||
5 | #include <stddef.h> | ||
6 | |||
7 | mp_thresholds mp_thresholds_init() { | ||
8 | mp_thresholds tmp = { | ||
9 | .critical = {}, | ||
10 | .critical_is_set = false, | ||
11 | .warning = {}, | ||
12 | .warning_is_set = false, | ||
13 | }; | ||
14 | return tmp; | ||
15 | } | ||
16 | |||
17 | char *fmt_threshold_warning(const thresholds th) { | ||
18 | if (th.warning == NULL) { | ||
19 | return ""; | ||
20 | } | ||
21 | |||
22 | return fmt_range(*th.warning); | ||
23 | } | ||
24 | |||
25 | char *fmt_threshold_critical(const thresholds th) { | ||
26 | if (th.critical == NULL) { | ||
27 | return ""; | ||
28 | } | ||
29 | return fmt_range(*th.critical); | ||
30 | } | ||
31 | |||
32 | mp_perfdata mp_pd_set_thresholds(mp_perfdata perfdata, mp_thresholds threshold) { | ||
33 | if (threshold.critical_is_set) { | ||
34 | perfdata.crit = threshold.critical; | ||
35 | perfdata.crit_present = true; | ||
36 | } | ||
37 | |||
38 | if (threshold.warning_is_set) { | ||
39 | perfdata.warn = threshold.warning; | ||
40 | perfdata.warn_present = true; | ||
41 | } | ||
42 | |||
43 | return perfdata; | ||
44 | } | ||
45 | |||
46 | mp_state_enum mp_get_pd_status(mp_perfdata perfdata) { | ||
47 | if (perfdata.crit_present) { | ||
48 | if (mp_check_range(perfdata.value, perfdata.crit)) { | ||
49 | return STATE_CRITICAL; | ||
50 | } | ||
51 | } | ||
52 | if (perfdata.warn_present) { | ||
53 | if (mp_check_range(perfdata.value, perfdata.warn)) { | ||
54 | return STATE_CRITICAL; | ||
55 | } | ||
56 | } | ||
57 | |||
58 | return STATE_OK; | ||
59 | } | ||