Реализовать лабораторную 7

This commit is contained in:
Krep4334
2026-12-01 17:47:59 +03:00
parent 20afc2c790
commit 9ffa60daef
89 changed files with 5054 additions and 69 deletions
+42
View File
@@ -0,0 +1,42 @@
import base64
import json
from pathlib import Path
import ssl
import time
from urllib.error import HTTPError, URLError
from urllib.request import Request, urlopen
ROOT = Path(__file__).resolve().parents[1]
def main():
context = ssl.create_default_context(cafile=str(ROOT / "secrets/operator/ca.pem"))
password = (ROOT / "secrets/grafana_password").read_text().strip()
auth = base64.b64encode(("admin:" + password).encode()).decode()
paths = {
"Prometheus": "/api/datasources/uid/prometheus/health",
"Loki": "/api/datasources/uid/loki/health",
"Tempo": "/api/datasources/proxy/uid/tempo/api/search",
}
for name, path in paths.items():
deadline = time.monotonic() + 90
while True:
request = Request("https://localhost:13007" + path,
headers={"Authorization": "Basic " + auth})
try:
with urlopen(request, context=context, timeout=15) as response:
result = json.load(response)
if name == "Tempo":
assert isinstance(result.get("traces"), list)
else:
assert result.get("status") == "OK"
print("PASS: Grafana queries " + name + " through verified mTLS", flush=True)
break
except (HTTPError, URLError, TimeoutError, AssertionError):
if time.monotonic() >= deadline:
raise
time.sleep(2)
if __name__ == "__main__":
main()