From ae2d085214bbe5c41b50cea8c1eb993806bf76d8 Mon Sep 17 00:00:00 2001 From: benya Date: Sun, 8 Feb 2026 18:51:45 +0300 Subject: [PATCH] Allow critical-only load alerts --- CONFIG.en.md | 1 + CONFIG.md | 1 + config.example.yaml | 2 ++ services/alerts.py | 5 ++++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CONFIG.en.md b/CONFIG.en.md index a991ba9..64f9075 100644 --- a/CONFIG.en.md +++ b/CONFIG.en.md @@ -24,6 +24,7 @@ This project uses `config.yaml`. Start from `config.example.yaml`. - `interval_sec` (int): Poll interval. - `cooldown_sec` (int): Cooldown between alerts. - `notify_cooldown_sec` (int): Global alert dedup cooldown (defaults to `cooldown_sec`). +- `load_only_critical` (bool): Only send critical load alerts (no warn/OK). - `quiet_hours` (object): Quiet hours for non‑critical alerts. - `enabled` (bool): Enable quiet hours. - `start` (string): Start time `HH:MM` (e.g. `23:00`). diff --git a/CONFIG.md b/CONFIG.md index 98ad097..7907570 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -24,6 +24,7 @@ - `interval_sec` (int): интервал опроса. - `cooldown_sec` (int): кулдаун между алертами. - `notify_cooldown_sec` (int): глобальный дедуп алертов (по умолчанию `cooldown_sec`). +- `load_only_critical` (bool): слать только критичные алерты по нагрузке (без warn/OK). - `quiet_hours` (object): тихие часы для не‑критичных уведомлений. - `enabled` (bool): включить тихие часы. - `start` (string): начало, формат `HH:MM` (например `23:00`). diff --git a/config.example.yaml b/config.example.yaml index bc8e4d0..9dd6100 100644 --- a/config.example.yaml +++ b/config.example.yaml @@ -19,6 +19,8 @@ alerts: cooldown_sec: 900 # Optional global dedup cooldown for notify() calls notify_cooldown_sec: 900 + # If true, only critical load alerts are sent (no warn/OK) + load_only_critical: false quiet_hours: enabled: false start: "23:00" diff --git a/services/alerts.py b/services/alerts.py index f95eb9b..f4f2298 100644 --- a/services/alerts.py +++ b/services/alerts.py @@ -11,6 +11,7 @@ async def monitor_resources(cfg, notify, bot, chat_id): interval = int(alerts_cfg.get("interval_sec", 60)) cooldown = int(alerts_cfg.get("cooldown_sec", 900)) notify_recovery = bool(alerts_cfg.get("notify_recovery", True)) + load_only_critical = bool(alerts_cfg.get("load_only_critical", False)) disk_warn = int(cfg.get("thresholds", {}).get("disk_warn", 80)) snapshot_warn = int(cfg.get("disk_report", {}).get("threshold", disk_warn)) @@ -57,9 +58,11 @@ async def monitor_resources(cfg, notify, bot, chat_id): level = 1 else: level = 0 + if load_only_critical and level == 1: + level = 0 if level == 0: - if state["load_level"] > 0 and notify_recovery: + if state["load_level"] > 0 and notify_recovery and not load_only_critical: await notify(bot, chat_id, f"🟢 Load OK: {load:.2f}", level="info", key="load_ok") state["load_level"] = 0 else: