diff --git a/dashboard/handlers/eco.py b/dashboard/handlers/eco.py index c029fc1..6a46e1e 100644 --- a/dashboard/handlers/eco.py +++ b/dashboard/handlers/eco.py @@ -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() - checks.append({ - 'name': 'WhatsApp bridge log', - 'pass': not has_error, - 'detail': last[:80] if last else 'Empty', - }) - else: - checks.append({'name': 'WhatsApp bridge log', 'pass': False, 'detail': 'Not found'}) + 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', + 'pass': connected, + 'detail': f'connected as {phone}' if connected else 'not connected (qr pending?)', + }) 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: