From 2e8bcb630dddaf0907268f05c9d165c8891de507 Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Sat, 9 May 2026 06:53:41 -0400 Subject: [PATCH] fix: show human-readable duration in re-notification messages Replace raw seconds with d h m s format in "ongoing for ..." strings. Co-Authored-By: Claude Sonnet 4.6 --- hbd/server/threshold.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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