refactor: canary шлёт алерт в Telegram, не email (юзер email не читает)
Канал алерта — Telegram напрямую (curl, без xray: xray телегу не роутит, проверено). Восстановление — молча в лог, без пинга. email_service.send_alert откачен (не нужен). Профилактика: регулярный вызов держит OAuth-сессию тёплой. Тест обновлён. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -52,32 +52,3 @@ def send_verification_code(to_email: str, code: str) -> bool:
|
||||
except Exception as e:
|
||||
logger.error("Failed to send email to %s: %s", to_email, e)
|
||||
return False
|
||||
|
||||
|
||||
def send_alert(subject: str, text: str, to_email: str | None = None) -> bool:
|
||||
"""Send a plain-text operational alert to the operator. Returns True on success.
|
||||
|
||||
Recipient: explicit arg → ALERT_EMAIL env → SMTP_USER (self). Used by
|
||||
scripts/agent_canary.sh when the Claude agent path goes down.
|
||||
"""
|
||||
to = to_email or os.environ.get("ALERT_EMAIL") or SMTP_USER
|
||||
if not SMTP_USER or not SMTP_PASS or not to:
|
||||
logger.warning("SMTP/ALERT not configured, skipping alert")
|
||||
return False
|
||||
|
||||
from email.header import Header
|
||||
msg = MIMEText(text, "plain", "utf-8")
|
||||
msg["Subject"] = subject
|
||||
msg["From"] = f"{Header('Сметный ассистент', 'utf-8').encode()} <{SMTP_USER}>"
|
||||
msg["To"] = to
|
||||
|
||||
try:
|
||||
context = ssl.create_default_context()
|
||||
with smtplib.SMTP_SSL(SMTP_HOST, SMTP_PORT, context=context, timeout=10) as server:
|
||||
server.login(SMTP_USER, SMTP_PASS)
|
||||
server.sendmail(SMTP_USER, to, msg.as_string())
|
||||
logger.info("Alert email sent to %s", to)
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error("Failed to send alert to %s: %s", to, e)
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user