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 os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import urllib.request
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from urllib.parse import parse_qs, urlparse
|
from urllib.parse import parse_qs, urlparse
|
||||||
@@ -285,22 +286,23 @@ class EcoHandlers:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
checks.append({'name': 'Config', 'pass': False, 'detail': str(e)})
|
checks.append({'name': 'Config', 'pass': False, 'detail': str(e)})
|
||||||
|
|
||||||
# 6. WhatsApp bridge log
|
# 6. WhatsApp bridge — connectivity, not log grepping. The bridge
|
||||||
wa_log = constants.ECHO_CORE_DIR / 'logs' / 'whatsapp-bridge.log'
|
# (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:
|
try:
|
||||||
if wa_log.exists():
|
with urllib.request.urlopen('http://127.0.0.1:8098/status', timeout=5) as resp:
|
||||||
r = subprocess.run(['tail', '-1', str(wa_log)], capture_output=True, text=True, timeout=5)
|
status = json.loads(resp.read())
|
||||||
last = r.stdout.strip()
|
connected = bool(status.get('connected'))
|
||||||
has_error = 'error' in last.lower() or 'fatal' in last.lower()
|
phone = status.get('phone') or 'unknown'
|
||||||
checks.append({
|
checks.append({
|
||||||
'name': 'WhatsApp bridge log',
|
'name': 'WhatsApp bridge',
|
||||||
'pass': not has_error,
|
'pass': connected,
|
||||||
'detail': last[:80] if last else 'Empty',
|
'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:
|
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
|
# 7. Claude CLI
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user