diff --git a/hbd/server/threshold.py b/hbd/server/threshold.py index 81d37dc..19cc78a 100644 --- a/hbd/server/threshold.py +++ b/hbd/server/threshold.py @@ -1393,6 +1393,17 @@ class ThresholdChecker: else: self._check_renotify(host_name, alert_state, metric_path, value, threshold, plugin_data, check_name=check_name, metric_name=metric_name) + @staticmethod + def _human_duration(seconds: float) -> str: + s = int(seconds) + if s < 120: + return f"{s}s" + if s < 3600: + return f"{s // 60}m {s % 60}s" + h, rem = divmod(s, 3600) + m = rem // 60 + return f"{h}h {m}m" if m else f"{h}h" + def _check_renotify( self, host_name: str, @@ -1454,9 +1465,9 @@ class ThresholdChecker: check_name=check_name, metric_name=metric_name, ) - body = f"{value} {threshold_info}, ongoing for {int(now - alert_state.since)}s" + body = f"{value} {threshold_info}, ongoing for {self._human_duration(now - alert_state.since)}" else: - body = f"{value} (ongoing for {int(now - alert_state.since)}s)" + body = f"{value} (ongoing for {self._human_duration(now - alert_state.since)})" message = f"REMINDER ({alert_state.level.name}): {host_name} - {short_path} = {body}" from . import hbdclass