#!/usr/bin/env python3 """Render collected doctor evidence without inventing a repair.""" import re import shlex import sys def main(): rows = [] with open(sys.argv[1], encoding="utf-8") as stream: for line in stream: fields = (line.rstrip("\n").split("\t") + [""] * 8)[:8] rows.append(fields) print(sys.argv[2]) print("=" * len(sys.argv[2])) problems = [row for row in rows if row[0] in ("warn", "fail")] if problems: print("\nWhat needs attention:") for row in problems: print(f"- {row[1]} / {row[2]}: {row[3]}") if row[1:3] == ["Orange Pi diagnostics", "K3s storage evidence"] and row[3].startswith("Stale read-only K3s mount"): print(" The former mounted device is absent. A reappeared disk is a candidate, not yet verified as the K3s volume.") print(" Evidence comes from systemctl is-active k3s, findmnt, lsblk and the kernel journal on the Orange Pi.") print(" To apply the guarded recovery: ./jeannie doctor opi5 --repair-k3s") match = re.fullmatch(r"[a-zA-Z0-9][a-zA-Z0-9_.-]*/[a-zA-Z0-9][a-zA-Z0-9_.-]* \(([a-zA-Z0-9][a-zA-Z0-9_.-]*)\)", row[2]) if row[1] == "Debian Compose" and match: if "desired state unknown" in row[3]: print(" The container is unhealthy or not running; whether it should be running is not recorded.") elif "operator recorded expected state: stopped" in row[3]: print(" The observed state differs from the operator's recorded stopped state.") print(" Read-only next check:") print(" $ sudo -n docker inspect --format 'state={{.State.Status}} exit={{.State.ExitCode}} restarts={{.RestartCount}}' " + shlex.quote(match.group(1))) else: print("\nNo failing or warning checks were observed.") print("\nCollected evidence:") if any(row[1] == "Debian Compose" for row in rows): print("$ sudo -n docker ps -a --filter label=com.docker.compose.project --format '{{json .}}'") for status, area, check, summary, detail, *_ in rows: if status == "skip": continue print(f"- {area} / {check}: {summary}") if detail and detail != summary: print(f" {detail}") if not rows: print("- No evidence was collected.") if problems: print("\nNo specific automatic mitigation has been established from these checks.") print("Record the intended state or inspect the affected service before making changes.") if __name__ == "__main__": main()