fix: normalize daily report layout for Telegram and UI

Ensure server line, compact spacing, and one user per row when ingesting
agent reports or sending SAC-generated daily reports.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
PTah
2026-05-30 09:52:09 +10:00
parent eba2f0d15c
commit 2501ecc4fe
6 changed files with 223 additions and 22 deletions
+17 -3
View File
@@ -8,6 +8,7 @@ from datetime import datetime
from typing import Any
from app.models import Event, Host, Problem
from app.services.daily_report_format import normalize_report_body
LOGON_TYPE_NAMES: dict[int, str] = {
2: "Интерактивный (консоль)",
@@ -181,13 +182,26 @@ def format_generic_event_html(event: Event) -> str:
def format_daily_report_html(event: Event) -> str:
details = _details_dict(event)
platform = "windows" if event.type == "report.daily.rdp" else "ssh"
body = _detail(details, "report_body", default="")
if body and body != "-":
body = normalize_report_body(body, event.host, platform)
parts: list[str] = []
for i, line in enumerate(body.split("\n")):
esc = html.escape(line)
if i == 0 and "ЕЖЕДНЕВНЫЙ ОТЧЕТ" in line:
parts.append(f"<b>{esc.strip()}</b>")
else:
parts.append(esc)
return "\n".join(parts)
report_html = details.get("report_html")
if isinstance(report_html, str) and report_html.strip():
return sanitize_telegram_html(report_html.strip())
text = sanitize_telegram_html(report_html.strip())
return re.sub(r"\n{3,}", "\n\n", text)
body = _detail(details, "report_body", default=event.summary)
if body != "-":
escaped = html.escape(body)
return f"<b>📊 {html_escape(event.title)}</b>\n{escaped}"
return html.escape(body)
return format_generic_event_html(event)