Add incidents log and viewer

This commit is contained in:
2026-02-08 01:33:14 +03:00
parent 4eb202c2ed
commit 4e79c401a9
8 changed files with 804 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
import asyncio
import os
from aiogram import F
from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
from app import dp, cfg
@@ -14,6 +15,7 @@ import state
from state import UPDATES_CACHE, REBOOT_PENDING
from services.metrics import summarize
from services.audit import read_audit_tail
from services.incidents import read_recent, incidents_path
@dp.message(F.text == "💽 Disks")
@@ -80,6 +82,29 @@ async def audit_log(msg: Message):
await msg.answer(text, reply_markup=system_kb, parse_mode="Markdown")
@dp.message(F.text == "📣 Incidents")
async def incidents(msg: Message):
if not is_admin_msg(msg):
return
path = incidents_path(cfg)
if not os.path.exists(path):
await msg.answer("⚠️ Incidents log not found", reply_markup=system_kb)
return
last_24h = read_recent(cfg, hours=24, limit=500)
last_7d = read_recent(cfg, hours=24 * 7, limit=1000)
recent = last_24h[-30:] if last_24h else ["(no incidents)"]
body = "\n".join(recent)
text = (
"📣 Incidents\n\n"
f"Last 24h: {len(last_24h)}\n"
f"Last 7d: {len(last_7d)}\n\n"
"Recent (24h):\n"
f"```\n{body}\n```"
)
await msg.answer(text, reply_markup=system_kb, parse_mode="Markdown")
@dp.message(F.text == "🔒 SSL")
async def ssl_certs(msg: Message):
if not is_admin_msg(msg):