52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
"""Снимок Grafana provisioning (datasources/dashboard) без секретов."""
|
|
from __future__ import annotations
|
|
|
|
import base64
|
|
import json
|
|
import ssl
|
|
import urllib.request
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
password = (ROOT / "secrets" / "grafana_admin_password").read_text(encoding="utf-8").strip()
|
|
ctx = ssl.create_default_context(cafile=str(ROOT / "certs" / "ca.crt"))
|
|
|
|
|
|
def get(path: str):
|
|
request = urllib.request.Request("https://127.0.0.1:3000" + path)
|
|
request.add_header(
|
|
"Authorization", "Basic " + base64.b64encode(f"admin:{password}".encode()).decode()
|
|
)
|
|
with urllib.request.urlopen(request, context=ctx, timeout=10) as response:
|
|
return json.loads(response.read())
|
|
|
|
|
|
def main() -> int:
|
|
health = get("/api/health")
|
|
datasources = get("/api/datasources")
|
|
dashboards = get("/api/search?type=dash-db")
|
|
summary = {
|
|
"health": health,
|
|
"datasources": [
|
|
{
|
|
"name": item["name"],
|
|
"uid": item.get("uid"),
|
|
"type": item["type"],
|
|
"url": item["url"],
|
|
"tlsAuth": (item.get("jsonData") or {}).get("tlsAuth", False),
|
|
"tlsAuthWithCACert": (item.get("jsonData") or {}).get("tlsAuthWithCACert", False),
|
|
}
|
|
for item in datasources
|
|
],
|
|
"dashboards": [{"uid": item.get("uid"), "title": item.get("title")} for item in dashboards],
|
|
}
|
|
(ROOT / "evidence" / "11-grafana.json").write_text(
|
|
json.dumps(summary, indent=2, ensure_ascii=False), encoding="utf-8"
|
|
)
|
|
print(json.dumps(summary, indent=2, ensure_ascii=False))
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|