Add restart confirmation from watchdog alerts
This commit is contained in:
@@ -150,3 +150,57 @@ async def logs_options(cb: CallbackQuery):
|
||||
return
|
||||
|
||||
await cb.answer("Bad request")
|
||||
|
||||
|
||||
@dp.callback_query(F.data.startswith("wdrestart:"))
|
||||
async def watchdog_restart_request(cb: CallbackQuery):
|
||||
if cb.from_user.id != ADMIN_ID:
|
||||
return
|
||||
|
||||
_, alias = cb.data.split(":", 1)
|
||||
if alias not in DOCKER_MAP:
|
||||
await cb.answer("Container not found")
|
||||
return
|
||||
|
||||
kb = InlineKeyboardMarkup(
|
||||
inline_keyboard=[[
|
||||
InlineKeyboardButton(
|
||||
text="✅ Confirm restart",
|
||||
callback_data=f"wdconfirm:{alias}"
|
||||
),
|
||||
InlineKeyboardButton(
|
||||
text="✖ Cancel",
|
||||
callback_data="wdcancel"
|
||||
),
|
||||
]]
|
||||
)
|
||||
await cb.message.answer(
|
||||
f"⚠️ Confirm restart `{alias}`?",
|
||||
reply_markup=kb,
|
||||
parse_mode="Markdown",
|
||||
)
|
||||
await cb.answer()
|
||||
|
||||
|
||||
@dp.callback_query(F.data == "wdcancel")
|
||||
async def watchdog_restart_cancel(cb: CallbackQuery):
|
||||
await cb.answer("Cancelled")
|
||||
|
||||
|
||||
@dp.callback_query(F.data.startswith("wdconfirm:"))
|
||||
async def watchdog_restart_confirm(cb: CallbackQuery):
|
||||
if cb.from_user.id != ADMIN_ID:
|
||||
return
|
||||
|
||||
_, alias = cb.data.split(":", 1)
|
||||
real = DOCKER_MAP.get(alias)
|
||||
if not real:
|
||||
await cb.answer("Container not found")
|
||||
return
|
||||
|
||||
await cb.answer("Restarting…")
|
||||
rc, out = await docker_cmd(["restart", real])
|
||||
await cb.message.answer(
|
||||
f"🔄 **{alias} restarted**\n```{out}```",
|
||||
parse_mode="Markdown",
|
||||
)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import asyncio
|
||||
from datetime import datetime, timezone
|
||||
from typing import Dict
|
||||
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||||
from services.runner import run_cmd
|
||||
|
||||
|
||||
@@ -109,6 +110,21 @@ async def docker_watchdog(container_map, notify, bot, chat_id):
|
||||
state = "error"
|
||||
state = state.strip()
|
||||
if last.get(alias) != state:
|
||||
await notify(bot, chat_id, f"🐳 {alias}: {state}")
|
||||
if state != "running":
|
||||
kb = InlineKeyboardMarkup(
|
||||
inline_keyboard=[[
|
||||
InlineKeyboardButton(
|
||||
text="🔄 Restart",
|
||||
callback_data=f"wdrestart:{alias}"
|
||||
)
|
||||
]]
|
||||
)
|
||||
await bot.send_message(
|
||||
chat_id,
|
||||
f"🐳 {alias}: {state}",
|
||||
reply_markup=kb,
|
||||
)
|
||||
else:
|
||||
await notify(bot, chat_id, f"🐳 {alias}: {state}")
|
||||
last[alias] = state
|
||||
await asyncio.sleep(120)
|
||||
|
||||
Reference in New Issue
Block a user