my-homelab-configs/scripts/doctor-narrative.py

38 lines
1.2 KiB
Python

#!/usr/bin/env python3
"""Render collected doctor evidence without inventing a repair."""
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]}")
else:
print("\nNo failing or warning checks were observed.")
print("\nCollected evidence:")
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("Review the evidence and use a focused doctor before changing the service.")
if __name__ == "__main__":
main()