API-Cookbook¶
Praktische Snippets für häufige Aufgaben.
1. Host anlegen + Agent-Token generieren¶
JWT="eyJhbGc..."
BASE="https://deine-domain.tld/api/v1"
# Host anlegen
HOST=$(curl -s -X POST "$BASE/hosts/" \
-H "Authorization: Bearer $JWT" \
-H "Content-Type: application/json" \
-d '{
"name": "web03.acme.local",
"tenant_id": "uuid-of-tenant",
"profile_id": "uuid-of-linux-profile",
"ip_address": "10.10.5.13",
"tags": ["production", "web"]
}')
HOST_ID=$(echo "$HOST" | jq -r .id)
# Agent-Token generieren
TOKEN=$(curl -s -X POST "$BASE/hosts/$HOST_ID/agent-token" \
-H "Authorization: Bearer $JWT" | jq -r .token)
# Agent installieren
ssh root@web03.acme.local \
"wget -qO- https://deine-domain.tld/agent/install.sh | bash -s -- $TOKEN https://deine-domain.tld"
import requests
BASE = "https://deine-domain.tld/api/v1"
HEADERS = {"Authorization": f"Bearer {JWT}"}
# Host anlegen
r = requests.post(f"{BASE}/hosts/", json={
"name": "web03.acme.local",
"tenant_id": tenant_id,
"profile_id": linux_profile_id,
"ip_address": "10.10.5.13",
"tags": ["production", "web"],
}, headers=HEADERS)
host = r.json()
# Agent-Token
token = requests.post(
f"{BASE}/hosts/{host['id']}/agent-token",
headers=HEADERS,
).json()["token"]
print("Token:", token)
2. Bulk-Import aus CSV¶
import csv, requests
with open("hosts.csv") as f:
for row in csv.DictReader(f):
requests.post(f"{BASE}/hosts/", json={
"name": row["hostname"],
"tenant_id": row["tenant_id"],
"profile_id": row["profile_id"],
"ip_address": row["ip"],
}, headers=HEADERS)
3. Service zu Host hinzufügen¶
curl -X POST "$BASE/host-services/" \
-H "Authorization: Bearer $JWT" \
-H "Content-Type: application/json" \
-d '{
"host_id": "host-uuid",
"profile_check_id": "profile-check-uuid",
"display_name": "Disk /var",
"config_overrides": { "path": "/var" },
"interval_override": 60
}'
4. Custom Dashboard programmatisch anlegen¶
dashboard = requests.post(f"{BASE}/dashboards/", json={
"name": "Acme NOC",
"tenant_id": tenant_id,
"layout": {
"grid": [
{ "x": 0, "y": 0, "w": 12, "h": 4, "widget": {
"type": "status_summary",
"config": { "scope": "tenant" }
}},
{ "x": 0, "y": 4, "w": 12, "h": 8, "widget": {
"type": "active_problems",
"config": { "max_items": 30 }
}}
]
},
"variables": [
{ "name": "host", "type": "query", "query": "all_hosts", "multi": True }
]
}, headers=HEADERS).json()
5. Bulk-Tag-Update¶
hosts = requests.get(f"{BASE}/hosts/?tag=legacy", headers=HEADERS).json()
for h in hosts["items"]:
new_tags = [t for t in h["tags"] if t != "legacy"] + ["deprecated"]
requests.patch(f"{BASE}/hosts/{h['id']}", json={"tags": new_tags}, headers=HEADERS)
6. Eigenes Webhook-Empfänger validieren¶
import hmac, hashlib, json
from flask import Flask, request
WEBHOOK_SECRET = "<secret aus channel-config>"
app = Flask(__name__)
@app.route("/vesana-webhook", methods=["POST"])
def receive():
body = request.get_data()
sig = request.headers.get("X-Vesana-Signature", "")
expected = "sha256=" + hmac.new(
WEBHOOK_SECRET.encode(), body, hashlib.sha256
).hexdigest()
if not hmac.compare_digest(sig, expected):
return "bad sig", 401
payload = json.loads(body)
if payload["status"] == "CRITICAL":
send_pager(payload["host"]["name"], payload["service"]["display_name"])
return "ok", 200
7. SLA-Report ziehen¶
curl "$BASE/reports/sla?from=2026-04-01&to=2026-04-30&tenant_id=acme-uuid&format=json" \
-H "Authorization: Bearer $JWT" \
| jq '.summary.tenant_availability'
8. Wartungsfenster setzen + auflösen¶
# Wartung planen
curl -X POST "$BASE/downtimes/" \
-H "Authorization: Bearer $JWT" \
-d '{
"scope": { "tag": "production" },
"starts_at": "2026-04-30T22:00:00Z",
"ends_at": "2026-04-30T23:30:00Z",
"comment": "Kernel-Update"
}'
# Vorzeitig beenden
curl -X DELETE "$BASE/downtimes/<id>" \
-H "Authorization: Bearer $JWT"
9. AI-Service-Analyse abrufen¶
curl -X POST "$BASE/ai/analyze/<service_id>" \
-H "Authorization: Bearer $JWT"
# Mit Force für höhere Temperature:
curl -X POST "$BASE/ai/analyze/<service_id>?force=true" \
-H "Authorization: Bearer $JWT"
10. Audit-Export für Compliance¶
curl "$BASE/audit-log/export?from=2026-04-01&format=csv" \
-H "Authorization: Bearer $JWT" \
> audit-april.csv