issues with mcp con
This commit is contained in:
@@ -561,6 +561,24 @@ def serve_dashboard(host: str, port: int, status_file: str, *, image_dir: str |
|
|||||||
image_root = Path(image_dir) if image_dir else None
|
image_root = Path(image_dir) if image_dir else None
|
||||||
config_store = ConfigStore(config_file)
|
config_store = ConfigStore(config_file)
|
||||||
|
|
||||||
|
def read_status() -> dict[str, object]:
|
||||||
|
try:
|
||||||
|
status = json.loads(status_path.read_text(encoding="utf-8")) if status_path.exists() else {}
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
status = {}
|
||||||
|
if not isinstance(status, dict):
|
||||||
|
status = {}
|
||||||
|
status.setdefault("status_schema", 2)
|
||||||
|
for row in status.get("stream_coverage", []) if isinstance(status.get("stream_coverage"), list) else []:
|
||||||
|
if isinstance(row, dict):
|
||||||
|
row.setdefault("aggregate_error", "")
|
||||||
|
row.setdefault("raw_error", "")
|
||||||
|
if row.get("aggregate_status") == "error" and not row.get("aggregate_error") and row.get("error"):
|
||||||
|
row["aggregate_error"] = str(row.get("error", ""))
|
||||||
|
if row.get("partial") and not row.get("raw_error") and row.get("error"):
|
||||||
|
row["raw_error"] = str(row.get("error", ""))
|
||||||
|
return status
|
||||||
|
|
||||||
class Handler(BaseHTTPRequestHandler):
|
class Handler(BaseHTTPRequestHandler):
|
||||||
def do_GET(self) -> None:
|
def do_GET(self) -> None:
|
||||||
if self.path == "/":
|
if self.path == "/":
|
||||||
@@ -618,21 +636,14 @@ def serve_dashboard(host: str, port: int, status_file: str, *, image_dir: str |
|
|||||||
self._send(400, "application/json", json.dumps({"error": str(exc)}).encode("utf-8"))
|
self._send(400, "application/json", json.dumps({"error": str(exc)}).encode("utf-8"))
|
||||||
return
|
return
|
||||||
if self.path == "/api/status":
|
if self.path == "/api/status":
|
||||||
if status_path.exists():
|
self._send(200, "application/json", json.dumps(read_status()).encode("utf-8"))
|
||||||
body = status_path.read_bytes()
|
|
||||||
else:
|
|
||||||
body = json.dumps({"summary": {}, "anomalies": [], "block_candidates": []}).encode("utf-8")
|
|
||||||
self._send(200, "application/json", body)
|
|
||||||
return
|
return
|
||||||
if self.path.startswith("/api/export/incidents"):
|
if self.path.startswith("/api/export/incidents"):
|
||||||
parsed = urlparse(self.path)
|
parsed = urlparse(self.path)
|
||||||
params = parse_qs(parsed.query)
|
params = parse_qs(parsed.query)
|
||||||
fmt = params.get("format", ["markdown"])[0]
|
fmt = params.get("format", ["markdown"])[0]
|
||||||
incident_id = params.get("incident_id", [""])[0] or None
|
incident_id = params.get("incident_id", [""])[0] or None
|
||||||
try:
|
status = read_status()
|
||||||
status = json.loads(status_path.read_text(encoding="utf-8")) if status_path.exists() else {}
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
status = {}
|
|
||||||
report = investigation_report(status, incident_id=incident_id)
|
report = investigation_report(status, incident_id=incident_id)
|
||||||
if fmt == "json":
|
if fmt == "json":
|
||||||
self._send(200, "application/json", json.dumps(report, indent=2, sort_keys=True).encode("utf-8"))
|
self._send(200, "application/json", json.dumps(report, indent=2, sort_keys=True).encode("utf-8"))
|
||||||
@@ -640,10 +651,7 @@ def serve_dashboard(host: str, port: int, status_file: str, *, image_dir: str |
|
|||||||
self._send(200, "text/markdown; charset=utf-8", investigation_report_markdown(report).encode("utf-8"))
|
self._send(200, "text/markdown; charset=utf-8", investigation_report_markdown(report).encode("utf-8"))
|
||||||
return
|
return
|
||||||
if self.path == "/metrics":
|
if self.path == "/metrics":
|
||||||
try:
|
status = read_status()
|
||||||
status = json.loads(status_path.read_text(encoding="utf-8")) if status_path.exists() else {}
|
|
||||||
except json.JSONDecodeError:
|
|
||||||
status = {}
|
|
||||||
self._send(200, "text/plain; version=0.0.4; charset=utf-8", prometheus_metrics(status).encode("utf-8"))
|
self._send(200, "text/plain; version=0.0.4; charset=utf-8", prometheus_metrics(status).encode("utf-8"))
|
||||||
return
|
return
|
||||||
if self.path.startswith("/images/") and image_root:
|
if self.path.startswith("/images/") and image_root:
|
||||||
|
|||||||
Reference in New Issue
Block a user