fix: host_silence proactive notify when event is None
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -114,6 +114,13 @@ def dispatch_host_silence_notifications(db: Session, results: list[HostSilenceSc
|
|||||||
for item in results:
|
for item in results:
|
||||||
if not item.created:
|
if not item.created:
|
||||||
continue
|
continue
|
||||||
notify_problem(item.problem, event=None, db=db)
|
try:
|
||||||
sent += 1
|
notify_problem(item.problem, event=None, db=db)
|
||||||
|
sent += 1
|
||||||
|
except Exception:
|
||||||
|
logger.exception(
|
||||||
|
"host_silence notify failed host=%s problem_id=%s",
|
||||||
|
item.hostname,
|
||||||
|
item.problem.id,
|
||||||
|
)
|
||||||
return sent
|
return sent
|
||||||
|
|||||||
@@ -543,8 +543,6 @@ def format_problem_telegram_html(problem: Problem, event: Event | None = None) -
|
|||||||
msg += f"\n<b>{html_escape(problem.title)}</b>\n{html_escape(problem.summary)}"
|
msg += f"\n<b>{html_escape(problem.title)}</b>\n{html_escape(problem.summary)}"
|
||||||
if event is not None:
|
if event is not None:
|
||||||
msg += f"\n\n<i>Триггер:</i> {html_escape(event.type)} ({html_escape(event.severity)})"
|
msg += f"\n\n<i>Триггер:</i> {html_escape(event.type)} ({html_escape(event.severity)})"
|
||||||
elif problem.rule_id == "rule:host_silence":
|
|
||||||
msg += "\n\n<i>Триггер:</i> периодическая проверка SAC (host_silence scan)"
|
|
||||||
if event.type in (
|
if event.type in (
|
||||||
"rdp.login.success",
|
"rdp.login.success",
|
||||||
"rdp.login.failed",
|
"rdp.login.failed",
|
||||||
@@ -557,4 +555,6 @@ def format_problem_telegram_html(problem: Problem, event: Event | None = None) -
|
|||||||
"smb.admin_share.access",
|
"smb.admin_share.access",
|
||||||
):
|
):
|
||||||
msg += "\n" + _format_event_body_html(event)
|
msg += "\n" + _format_event_body_html(event)
|
||||||
|
elif problem.rule_id == "rule:host_silence":
|
||||||
|
msg += "\n\n<i>Триггер:</i> периодическая проверка SAC (host_silence scan)"
|
||||||
return append_notification_source_html(msg, generated_by="sac")
|
return append_notification_source_html(msg, generated_by="sac")
|
||||||
|
|||||||
@@ -326,3 +326,32 @@ def test_agent_inventory_hardware_change_template():
|
|||||||
assert "железо" in text.lower() or "Изменилось" in text
|
assert "железо" in text.lower() or "Изменилось" in text
|
||||||
assert "memory_gb" in text
|
assert "memory_gb" in text
|
||||||
assert "32" in text
|
assert "32" in text
|
||||||
|
|
||||||
|
|
||||||
|
def test_format_problem_host_silence_scan_without_event():
|
||||||
|
from app.models import Host, Problem
|
||||||
|
from app.services.problem_rules import RULE_HOST_SILENCE
|
||||||
|
from app.services.telegram_templates import format_problem_telegram_html
|
||||||
|
|
||||||
|
host = Host(
|
||||||
|
hostname="YURKOV-PC",
|
||||||
|
os_family="windows",
|
||||||
|
product="rdp-login-monitor",
|
||||||
|
last_seen_at=datetime(2026, 6, 11, 9, 0, tzinfo=timezone.utc),
|
||||||
|
)
|
||||||
|
problem = Problem(
|
||||||
|
host_id=1,
|
||||||
|
host=host,
|
||||||
|
title="Host silence: YURKOV-PC",
|
||||||
|
summary="Нет свежего agent.heartbeat более 300 мин",
|
||||||
|
severity="high",
|
||||||
|
status="open",
|
||||||
|
rule_id=RULE_HOST_SILENCE,
|
||||||
|
fingerprint="fp-silence",
|
||||||
|
event_count=0,
|
||||||
|
last_seen_at=datetime(2026, 6, 11, 9, 0, tzinfo=timezone.utc),
|
||||||
|
)
|
||||||
|
text = format_problem_telegram_html(problem, event=None)
|
||||||
|
assert "периодическая проверка SAC" in text
|
||||||
|
assert "host_silence scan" in text
|
||||||
|
assert "YURKOV-PC" in text or "UNMS" not in text # host label uses hostname
|
||||||
|
|||||||
Reference in New Issue
Block a user