#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Генератор HTML отчетов для универсальной лаборатории Автор: Сергей Антропов Сайт: https://devops.org.ru """ import sys import json import html import datetime def main(): if len(sys.argv) < 3: print("Usage: report_html.py ") sys.exit(1) inp, outp = sys.argv[1], sys.argv[2] try: with open(inp, 'r', encoding='utf-8') as f: data = json.load(f) except Exception as e: data = {"error": f"failed to read json: {e}"} ts = data.get("timestamp", datetime.datetime.utcnow().isoformat()) idemp_raw = data.get("idempotence_raw", "") haproxy_sel = data.get("haproxy_select1", "") helm_ingress_toolbox = data.get("helm_ingress_toolbox_raw", "") istio_kiali = data.get("istio_kiali_raw", "") istio_bookinfo = data.get("istio_bookinfo_raw", "") k8s_overview = data.get("k8s_overview_raw", "") def badge(label, ok): color = "#10b981" if ok else "#ef4444" return f'{html.escape(label)}' # Анализ статусов idempotent_ok = ("changed=0" in idemp_raw) haproxy_ok = (haproxy_sel.strip() == "1") if haproxy_sel else None ingress_ok = ("ingress" in helm_ingress_toolbox.lower()) or ("curl http://localhost" in helm_ingress_toolbox.lower()) toolbox_ok = ("deploy/toolbox" in helm_ingress_toolbox.lower()) or ("rollout status" in helm_ingress_toolbox.lower()) istio_ok = ("istio-system" in istio_kiali.lower()) and ("istiod" in istio_kiali.lower()) kiali_ok = ("kiali" in istio_kiali.lower()) bookinfo_ok = ("bookinfo" in istio_bookinfo.lower()) or ("productpage" in istio_bookinfo.lower()) k8s_ok = ("nodes" in k8s_overview.lower()) and ("pods" in k8s_overview.lower()) def maybe_badge(label, status): if status is None: return f'{html.escape(label)}: n/a' return badge(f"{label}", bool(status)) html_doc = f""" Lab Report

Ansible Lab Report

generated: {html.escape(ts)}

Summary

{badge("Idempotent", idempotent_ok)} {maybe_badge("HAProxy SELECT=1", haproxy_ok)} {maybe_badge("Ingress ready", ingress_ok)} {maybe_badge("Toolbox ready", toolbox_ok)} {maybe_badge("Istio ready", istio_ok)} {maybe_badge("Kiali ready", kiali_ok)} {maybe_badge("Bookinfo ready", bookinfo_ok)} {maybe_badge("K8s ready", k8s_ok)}

Idempotence (raw)

{html.escape(idemp_raw) if idemp_raw else "n/a"}

Helm + Ingress + Toolbox (raw)

{html.escape(helm_ingress_toolbox) if helm_ingress_toolbox else "n/a"}

Istio / Kiali (raw)

{html.escape(istio_kiali) if istio_kiali else "n/a"}

Istio Bookinfo (raw)

{html.escape(istio_bookinfo) if istio_bookinfo else "n/a"}

K8s Overview (raw)

{html.escape(k8s_overview) if k8s_overview else "n/a"}

HAProxy SELECT 1

{html.escape(haproxy_sel) if haproxy_sel else "n/a"}
""" with open(outp, "w", encoding="utf-8") as f: f.write(html_doc) print(outp) if __name__ == "__main__": main()