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 <noreply@anthropic.com>
This commit is contained in:
+13
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user