diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-02-21 14:33:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-21 14:33:24 +0100 |
commit | 75658bd04d84d037dbcc9fafd9f7860555ac4836 (patch) | |
tree | 6b50ee39401c68a27757abac785c931bd82ae02d /lib/thresholds.c | |
parent | b38dec3e9b45efa6a6631acc38ada853e69fc547 (diff) | |
parent | 7c8c9d9b3e7bb6c29d82788d05d74e3f18f01aa5 (diff) | |
download | monitoring-plugins-master.tar.gz |
Feature/new output infra
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 | } | ||