From 7bab15ae52a62389c728991cd971ffa4e15d8d78 Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Sat, 6 Jun 2026 09:00:09 -0400 Subject: [PATCH] fix: don't set stale timer until two plugin samples establish real interval MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoids false-stale firing for slow plugins (e.g. nagios_runner at 300 s) when the heartbeat interval is much shorter. On the first sample cancel any leftover timer; arm the 3× stale timer only after the second sample. Co-Authored-By: Claude Sonnet 4.6 --- hbd/server/udp.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/hbd/server/udp.py b/hbd/server/udp.py index 20cf4bf..831948e 100644 --- a/hbd/server/udp.py +++ b/hbd/server/udp.py @@ -389,10 +389,17 @@ def handle_datagram(msg: dict, addr, transport, ctx: dict): if k not in ("ID", "plugin", "id", "name")} # Store plugin data with timestamp host.add_plugin_data(plugin_name, plugin_data, timestamp=now) - # Reset stale timer — 3× the heartbeat interval (min 60 s) - stale_timeout = max(host.interval * 3, 60) - host.reset_plugin_timer(plugin_name, stale_timeout, - _make_plugin_stale_callback(uname, ctx)) + # Reset stale timer using the observed send interval for this plugin. + # We need two samples to know the real interval; on the first sample + # we cancel any leftover timer but don't set a new one, to avoid + # false-stale firing for slow plugins (e.g. nagios_runner at 300 s). + history = host.plugin_data.get(plugin_name, []) + if len(history) >= 2: + 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)) + else: + host.cancel_plugin_timer(plugin_name) # If os_info reports an owner and none is configured server-side, apply it if plugin_name == "os_info":