From b0addd7c6780f09a743bc78e6b9a5b5205ae5796 Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Sat, 6 Jun 2026 11:32:38 -0400 Subject: [PATCH] feat: clear alerts for individual plugin metrics that disappear between samples When a PLG message arrives with fewer keys than the previous sample, alert states for the missing metrics are removed immediately. Handles nagios checks removed from configuration while the runner plugin continues. Co-Authored-By: Claude Sonnet 4.6 --- hbd/server/udp.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hbd/server/udp.py b/hbd/server/udp.py index 831948e..4cc359e 100644 --- a/hbd/server/udp.py +++ b/hbd/server/udp.py @@ -398,6 +398,16 @@ def handle_datagram(msg: dict, addr, transport, ctx: dict): plugin_interval = max(history[-1][0] - history[-2][0], 1) host.reset_plugin_timer(plugin_name, plugin_interval * 3, _make_plugin_stale_callback(uname, ctx)) + # Remove alert states for metrics present in the previous sample + # but absent now (e.g. a nagios check removed from configuration). + prev_keys = set(history[-2][1].keys()) + curr_keys = set(plugin_data.keys()) + for metric_name in prev_keys - curr_keys: + metric_path = f"{plugin_name}.{metric_name}" + if host.alert_states.pop(metric_path, None) is not None: + eventlog(uname, "INFO", f"stale check removed: {metric_path}") + if (prev_keys - curr_keys) and msg_to_websockets: + msg_to_websockets("host", host.stateinfo()) else: host.cancel_plugin_timer(plugin_name)