Backup automatico script del 2026-07-26 07:00

This commit is contained in:
daniele committed 2026-07-26 07:00:01 +02:00
1 parent 4802b021fe
commit a9bbb92090
19 files changed
+1086 -550

No files matched your search

+41 -1
View File
@@ -44,9 +44,45 @@ CATEGORIES = {
"telegram_error": re.compile(r"Telegram error|Bad Request|chat not found|can't parse entities", re.IGNORECASE),
"traceback": re.compile(r"Traceback", re.IGNORECASE),
"exception": re.compile(r"\bERROR\b|Exception", re.IGNORECASE),
"token_missing": re.compile(r"token missing|Token Telegram assente", re.IGNORECASE),
# Solo token realmente assente (non i messaggi ambigui con Telegram sospeso)
"token_missing": re.compile(
r"Telegram token missing|Token Telegram assente|Token Telegram mancante",
re.IGNORECASE,
),
}
# Comportamento atteso con LOOGLE_TELEGRAM_ALERTS=0 / canale WebApp: non sono problemi.
IGNORE_ISSUE_PATTERNS = [
re.compile(r"Telegram sospeso", re.IGNORECASE),
re.compile(r"Alert NON inviato \(token missing o errore Telegram\)", re.IGNORECASE),
re.compile(r"NOT sent \(token missing or Telegram error\)", re.IGNORECASE),
re.compile(r"Notifica NON inviata \(token/telegram\)", re.IGNORECASE),
re.compile(r"token missing o errore Telegram", re.IGNORECASE),
re.compile(r"token mancante o errore Telegram", re.IGNORECASE),
re.compile(r"Telegram saltato/sospeso", re.IGNORECASE),
re.compile(r"All-clear Telegram skip/fail", re.IGNORECASE),
re.compile(r"publish_web_alert failed", re.IGNORECASE), # gestito sotto come web_notify se serve
]
def telegram_alerts_suspended() -> bool:
env_path = os.path.join(BASE_DIR, "cron-alerts.env")
try:
with open(env_path, "r", encoding="utf-8") as f:
for line in f:
line = line.strip()
if line.startswith("LOOGLE_TELEGRAM_ALERTS="):
val = line.split("=", 1)[1].strip().strip('"').strip("'").lower()
return val in ("0", "off", "false", "no", "disabled")
except OSError:
pass
val = os.environ.get("LOOGLE_TELEGRAM_ALERTS", "1").strip().lower()
return val in ("0", "off", "false", "no", "disabled")
def should_ignore_issue_line(line: str) -> bool:
return any(p.search(line) for p in IGNORE_ISSUE_PATTERNS)
def load_text_file(path: str) -> str:
try:
@@ -126,6 +162,8 @@ def analyze_logs(files: List[str], since: datetime.datetime, max_lines: int) ->
last_ts = ts
if not last_ts or last_ts < since:
continue
if should_ignore_issue_line(line):
continue
for cat, regex in CATEGORIES.items():
if regex.search(line):
category_hits[cat].append((last_ts, path, line))
@@ -169,6 +207,8 @@ def format_report(
lines.append(f"🧾 Log Monitor - ultimi {days} giorni")
lines.append(f"Intervallo: {since.strftime('%Y-%m-%d %H:%M')}{now.strftime('%Y-%m-%d %H:%M')}")
lines.append(f"File analizzati: {len(files)}")
if telegram_alerts_suspended():
lines.append("️ Telegram sospeso (LOOGLE_TELEGRAM_ALERTS=0): canale primario WebApp Casa")
lines.append("")
# Sezione log non aggiornati