Files
jcoffey-dev f2f13c3367 metrics-test and alerts-test: scraping, OTLP and the chart's alerts (K-C10)
metrics-test.sh: every server pod refuses /metrics/prometheus without the
password and with a wrong one, answers the chart's with the alert gauges,
renewed its cluster lease in the last 150 s, is listed by the headless
metrics Service, and pushes OTLP (HAProxy on the kind network stands in
for the collector) with the token from the headers Secret.

alerts-test.sh: Prometheus v3.5.0 on its own (no operator), scraping as
the chart's ServiceMonitor does, with the chart's rules and every for cut
to 0s. Quiet on a healthy install; then each alert from real breakage: a
stopped server process, a pod cut off from Postgres, mail to a host that
never answers (wait.lab.test, added to CoreDNS for the test), mail to
example.com's null MX, a certificate that runs out in two days. The store
latency alert with a threshold any read crosses. Puts everything back.

admin-jmap.py and queue-clean.py: JMAP as the lab admin, and removing
the mail a test queued.
2026-11-19 11:30:05 -07:00

27 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python3
"""JMAP method calls as [email protected], read as JSON from stdin.
admin-jmap.py <server> <admin password file> < calls.json
Signs in like the console (as blocked-ips.py) and prints the
methodResponses as JSON. Exits non-zero on an HTTP error.
"""
import base64, hashlib, http.client, json, secrets, sys, urllib.parse
server, pwfile = sys.argv[1:]
def request(method, path, headers=None, body=None):
u = urllib.parse.urlsplit(server); c = http.client.HTTPConnection(u.hostname, u.port, timeout=60)
c.request(method, path, body=body, headers=headers or {}); r = c.getresponse(); d = r.read(); c.close(); return r, d
v = secrets.token_urlsafe(48); ch = base64.urlsafe_b64encode(hashlib.sha256(v.encode()).digest()).rstrip(b"=").decode()
red = "https://admin.lab.test/oauth/callback"
r, d = request("POST", "/api/auth", {"content-type": "application/json"}, json.dumps({"type": "authCode", "accountName": "[email protected]",
"accountSecret": open(pwfile).read().strip(), "clientId": "inbuxa-admin", "redirectUri": red, "codeChallenge": ch, "codeChallengeMethod": "S256", "state": "x"}))
code = json.loads(d)["client_code"]
r, d = request("POST", "/auth/token", {"content-type": "application/x-www-form-urlencoded"}, urllib.parse.urlencode({"grant_type": "authorization_code",
"code": code, "redirect_uri": red, "client_id": "inbuxa-admin", "code_verifier": v}))
tok = json.loads(d)["access_token"]
r, d = request("POST", "/jmap", {"content-type": "application/json", "authorization": "Bearer " + tok},
json.dumps({"using": ["urn:ietf:params:jmap:core", "urn:inbuxa:jmap:registry"], "methodCalls": json.load(sys.stdin)}))
if r.status != 200:
sys.exit(f"jmap: HTTP {r.status}: {d[:300]!r}")
print(json.dumps(json.loads(d)["methodResponses"]))