Files
Nexus/tests/test_fleet_alert_buckets.py
T
Nexus Agent 7209f53af9 feat: 子机离线 Telegram 告警与仪表盘统计/趋势增强
离线边沿检测推送一次 Telegram(设置开关 notify_alert_offline);对齐仪表盘与服务器页统计卡、舰队趋势交互与告警叠加。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-09 17:16:48 +08:00

32 lines
1.1 KiB
Python

"""Fleet trend alert window bucketing."""
from datetime import datetime, timezone
from server.utils.fleet_alert_buckets import attach_alerts_to_fleet_points
class _Alert:
def __init__(self, created_at, **kwargs):
self.created_at = created_at
self.server_name = kwargs.get("server_name", "srv")
self.server_id = kwargs.get("server_id", 1)
self.alert_type = kwargs.get("alert_type", "cpu")
self.value = kwargs.get("value", "90")
self.is_recovery = kwargs.get("is_recovery", False)
def test_attach_alerts_to_sample_window():
points = [
{"recorded_at": "2026-06-09 10:00:00", "cpu_avg": 10},
{"recorded_at": "2026-06-09 10:10:00", "cpu_avg": 20},
]
alerts = [
_Alert(datetime(2026, 6, 9, 10, 5, tzinfo=timezone.utc), alert_type="cpu"),
_Alert(datetime(2026, 6, 9, 10, 8, tzinfo=timezone.utc), alert_type="mem"),
]
out = attach_alerts_to_fleet_points(points, alerts, interval_minutes=10)
assert out[0]["alert_count"] == 0
assert out[1]["alert_count"] == 2
types = {a["alert_type"] for a in out[1]["alerts"]}
assert types == {"cpu", "mem"}