From 0770abf2e05854e4ecc78984cba69936ac874658 Mon Sep 17 00:00:00 2001 From: "Daniele Verducci (Slimpenguin)" Date: Thu, 21 Dec 2023 08:13:07 +0100 Subject: [PATCH] WIP implementing flapping avoidance --- healthcheck/healthcheck.cfg.example | 8 ++++++++ healthcheck/healthcheck.py | 11 +++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/healthcheck/healthcheck.cfg.example b/healthcheck/healthcheck.cfg.example index a331901..835196e 100644 --- a/healthcheck/healthcheck.cfg.example +++ b/healthcheck/healthcheck.cfg.example @@ -80,6 +80,14 @@ NOTIFY_ALARM_END=TRUE # success result, error result, command failure. Then paste the command # and regex in this config, enable the check and run to verify is working. +#### AVOID FLAPPING #### +# For values slowly changing, like a server cabinet temperature, a lot of start/end alarm notifications +# may be generated if the value is near the limit (e.g. alarm set to 30, temperature jumping between 30.1 +# and 29.9). To avoid this, a "grace" delta can be set with: +# DELTA=0.5 +# In the previous example, this make the alarm fire at 30.5 and stop at 29.5. +# If not specified, the delta is 0. + [system_load_1min] # The system load average in the last minute diff --git a/healthcheck/healthcheck.py b/healthcheck/healthcheck.py index dd2d2f2..9bc7d32 100755 --- a/healthcheck/healthcheck.py +++ b/healthcheck/healthcheck.py @@ -169,13 +169,20 @@ class Main: # Compare detected value with equal, not equal, more than and less values logging.info('detected {}'.format(detectedValue)) + + # String comparison if config.alarm_string_equal and (detectedValue == config.alarm_string_equal): return 'value is "{}"'.format(detectedValue) if config.alarm_string_not_equal and (detectedValue != config.alarm_string_not_equal): return 'value is "{}", but should be "{}"'.format(detectedValue, config.alarm_string_not_equal) - if config.alarm_value_equal and (locale.atof(detectedValue) == float(config.alarm_value_equal)): + + # Numeric comparison + numeric_value = locale.atof(detectedValue) + delta_upper = numeric_value + config.delta + delta_lower = numeric_value - config.delta + if config.alarm_value_equal and (delta_lower < float(config.alarm_value_equal) or delta_upper > float(config.alarm_value_equal)): return 'value is {}'.format(detectedValue) - if config.alarm_value_not_equal and (locale.atof(detectedValue) != float(config.alarm_value_not_equal)): + if config.alarm_value_not_equal and (delta_lower > float(config.alarm_value_not_equal) or delta_upper < float(config.alarm_value_not_equal)): return 'value is {}, but should be {}'.format(detectedValue, config.alarm_value_not_equal) if config.alarm_value_more_than and locale.atof(detectedValue) > float(config.alarm_value_more_than): return 'value is {}, but should not exceed {}'.format(locale.atof(detectedValue), config.alarm_value_more_than)