fix(doctor): health check WhatsApp prin /status, nu grep pe log
Bridge-ul Baileys scrie erori tranzitorii, non-fatale (timeout pe query-uri interne de init) la nivel pino 50 chiar și conectat — verificarea "ultima linie de log conține 'error'" le raporta ca eșec. /status e ce consideră bridge-ul însuși despre starea lui. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SiJGsZVSEGjRHZEJiXaxCC
This commit is contained in:
@@ -3,6 +3,7 @@ import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import urllib.request
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
@@ -285,22 +286,23 @@ class EcoHandlers:
|
||||
except Exception as e:
|
||||
checks.append({'name': 'Config', 'pass': False, 'detail': str(e)})
|
||||
|
||||
# 6. WhatsApp bridge log
|
||||
wa_log = constants.ECHO_CORE_DIR / 'logs' / 'whatsapp-bridge.log'
|
||||
# 6. WhatsApp bridge — connectivity, not log grepping. The bridge
|
||||
# (Baileys) logs transient, non-fatal errors (timeouts on internal
|
||||
# init queries) at pino level 50 even while connected; a "does the
|
||||
# last log line contain 'error'" check flagged those as failures.
|
||||
# /status is what the bridge itself considers its health.
|
||||
try:
|
||||
if wa_log.exists():
|
||||
r = subprocess.run(['tail', '-1', str(wa_log)], capture_output=True, text=True, timeout=5)
|
||||
last = r.stdout.strip()
|
||||
has_error = 'error' in last.lower() or 'fatal' in last.lower()
|
||||
with urllib.request.urlopen('http://127.0.0.1:8098/status', timeout=5) as resp:
|
||||
status = json.loads(resp.read())
|
||||
connected = bool(status.get('connected'))
|
||||
phone = status.get('phone') or 'unknown'
|
||||
checks.append({
|
||||
'name': 'WhatsApp bridge log',
|
||||
'pass': not has_error,
|
||||
'detail': last[:80] if last else 'Empty',
|
||||
'name': 'WhatsApp bridge',
|
||||
'pass': connected,
|
||||
'detail': f'connected as {phone}' if connected else 'not connected (qr pending?)',
|
||||
})
|
||||
else:
|
||||
checks.append({'name': 'WhatsApp bridge log', 'pass': False, 'detail': 'Not found'})
|
||||
except Exception as e:
|
||||
checks.append({'name': 'WhatsApp bridge log', 'pass': False, 'detail': str(e)})
|
||||
checks.append({'name': 'WhatsApp bridge', 'pass': False, 'detail': f'unreachable: {e}'})
|
||||
|
||||
# 7. Claude CLI
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user