Split Logs menu into subcategories

This commit is contained in:
2026-02-08 02:48:25 +03:00
parent 0f7f53cb27
commit fc061ece30
4 changed files with 98 additions and 33 deletions

View File

@@ -4,7 +4,13 @@ from aiogram import F
from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
from app import dp, cfg
from auth import is_admin_msg
from keyboards import system_info_kb, system_ops_kb, system_logs_kb
from keyboards import (
system_info_kb,
system_ops_kb,
system_logs_audit_kb,
system_logs_security_kb,
system_logs_integrations_kb,
)
from system_checks import security, disks, hardware, list_disks, smart_last_test
from services.http_checks import get_url_checks, check_url
from services.queue import enqueue
@@ -39,10 +45,10 @@ async def urls(msg: Message):
checks = list(get_url_checks(cfg))
if not checks:
await msg.answer("⚠️ Нет URL для проверки", reply_markup=system_logs_kb)
await msg.answer("⚠️ Нет URL для проверки", reply_markup=system_logs_security_kb)
return
await msg.answer("⏳ Проверяю URL…", reply_markup=system_logs_kb)
await msg.answer("⏳ Проверяю URL…", reply_markup=system_logs_security_kb)
async def worker():
tasks = [asyncio.to_thread(check_url, url) for _, url in checks]
@@ -58,7 +64,7 @@ async def urls(msg: Message):
reason = err or "error"
lines.append(f"🔴 {alias}: {reason} ({ms}ms)")
await msg.answer("\n".join(lines), reply_markup=system_logs_kb)
await msg.answer("\n".join(lines), reply_markup=system_logs_security_kb)
asyncio.create_task(worker())
@@ -68,7 +74,7 @@ async def ssh_log(msg: Message):
if not is_admin_msg(msg):
return
await msg.answer("⏳ Loading SSH logins…", reply_markup=system_logs_kb)
await msg.answer("⏳ Loading SSH logins…", reply_markup=system_logs_security_kb)
async def worker():
raw_lines: list[str] = []
@@ -98,13 +104,13 @@ async def ssh_log(msg: Message):
raw_lines.append(line)
if not raw_lines:
await msg.answer("🔑 SSH log\n\n(no logins today)", reply_markup=system_logs_kb)
await msg.answer("🔑 SSH log\n\n(no logins today)", reply_markup=system_logs_security_kb)
return
recent = raw_lines[-30:]
pretty = [_format_ssh_line(line) for line in recent]
text = "🔑 SSH logins (today)\n```\n" + "\n".join(pretty) + "\n```"
await msg.answer(text, reply_markup=system_logs_kb, parse_mode="Markdown")
await msg.answer(text, reply_markup=system_logs_security_kb, parse_mode="Markdown")
asyncio.create_task(worker())
@@ -194,16 +200,16 @@ async def audit_log(msg: Message):
return
text = read_audit_tail(cfg, limit=200)
if text.startswith("⚠️") or text.startswith(""):
await msg.answer(text, reply_markup=system_logs_kb)
await msg.answer(text, reply_markup=system_logs_audit_kb)
else:
await msg.answer(text, reply_markup=system_logs_kb, parse_mode="Markdown")
await msg.answer(text, reply_markup=system_logs_audit_kb, parse_mode="Markdown")
@dp.message(F.text == "🌍 External")
async def external_checks(msg: Message):
if not is_admin_msg(msg):
return
await msg.answer(format_report(cfg), reply_markup=system_logs_kb)
await msg.answer(format_report(cfg), reply_markup=system_logs_security_kb)
@dp.message(F.text == "📣 Incidents")
@@ -212,7 +218,7 @@ async def incidents(msg: Message):
return
path = incidents_path(cfg)
if not os.path.exists(path):
await msg.answer("⚠️ Incidents log not found", reply_markup=system_logs_kb)
await msg.answer("⚠️ Incidents log not found", reply_markup=system_logs_audit_kb)
return
last_24h = read_recent(cfg, hours=24, limit=500)
last_7d = read_recent(cfg, hours=24 * 7, limit=1000)
@@ -226,7 +232,7 @@ async def incidents(msg: Message):
"Recent (24h):\n"
f"```\n{body}\n```"
)
await msg.answer(text, reply_markup=system_logs_kb, parse_mode="Markdown")
await msg.answer(text, reply_markup=system_logs_audit_kb, parse_mode="Markdown")
@dp.message(F.text == "🔒 SSL")
@@ -234,7 +240,7 @@ async def ssl_certs(msg: Message):
if not is_admin_msg(msg):
return
await msg.answer("⏳ Checking SSL certificates…", reply_markup=system_logs_kb)
await msg.answer("⏳ Checking SSL certificates…", reply_markup=system_logs_security_kb)
async def worker():
try:
@@ -242,7 +248,7 @@ async def ssl_certs(msg: Message):
text = format_certificates(certs)
except Exception as e:
text = f"⚠️ NPMplus error: {e}"
await msg.answer(text, reply_markup=system_logs_kb)
await msg.answer(text, reply_markup=system_logs_security_kb)
asyncio.create_task(worker())
@@ -252,14 +258,14 @@ async def gitea_health(msg: Message):
if not is_admin_msg(msg):
return
await msg.answer("⏳ Checking Gitea health…", reply_markup=system_logs_kb)
await msg.answer("⏳ Checking Gitea health…", reply_markup=system_logs_integrations_kb)
async def worker():
try:
text = await asyncio.to_thread(get_gitea_health, cfg)
except Exception as e:
text = f"⚠️ Gitea error: {e}"
await msg.answer(text, reply_markup=system_logs_kb)
await msg.answer(text, reply_markup=system_logs_integrations_kb)
asyncio.create_task(worker())
@@ -269,17 +275,17 @@ async def npmplus_hosts(msg: Message):
if not is_admin_msg(msg):
return
await msg.answer("⏳ Loading NPMplus hosts…", reply_markup=system_logs_kb)
await msg.answer("⏳ Loading NPMplus hosts…", reply_markup=system_logs_integrations_kb)
async def worker():
try:
hosts = await asyncio.to_thread(list_proxy_hosts, cfg)
except Exception as e:
await msg.answer(f"⚠️ NPMplus error: {e}", reply_markup=system_logs_kb)
await msg.answer(f"⚠️ NPMplus error: {e}", reply_markup=system_logs_integrations_kb)
return
if not hosts:
await msg.answer("🧩 NPMplus\n\n(no proxy hosts)", reply_markup=system_logs_kb)
await msg.answer("🧩 NPMplus\n\n(no proxy hosts)", reply_markup=system_logs_integrations_kb)
return
lines = ["🧩 NPMplus proxy hosts\n"]
@@ -461,9 +467,9 @@ async def npmplus_toggle(cb: CallbackQuery):
await cb.answer("Working…")
ok, info = await asyncio.to_thread(set_proxy_host, cfg, host_id, enable)
if ok:
await cb.message.answer("✅ Updated", reply_markup=system_logs_kb)
await cb.message.answer("✅ Updated", reply_markup=system_logs_integrations_kb)
else:
await cb.message.answer(f"❌ NPMplus error: {info}", reply_markup=system_logs_kb)
await cb.message.answer(f"❌ NPMplus error: {info}", reply_markup=system_logs_integrations_kb)
@dp.message(F.text, F.func(lambda msg: msg.from_user and msg.from_user.id in REBOOT_PENDING))