fix(server): honour the legacy thresholds: config; repair the stale test suite

Since the built-in defaults were seeded into threshold_configs, the legacy
top-level thresholds: format was silently ignored. get_thresholds_for_host
now uses it whenever it was configured.

Tests: point imports at hbd.server/hbd.common, rewrite the DNS worker,
proto, datagram and threshold tests for the current API, add pytest-asyncio
to the dev extras and set testpaths so a bare pytest runs cleanly.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-28 04:53:43 -04:00
co-authored by Claude Sonnet 5.5
parent 952adb68f8
commit 85c6a4eebe
8 changed files with 78 additions and 120 deletions
+15 -10
View File
@@ -19,7 +19,7 @@ from pathlib import Path
# Add parent directory to path for imports
sys.path.insert(0, str(Path(__file__).parent.parent))
from hbd.threshold import (
from hbd.server.threshold import (
ThresholdChecker,
ThresholdConfig,
AlertLevel,
@@ -257,7 +257,16 @@ def test_threshold_checker_parsing():
print(f" ✓ Parsed {len(checker.thresholds)} thresholds correctly")
def test_check_plugin_data():
def _checker_with_notifications(config, notifications, monkeypatch):
"""ThresholdChecker with no grace period that records notifications instead of sending them."""
monkeypatch.setattr(
ThresholdChecker, "_send_notification",
lambda self, host, lvl, message, *a: notifications.append(f"[{lvl}] {host} {message}"),
)
return ThresholdChecker({"grace": 0, **config})
def test_check_plugin_data(monkeypatch):
"""Test checking plugin data against thresholds."""
print("\nTest 6: Plugin data checking...")
@@ -277,11 +286,7 @@ def test_check_plugin_data():
}
notifications = []
def notification_callback(msg):
notifications.append(msg)
checker = ThresholdChecker(config, notification_callback=notification_callback)
checker = _checker_with_notifications(config, notifications, monkeypatch)
alert_states = {}
# First check - OK
@@ -353,12 +358,12 @@ def test_check_plugin_data():
assert len(state_changes) == 2, "Two metrics should recover"
assert len(notifications) == 2, "Two recovery notifications"
assert any("RECOVERED" in n for n in notifications), "Should have recovery notification"
assert any("RECOVER" in n for n in notifications), "Should have recovery notification"
print(" ✓ Plugin data checking and notifications work")
def test_nested_metrics():
def test_nested_metrics(monkeypatch):
"""Test checking nested metrics like disk partitions."""
print("\nTest 7: Nested metrics (partitions)...")
@@ -384,7 +389,7 @@ def test_nested_metrics():
}
notifications = []
checker = ThresholdChecker(config, notification_callback=lambda m: notifications.append(m))
checker = _checker_with_notifications(config, notifications, monkeypatch)
alert_states = {}
plugin_data = {