From 1ddc4b8132b430c22a01b91ed5e3cbb5f996d3da Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Fri, 8 May 2026 06:19:16 -0400 Subject: [PATCH] threshold/alerts: strip _status_code suffix from displayed metric names Co-Authored-By: Claude Sonnet 4.6 --- hbd/server/templates/alerts.html | 2 +- hbd/server/threshold.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hbd/server/templates/alerts.html b/hbd/server/templates/alerts.html index 8b0da0c..bde9af7 100644 --- a/hbd/server/templates/alerts.html +++ b/hbd/server/templates/alerts.html @@ -438,7 +438,7 @@
${alert.level} ${alert.hostname} - ${alert.metric_path.includes('.') ? alert.metric_path.slice(alert.metric_path.indexOf('.') + 1) : alert.metric_path} + ${(alert.metric_path.includes('.') ? alert.metric_path.slice(alert.metric_path.indexOf('.') + 1) : alert.metric_path).replace(/_status_code$/, '')}
${valueText} diff --git a/hbd/server/threshold.py b/hbd/server/threshold.py index 2be4588..11d79a3 100644 --- a/hbd/server/threshold.py +++ b/hbd/server/threshold.py @@ -1044,8 +1044,8 @@ class ThresholdChecker: # Format operator symbol op_symbol = threshold.operator.value - # Short metric label: strip the plugin-name prefix for readability - short_path = metric_path.partition(".")[2] or metric_path + # Short metric label: strip the plugin-name prefix and _status_code suffix + short_path = (metric_path.partition(".")[2] or metric_path).removesuffix("_status_code") # Use a display-friendly value (inf is the sentinel for "overdue") import math @@ -1109,7 +1109,7 @@ class ThresholdChecker: if host is not None and not host.watched: eventlog(host_name, lvl, message, service="threshold") return - short_path = metric_path.partition(".")[2] or metric_path + short_path = (metric_path.partition(".")[2] or metric_path).removesuffix("_status_code") title = f"[{lvl}] {host_name} {short_path}" # Strip the "metric = " prefix from message so body is just the value/detail prefix = short_path + " = " @@ -1349,7 +1349,7 @@ class ThresholdChecker: # Format operator symbol op_symbol = threshold.operator.value - short_path = metric_path.partition(".")[2] or metric_path + short_path = (metric_path.partition(".")[2] or metric_path).removesuffix("_status_code") # Time to re-notify if threshold_value is not None: