From 0645c9fc2c7f801ba3c7d68a17c137a63ada299f Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Tue, 18 Feb 2025 21:58:34 +0100 Subject: Implement new output functionality --- lib/thresholds.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 lib/thresholds.c (limited to 'lib/thresholds.c') 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 @@ +#include "./thresholds.h" +#include "./utils_base.h" +#include "perfdata.h" + +#include + +mp_thresholds mp_thresholds_init() { + mp_thresholds tmp = { + .critical = {}, + .critical_is_set = false, + .warning = {}, + .warning_is_set = false, + }; + return tmp; +} + +char *fmt_threshold_warning(const thresholds th) { + if (th.warning == NULL) { + return ""; + } + + return fmt_range(*th.warning); +} + +char *fmt_threshold_critical(const thresholds th) { + if (th.critical == NULL) { + return ""; + } + return fmt_range(*th.critical); +} + +mp_perfdata mp_pd_set_thresholds(mp_perfdata perfdata, mp_thresholds threshold) { + if (threshold.critical_is_set) { + perfdata.crit = threshold.critical; + perfdata.crit_present = true; + } + + if (threshold.warning_is_set) { + perfdata.warn = threshold.warning; + perfdata.warn_present = true; + } + + return perfdata; +} + +mp_state_enum mp_get_pd_status(mp_perfdata perfdata) { + if (perfdata.crit_present) { + if (mp_check_range(perfdata.value, perfdata.crit)) { + return STATE_CRITICAL; + } + } + if (perfdata.warn_present) { + if (mp_check_range(perfdata.value, perfdata.warn)) { + return STATE_CRITICAL; + } + } + + return STATE_OK; +} -- cgit v1.2.3-74-g34f1