API und Heartbeat-Anleitung
Mit der REST-API legst du Monitore an, änderst sie und liest Vorfälle aus, zum Beispiel aus einer CI/CD-Pipeline. Heartbeat-Monitore überwachen Cronjobs und Backups.
Zugang
Die API gibt es im Tarif PRO. Einen Schlüssel legst du in den Einstellungen unter „Integrationen & API“ an; er wird nur einmal angezeigt.
Jede Anfrage schickt den Schlüssel im Header X-API-KEY. Ein Schlüssel darf Monitore und Vorfälle bearbeiten, aber nicht Team, Schlüssel oder Einstellungen.
Antworten kommen als JSON. Bei einem Fehler ist der HTTP-Status 400 oder höher, die Meldung steht im Feld detail.
curl -fsS -H "X-API-KEY: $WATCHCORE_KEY" https://watchcore.de/api/v1/monitorsEndpunkte
| GET | /monitors | Alle Monitore, optional gefiltert mit ?type= und ?project= |
| GET | /monitors/{id}?range=24h | Details, Kennzahlen und letzte Prüfungen (24h, 7d oder 30d) |
| POST | /monitors | Monitor anlegen |
| PATCH | /monitors/{id} | Monitor ändern; nur die mitgeschickten Felder |
| DELETE | /monitors/{id} | Monitor löschen; Verlauf und Vorfälle bleiben |
| POST | /monitors/{id}/duplicate | Pausierte Kopie mit allen Einstellungen anlegen |
| POST | /monitors/import | Monitore aus CSV anlegen, wie der Import in der Monitor-Liste |
| POST | /projects/quickstart | Projekt aus einer Vorlage anlegen: Monitore und Statusseite, ohne Alarmkanäle |
| GET | /templates | Die Vorlagen dafür und die Health-Vorlagen für JSON-Query-Monitore |
| GET | /metrics | Zustand aller Monitore im Textformat von Prometheus |
| POST | /trigger/{id} | Sofort prüfen (höchstens einmal pro Minute je Monitor) |
| GET | /incidents?limit=50 | Die letzten Vorfälle |
| POST | /incidents/{id}/ack | Vorfall bestätigen |
Beispiel: einen HTTP-Monitor anlegen.
curl -fsS -X POST https://watchcore.de/api/v1/monitors \
-H "X-API-KEY: $WATCHCORE_KEY" -H "Content-Type: application/json" \
-d '{"name": "Shop", "url": "https://shop.example.com", "type": "http", "project": "Web", "interval": 60}'Mögliche Typen: http, ping, port, ssh, dns, json_query, websocket, heartbeat, blacklist, pagespeed, synthetic, smtp und website, je nach Tarif. Das Intervall in Sekunden hebt der Server auf das Minimum von Tarif und Typ an.
Ein ganzes Projekt aus einer Vorlage anlegen (wie der Schnellstart auf der Seite Projekte):
curl -fsS -X POST https://watchcore.de/api/v1/projects/quickstart \
-H "X-API-KEY: $WATCHCORE_KEY" -H "Content-Type: application/json" \
-d '{"template": "wordpress", "domain": "shop.example.com", "project": "Shop"}'Prometheus und Grafana
Unter /api/v1/metrics stehen alle Monitore deines Kontos im Textformat von Prometheus, mit demselben API-Schlüssel. Prometheus schickt ihn als Bearer-Token, der Header X-API-KEY geht auch.
# prometheus.yml (excerpt)
scrape_configs:
- job_name: watchcore
scheme: https
metrics_path: /api/v1/metrics
scrape_interval: 60s
authorization:
type: Bearer
credentials_file: /etc/prometheus/watchcore.key
static_configs:
- targets: ["watchcore.de"]Je Monitor mit den Labels id, name, project und type: up (1 oder 0, nur aktive Monitore), Antwortzeit und Zeitpunkt der letzten Prüfung, laufende Wartung, pausiert, offene Vorfälle und Resttage des Zertifikats.
watchcore_monitor_up{id="Shop_ab12cd34",name="Shop",project="Web",type="http"} 1
watchcore_monitor_response_time_seconds{id="Shop_ab12cd34",name="Shop",project="Web",type="http"} 0.118
watchcore_monitor_ssl_expiry_days{id="Shop_ab12cd34",name="Shop",project="Web",type="http"} 61Ein fertiges Dashboard für Grafana: watchcore-grafana.json. In Grafana unter Dashboards, Import einlesen und die Prometheus-Datenquelle wählen.
Monitore als Code
Das Beispielskript legt Monitore aus einer YAML-Datei an und hält sie abgeglichen, etwa aus einem Git-Repository. Es erkennt einen Monitor an Projekt und Name, legt fehlende an und ändert abweichende Felder. Ohne --apply zeigt es nur, was es tun würde; löschen nur mit --prune und nur in den Projekten aus der Datei.
Skript (Python 3.9 oder neuer): watchcore_monitors.py
# monitors.yaml
project: Shop # for monitors without their own project
monitors:
- name: Shop
url: https://shop.example.com
interval: 60
keyword: Warenkorb
- name: Shop API
type: json_query
url: https://api.shop.example.com/health
assertions:
- {path: $.status, operator: "==", expected: UP}
- name: Shop DNS
type: dns
url: shop.example.com
interval: 600pip install pyyaml
export WATCHCORE_KEY=myk_live_...
python watchcore_monitors.py monitors.yaml # only shows what would change
python watchcore_monitors.py monitors.yaml --apply # creates and updates
python watchcore_monitors.py monitors.yaml --apply --prune # also deletes monitors of these projects missing in the fileCI/CD: Wartung während eines Deploys
Damit ein Deploy keinen Alarm auslöst, trage vorher ein Wartungsfenster ein. Solange es läuft, bleiben Alarme aus, und die Zeit zählt nicht gegen dein SLA. maintenance_windows ersetzt die gespeicherten Fenster des Monitors.
# .github/workflows/deploy.yml (excerpt)
- name: Start WatchCore maintenance (30 minutes)
run: |
START=$(date -u +%Y-%m-%dT%H:%M:%SZ)
END=$(date -u -d '+30 minutes' +%Y-%m-%dT%H:%M:%SZ)
curl -fsS -X PATCH "https://watchcore.de/api/v1/monitors/$MONITOR_ID" \
-H "X-API-KEY: ${{ secrets.WATCHCORE_KEY }}" -H "Content-Type: application/json" \
-d "{\"maintenance_windows\": [{\"start\": \"$START\", \"end\": \"$END\"}]}"
# ... deploy ...
- name: End WatchCore maintenance and check
if: always()
run: |
curl -fsS -X PATCH "https://watchcore.de/api/v1/monitors/$MONITOR_ID" \
-H "X-API-KEY: ${{ secrets.WATCHCORE_KEY }}" -H "Content-Type: application/json" \
-d '{"maintenance_windows": []}'
curl -fsS -X POST "https://watchcore.de/api/v1/trigger/$MONITOR_ID" -H "X-API-KEY: ${{ secrets.WATCHCORE_KEY }}"CI/CD: nach dem Deploy prüfen
Nach dem Deploy löst die Pipeline eine Prüfung aus, wartet auf das Ergebnis und schlägt fehl, wenn der Monitor DOWN ist. Eine eigene GitHub Action braucht es dafür nicht, curl und jq reichen.
GitHub Actions:
# .github/workflows/deploy.yml (excerpt), after the deploy step
- name: Check with WatchCore
env:
KEY: ${{ secrets.WATCHCORE_KEY }}
MONITOR_ID: ${{ vars.WATCHCORE_MONITOR_ID }}
run: |
URL="https://watchcore.de/api/v1/monitors/$MONITOR_ID"
BEFORE=$(curl -fsS -H "X-API-KEY: $KEY" "$URL" | jq -r .last_check)
curl -fsS -X POST -H "X-API-KEY: $KEY" "https://watchcore.de/api/v1/trigger/$MONITOR_ID"
for i in $(seq 12); do
sleep 10
NOW=$(curl -fsS -H "X-API-KEY: $KEY" "$URL")
if [ "$(echo "$NOW" | jq -r .last_check)" != "$BEFORE" ]; then break; fi
done
echo "$NOW" | jq -e --arg b "$BEFORE" '(.last_check | tostring) != $b and .up' > /dev/null \
|| { echo "WatchCore: monitor is DOWN or was not checked"; exit 1; }GitLab CI:
# .gitlab-ci.yml (excerpt); WATCHCORE_KEY and MONITOR_ID as CI/CD variables
watchcore-check:
stage: .post
image: alpine:3.20
script:
- apk add --no-cache curl jq
- |
URL="https://watchcore.de/api/v1/monitors/$MONITOR_ID"
BEFORE=$(curl -fsS -H "X-API-KEY: $WATCHCORE_KEY" "$URL" | jq -r .last_check)
curl -fsS -X POST -H "X-API-KEY: $WATCHCORE_KEY" "https://watchcore.de/api/v1/trigger/$MONITOR_ID"
for i in $(seq 12); do
sleep 10
NOW=$(curl -fsS -H "X-API-KEY: $WATCHCORE_KEY" "$URL")
if [ "$(echo "$NOW" | jq -r .last_check)" != "$BEFORE" ]; then break; fi
done
echo "$NOW" | jq -e --arg b "$BEFORE" '(.last_check | tostring) != $b and .up' > /dev/null \
|| { echo "WatchCore: monitor is DOWN or was not checked"; exit 1; }Status-Badges
Jeder aktive, öffentliche Monitor auf einer öffentlichen Statusseite ohne Passwort hat ein Badge als SVG, zum Beispiel für eine README. Es zeigt In Betrieb, Gestört oder Wartung in der Sprache deines Kontos und ist höchstens eine Minute alt. Den fertigen Markdown-Code je Monitor findest du unter Status Pages.
[](https://watchcore.de/status/SLUG)Heartbeat: Cronjobs und Backups überwachen
Ein Heartbeat-Monitor wartet auf Signale deines Jobs. Bleibt ein Signal länger aus als eingestellt, gibt es Alarm. So merkst du auch, wenn ein Job gar nicht mehr startet.
- Einen Monitor vom Typ Heartbeat anlegen (Tarif PRO). Die Wartezeit etwas länger wählen als den Abstand zwischen zwei Läufen.
- Die geheime Ping-URL steht danach in den Monitor-Details. Bewahre sie wie ein Passwort auf, zum Beispiel als Secret in der CI.
- Am Ende des Jobs die URL aufrufen (GET, POST oder HEAD); bei einem Fehler mit ?status=fail.
Linux mit cron:
#!/bin/sh
# /usr/local/bin/backup-with-heartbeat.sh, crontab: 0 3 * * * /usr/local/bin/backup-with-heartbeat.sh
URL="https://watchcore.de/api/v1/heartbeat/TOKEN"
if /usr/local/bin/backup.sh; then
curl -fsS -m 10 --retry 3 "$URL" > /dev/null
else
curl -fsS -m 10 --retry 3 "$URL?status=fail" > /dev/null
fiWeitere Prüfungen per cron, je ein Heartbeat-Monitor: Dienst läuft, Platte unter 90 % voll, Datenbank antwortet, Docker-Container läuft. Bleibt der Aufruf aus, gibt es Alarm.
# crontab: every 5 minutes, one heartbeat monitor per check
*/5 * * * * systemctl is-active --quiet nginx && curl -fsS -m 10 "https://watchcore.de/api/v1/heartbeat/TOKEN_NGINX" > /dev/null
*/5 * * * * [ "$(df --output=pcent / | tail -1 | tr -dc 0-9)" -lt 90 ] && curl -fsS -m 10 "https://watchcore.de/api/v1/heartbeat/TOKEN_DISK" > /dev/null
*/5 * * * * pg_isready -q -h localhost && curl -fsS -m 10 "https://watchcore.de/api/v1/heartbeat/TOKEN_DB" > /dev/null
*/5 * * * * [ "$(docker inspect -f '{{.State.Running}}' shop)" = true ] && curl -fsS -m 10 "https://watchcore.de/api/v1/heartbeat/TOKEN_DOCKER" > /dev/nullWindows mit PowerShell:
# Windows Task Scheduler
$url = "https://watchcore.de/api/v1/heartbeat/TOKEN"
try { & C:\Scripts\backup.ps1 -ErrorAction Stop } catch { $url += "?status=fail" }
Invoke-RestMethod $url | Out-NullGitHub Actions:
# at the end of a scheduled GitHub workflow
- name: Heartbeat
if: always()
run: curl -fsS -m 10 "https://watchcore.de/api/v1/heartbeat/${{ secrets.HEARTBEAT_TOKEN }}${{ job.status != 'success' && '?status=fail' || '' }}"Die Ping-URL nimmt höchstens 120 Aufrufe pro Minute an.