#!/usr/bin/env python3
"""Render AUDIT-360-MAX.json as one human-readable Markdown file."""
import json
from pathlib import Path
ROOT = Path("/root/buryan-infra/ops/audit")
D = json.loads((ROOT / "AUDIT-360-MAX.json").read_text(encoding="utf-8"))
OUT = ROOT / "BURYANS-HUB-FULL.md"
def e(x):
if x is None:
return ""
return str(x).replace("|", "\\|").replace("\n", "
").strip()
def table(headers, rows):
out = ["| " + " | ".join(headers) + " |", "|" + "|".join("---" for _ in headers) + "|"]
for r in rows:
out.append("| " + " | ".join(e(x) for x in r) + " |")
return "\n".join(out)
s = D.get("summary", {})
lines = []
lines.append("# Buryans Hub — полный аудит и ТЗ для агентов")
lines.append("")
lines.append("Дата: %s" % D.get("generated_at"))
lines.append("Схема: `%s`" % D.get("schema"))
lines.append("")
lines.append("## 1. Сводка")
lines.append("")
lines.append(table(["Слой", "Количество"], [
["CT", s.get("cts")], ["VM", s.get("vms")],
["Контейнеры всего", s.get("containers_all")],
["Контейнеры running", s.get("containers_running")],
["Compose-сервисы", s.get("compose_services")],
["Автоматизации", s.get("automations")],
["systemd", s.get("systemd")],
["Домены", s.get("domains")], ["Маршруты", s.get("routes")],
["Kuma", s.get("kuma")], ["PostgreSQL БД", s.get("databases")],
["Владельцы", s.get("owners")], ["Интеграции", s.get("integrations")],
["Gitea-файлы", s.get("gitea_files")],
["Findings", s.get("findings")], ["Capabilities", s.get("capabilities")],
["Decisions", s.get("decisions")], ["Experiments", s.get("experiments")],
["Arena ideas", s.get("arena_items")],
]))
lines.append("")
lines.append("**Медиасервер:** Jellyfin CT103, Radarr/Sonarr/Prowlarr/Bazarr, Seerr, "
"qBittorrent, `media.buryans.ru`. Медиатека по файлам в аудит не входит.")
lines.append("")
lines.append("**Границы:** это инфраструктурный срез. Секретов, содержимого всех файлов Gitea "
"и runtime-трафика здесь нет намеренно.")
lines.append("")
lines.append("## 2. Gitea")
lines.append("")
g = D.get("gitea", {})
lines.append(table(["Параметр", "Значение"], [
["HEAD", "`%s`" % g.get("head")], ["Branch", g.get("branch")],
["Remote", g.get("remote")], ["Tracked files", g.get("tracked_files")],
["Dirty", "
".join(g.get("dirty") or []) or "clean"],
]))
lines.append("")
lines.append("## 3. CT и VM")
lines.append("")
lines.append(table(["CT", "Статус", "Имя"], [(c.get("vmid"), c.get("status"), c.get("name")) for c in D.get("cts", [])]))
lines.append("")
lines.append(table(["VM", "Сырой статус"], [(v.get("vmid"), v.get("raw")) for v in D.get("vms", [])]))
lines.append("")
lines.append("## 4. Контейнеры (все, включая остановленные)")
lines.append("")
lines.append(table(["CT", "Имя", "Состояние", "Порты"],
[(c.get("ct"), c.get("name"), c.get("state"), c.get("ports")) for c in D.get("containers_all", [])]))
lines.append("")
lines.append("## 5. Compose-сервисы из Gitea")
lines.append("")
lines.append(table(["Файл", "Сервис", "Image", "Container", "Ports"],
[(c.get("file"), c.get("service"), c.get("image"), c.get("container_name"), c.get("ports"))
for c in (D.get("compose") or {}).get("services", [])]))
lines.append("")
lines.append("## 6. systemd")
lines.append("")
lines.append(table(["Unit", "Active", "Sub", "Description"],
[(x.get("unit"), x.get("active"), x.get("sub"), x.get("description")) for x in D.get("systemd", [])]))
lines.append("")
lines.append("## 7. Домены")
lines.append("")
for x in D.get("nginx_domains", []):
lines.append("- `%s`" % x)
lines.append("")
lines.append("## 8. Маршруты домен → upstream")
lines.append("")
lines.append(table(["Файл", "Домены", "Upstreams"],
[(r.get("file"), ", ".join(r.get("names") or []), ", ".join(r.get("upstreams") or []))
for r in D.get("routes", [])]))
lines.append("")
lines.append("## 9. Kuma")
lines.append("")
lines.append(table(["Монитор", "Состояние"], [(k.get("name"), "up" if k.get("up") else "down") for k in D.get("kuma", [])]))
lines.append("")
lines.append("## 10. PostgreSQL")
lines.append("")
lines.append(table(["База", "Размер"], [(d.get("name"), d.get("size")) for d in D.get("databases", [])]))
lines.append("")
lines.append("## 11. Владельцы")
lines.append("")
lines.append(table(["Имя", "Роль", "Email"], [(o.get("name"), o.get("role"), o.get("email")) for o in D.get("owners", [])]))
lines.append("")
lines.append("## 12. Автоматизации")
lines.append("")
for i, a in enumerate((D.get("automations") or {}).get("items", []) or [], 1):
if isinstance(a, dict):
name = a.get("name") or a.get("id") or a.get("unit") or a.get("schedule") or ""
src = a.get("source") or a.get("type") or a.get("origin") or ""
sched = a.get("schedule") or a.get("cron") or a.get("on_calendar") or ""
else:
name, src, sched = str(a), "", ""
lines.append("%d. %s — `%s` — `%s`" % (i, e(name), e(src), e(sched)))
lines.append("")
lines.append("## 13. Интеграции")
lines.append("")
lines.append("Всего связей: **%d**." % len(D.get("integrations", [])))
lines.append("")
lines.append("Полный список связей
")
lines.append("")
lines.append(table(["Связь"], [(json.dumps(x, ensure_ascii=False),) for x in D.get("integrations", [])]))
lines.append(" ")
lines.append("")
lines.append("## 14. Findings")
lines.append("")
lines.append(table(["ID", "Severity", "Area", "Title", "Owner", "Status"],
[(f.get("id"), f.get("severity"), f.get("area"), f.get("title"), f.get("owner"), f.get("status"))
for f in (D.get("audit") or {}).get("findings", [])]))
lines.append("")
lines.append("## 15. Decisions")
lines.append("")
lines.append(table(["ID", "Title", "Status", "Owner", "Review"],
[(d.get("id"), d.get("title"), d.get("status"), d.get("owner"), d.get("review_at"))
for d in (D.get("audit") or {}).get("decisions", [])]))
lines.append("")
lines.append("## 16. Experiments")
lines.append("")
lines.append(table(["ID", "Title", "Status", "Verification", "Result"],
[(x.get("id"), x.get("title"), x.get("status"), x.get("verification"), x.get("result"))
for x in (D.get("audit") or {}).get("experiments", [])]))
lines.append("")
lines.append("## 17. Arena")
lines.append("")
lines.append(table(["Score", "Title", "Voices", "Capability", "Impact/Effort/Risk"],
[(x.get("score"), x.get("title"), x.get("voices"), x.get("capability"),
"%s/%s/%s" % (x.get("impact"), x.get("effort"), x.get("risk")))
for x in D.get("arena_items", [])]))
lines.append("")
lines.append("## 18. Capabilities")
lines.append("")
lines.append(table(["Key", "Title", "Maturity", "Automation", "Leverage", "Criticality"],
[(c.get("key"), c.get("title"), c.get("maturity"), c.get("automation"), c.get("leverage"), c.get("criticality"))
for c in (D.get("audit") or {}).get("capabilities", [])]))
lines.append("")
lines.append("## 19. Полный манифест Gitea")
lines.append("")
lines.append("%d tracked files
" % len(g.get("files", [])))
lines.append("")
for f in g.get("files", []):
lines.append("- `%s`" % f)
lines.append(" ")
lines.append("")
lines.append("## 20. Что это значит")
lines.append("")
lines.append("- Инфраструктура описана полностью на уровне сервисов, доменов, маршрутов, БД и связей.")
lines.append("- Медиасервер есть: Jellyfin + *arr + Seerr + qBittorrent.")
lines.append("- HA PostgreSQL остаётся backlog после RAM.")
lines.append("- Следующий уровень — единый orchestrator, approvals, event bus и runtime graph.")
lines.append("- Для внешних моделей используй этот Markdown, а не JSON.")
OUT.write_text("\n".join(lines) + "\n", encoding="utf-8")
print("bytes", OUT.stat().st_size, "lines", len(lines))