Compare commits

..

3 Commits

View File

@@ -13,6 +13,7 @@ from keyboards import (
system_logs_integrations_kb, system_logs_integrations_kb,
system_logs_kb, system_logs_kb,
openwrt_kb, openwrt_kb,
docker_kb,
) )
from system_checks import security, disks, hardware, list_disks, smart_last_test from system_checks import security, disks, hardware, list_disks, smart_last_test
from services.http_checks import get_url_checks, check_url from services.http_checks import get_url_checks, check_url
@@ -205,7 +206,7 @@ async def smart_status(msg: Message):
await msg.answer("\n".join(lines), reply_markup=system_info_kb) await msg.answer("\n".join(lines), reply_markup=system_info_kb)
@dp.message(F.text.in_({"📡 OpenWrt", "📡 Full status"})) @dp.message(F.text.in_({"/openwrt", "📡 Full status"}))
async def openwrt_status(msg: Message): async def openwrt_status(msg: Message):
if not is_admin_msg(msg): if not is_admin_msg(msg):
return return
@@ -245,6 +246,13 @@ async def openwrt_wan(msg: Message):
asyncio.create_task(worker()) asyncio.create_task(worker())
@dp.message(F.text == "📡 OpenWrt")
async def openwrt_menu(msg: Message):
if not is_admin_msg(msg):
return
await msg.answer("📡 OpenWrt menu", reply_markup=openwrt_kb)
@dp.message(F.text.in_({"/openwrt_clients", "📶 Wi-Fi clients"})) @dp.message(F.text.in_({"/openwrt_clients", "📶 Wi-Fi clients"}))
async def openwrt_clients(msg: Message): async def openwrt_clients(msg: Message):
if not is_admin_msg(msg): if not is_admin_msg(msg):
@@ -549,15 +557,15 @@ async def backup_sla(msg: Message):
return return
rc, out = await run_cmd_full(["restic", "snapshots", "--json"], use_restic_env=True, timeout=40) rc, out = await run_cmd_full(["restic", "snapshots", "--json"], use_restic_env=True, timeout=40)
if rc != 0: if rc != 0:
await msg.answer(f"⚠️ Restic error: {out.strip() or rc}", reply_markup=system_logs_audit_kb) await msg.answer(f"⚠️ Restic error: {out.strip() or rc}", reply_markup=backup_kb)
return return
try: try:
snaps = json.loads(out) snaps = json.loads(out)
except Exception as e: except Exception as e:
await msg.answer(f"⚠️ Invalid restic JSON: {e}", reply_markup=system_logs_audit_kb) await msg.answer(f"⚠️ Invalid restic JSON: {e}", reply_markup=backup_kb)
return return
if not isinstance(snaps, list) or not snaps: if not isinstance(snaps, list) or not snaps:
await msg.answer("⚠️ No snapshots found", reply_markup=system_logs_audit_kb) await msg.answer("⚠️ No snapshots found", reply_markup=backup_kb)
return return
snaps.sort(key=lambda s: s.get("time", ""), reverse=True) snaps.sort(key=lambda s: s.get("time", ""), reverse=True)
last_time_raw = snaps[0].get("time") last_time_raw = snaps[0].get("time")
@@ -583,7 +591,7 @@ async def backup_sla(msg: Message):
f"Snapshots: {len(snaps)}\n" f"Snapshots: {len(snaps)}\n"
f"Last: {last_str} (age {age_str})\n" f"Last: {last_str} (age {age_str})\n"
f"SLA: {sla}h", f"SLA: {sla}h",
reply_markup=system_logs_audit_kb, reply_markup=backup_kb,
) )
@@ -602,7 +610,7 @@ async def docker_restarts(msg: Message):
rows = read_raw(cfg, hours=hours, limit=5000, include_old=True) rows = read_raw(cfg, hours=hours, limit=5000, include_old=True)
restarts = [(dt, line) for dt, line in rows if "docker_restart" in line] restarts = [(dt, line) for dt, line in rows if "docker_restart" in line]
if not restarts: if not restarts:
await msg.answer(f"🐳 No docker restarts in last {hours}h", reply_markup=system_logs_audit_kb) await msg.answer(f"🐳 No docker restarts in last {hours}h", reply_markup=docker_kb)
return return
counts: dict[str, int] = {} counts: dict[str, int] = {}
for _dt, line in restarts: for _dt, line in restarts:
@@ -616,7 +624,7 @@ async def docker_restarts(msg: Message):
body = "\n".join(f"{dt.astimezone().strftime('%m-%d %H:%M')} {line}" for dt, line in restarts[-50:]) body = "\n".join(f"{dt.astimezone().strftime('%m-%d %H:%M')} {line}" for dt, line in restarts[-50:])
await msg.answer( await msg.answer(
f"🐳 Docker restarts ({hours}h): {len(restarts)} ({top})\n```\n{body}\n```", f"🐳 Docker restarts ({hours}h): {len(restarts)} ({top})\n```\n{body}\n```",
reply_markup=system_logs_audit_kb, reply_markup=docker_kb,
parse_mode="Markdown", parse_mode="Markdown",
) )
@@ -637,7 +645,7 @@ async def openwrt_leases_diff(msg: Message):
prev = runtime_state.get("openwrt_leases_prev", []) prev = runtime_state.get("openwrt_leases_prev", [])
if not prev: if not prev:
runtime_state.set_state("openwrt_leases_prev", leases_now) runtime_state.set_state("openwrt_leases_prev", leases_now)
await msg.answer(f"Baseline saved ({len(leases_now)} leases)", reply_markup=system_info_kb) await msg.answer(f"Baseline saved ({len(leases_now)} leases)", reply_markup=openwrt_kb)
return return
prev_set = set(prev) prev_set = set(prev)
now_set = set(leases_now) now_set = set(leases_now)
@@ -664,7 +672,7 @@ async def queue_sla(msg: Message):
return return
hist = get_history_raw() hist = get_history_raw()
if not hist: if not hist:
await msg.answer("🧾 Queue SLA: history is empty", reply_markup=system_logs_audit_kb) await msg.answer("🧾 Queue SLA: history is empty", reply_markup=backup_kb)
return return
waits = [item.get("wait_sec", 0) for item in hist] waits = [item.get("wait_sec", 0) for item in hist]
runs = [item.get("runtime_sec", 0) for item in hist] runs = [item.get("runtime_sec", 0) for item in hist]
@@ -688,7 +696,7 @@ async def queue_sla(msg: Message):
f"Avg wait: {stats.get('avg_wait_sec', 0):.1f}s, " f"Avg wait: {stats.get('avg_wait_sec', 0):.1f}s, "
f"avg run: {stats.get('avg_runtime_sec', 0):.1f}s" f"avg run: {stats.get('avg_runtime_sec', 0):.1f}s"
) )
await msg.answer("\n".join(lines), reply_markup=system_logs_audit_kb) await msg.answer("\n".join(lines), reply_markup=backup_kb)
@dp.message(F.text == "/selftest_history") @dp.message(F.text == "/selftest_history")