diff options
Diffstat (limited to 'lib/thresholds.c')
| -rw-r--r-- | lib/thresholds.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/lib/thresholds.c b/lib/thresholds.c new file mode 100644 index 00000000..de2b9315 --- /dev/null +++ b/lib/thresholds.c | |||
| @@ -0,0 +1,71 @@ | |||
| 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_WARNING; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | return STATE_OK; | ||
| 59 | } | ||
| 60 | |||
| 61 | mp_thresholds mp_thresholds_set_warn(mp_thresholds thlds, mp_range warn) { | ||
| 62 | thlds.warning = warn; | ||
| 63 | thlds.warning_is_set = true; | ||
| 64 | return thlds; | ||
| 65 | } | ||
| 66 | |||
| 67 | mp_thresholds mp_thresholds_set_crit(mp_thresholds thlds, mp_range crit) { | ||
| 68 | thlds.critical = crit; | ||
| 69 | thlds.critical_is_set = true; | ||
| 70 | return thlds; | ||
| 71 | } | ||
