feat: unify SSH and Windows daily report layout in SAC and UI

Agent-style report body for SAC aggregation; shared stats cards; RDP ban note in docs

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
PTah
2026-05-29 17:03:29 +10:00
parent 11195ae64f
commit 7ebbb9a9d1
8 changed files with 469 additions and 105 deletions
+63
View File
@@ -0,0 +1,63 @@
"""Unified daily report text format."""
from datetime import datetime, timezone
from app.models import Host
from app.services.daily_report_format import build_report_body, enrich_stats_for_storage
def test_build_report_body_ssh_matches_agent_layout():
host = Host(
hostname="haproxy",
display_name="HaProxy Kalina",
ipv4="192.168.160.117",
os_family="linux",
product="ssh-monitor",
)
when = datetime(2026, 5, 29, 9, 0, 5, tzinfo=timezone.utc)
stats = enrich_stats_for_storage(
"ssh",
{
"successful_ssh": 0,
"failed_ssh": 0,
"sudo_commands": 5,
"active_bans": 0,
"top_failed_ips": [],
"active_users": [
"👤 papatramp | pts/0 | с 2026-05-27 12:28 | 🌐 192.168.160.3",
],
},
)
body = build_report_body("ssh", host, stats, when, sac_generated=True)
assert "ЕЖЕДНЕВНЫЙ ОТЧЕТ SSH МОНИТОРИНГА" in body
assert "HaProxy Kalina (192.168.160.117)" in body
assert "Команд через sudo: 5" in body
assert "АКТИВНЫЕ ПОЛЬЗОВАТЕЛИ (1)" in body
assert "papatramp" in body
def test_build_report_body_windows_layout():
host = Host(
hostname="WIN01",
display_name="K6A-DC3",
ipv4="10.0.0.10",
os_family="windows",
product="rdp-login-monitor",
)
when = datetime(2026, 5, 29, 9, 0, 5, tzinfo=timezone.utc)
stats = enrich_stats_for_storage(
"windows",
{
"rdp_success": 1,
"rdp_failed": 2,
"active_bans": 0,
"top_failed_ips": ["1.2.3.4 — 2"],
"active_users": ["👤 DOMAIN\\user1", "👤 user2"],
},
)
body = build_report_body("windows", host, stats, when, sac_generated=True)
assert "ЕЖЕДНЕВНЫЙ ОТЧЕТ МОНИТОРИНГА WINDOWS" in body
assert "K6A-DC3 (10.0.0.10)" in body
assert "Успешных RDP подключений: 1" in body
assert "АКТИВНЫЕ ПОЛЬЗОВАТЕЛИ (2)" in body
assert "user2" in body