Zum Inhalt springen

Loki-Alerts per Observability-API verwalten

Zuletzt aktualisiert am

Eine vollständige Liste aller verfügbaren Endpunkte, Parameter und Schemata finden Sie in der STACKIT Observability Logs API-Spezifikation.

So erstellen Sie Loki-Alerts mit einer neuen Alert-Gruppe

Abschnitt betitelt „So erstellen Sie Loki-Alerts mit einer neuen Alert-Gruppe“

Um eine neue Loki-Alert-Gruppe zu erstellen, müssen Sie eine HTTP-POST-Anfrage an den Endpunkt logs-alertgroups senden.

Beispiel für einen Request-Body:

{
"name": "YourAlertGroupName",
"interval": "30m",
"rules": [
{
"alert": "error",
"expr": "count_over_time({app=\"yourAppName\", severity=\"critical\"} |~ \".*error*\"[5m]) > 25",
"for": "0m",
"labels": {
"app": "yourAppName",
"project_name": "yourProjectName",
"id": "yourAppId",
"severity": "critical"
},
"annotations": {
"summary": "Too many errors are coming frequently!"
}
}
]
}

Befehl:

Terminal-Fenster
stackit curl -X POST "[https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/logs-alertgroups](https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/logs-alertgroups)" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data '{"name":"YourAlertGroupName","interval":"30m","rules":[{"alert":"error","expr":"count_over_time({app=\"yourAppName\", severity=\"critical\"} |~ \".*error*\"[5m]) > 25","for":"0m","labels":{"app":"yourAppName","project_name":"yourProjectName","id":"yourAppId","severity":"critical"},"annotations":{"summary":"Too many errors are coming frequently!"}}]}'

Überprüfung der Erstellung von Loki-Alert-Gruppen und Alert-Rules

Abschnitt betitelt „Überprüfung der Erstellung von Loki-Alert-Gruppen und Alert-Rules“

Sie können die Erstellung Ihrer Loki-Alert-Gruppe und der Alert-Rules überprüfen, indem Sie eine HTTP-GET-Anfrage an denselben Endpunkt senden.

Befehl:

Terminal-Fenster
stackit curl -X GET "[https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/logs-alertgroups](https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/logs-alertgroups)" \
-H "accept: application/json"

So erstellen Sie Loki-Alerts mit einer bestehenden Alert-Gruppe

Abschnitt betitelt „So erstellen Sie Loki-Alerts mit einer bestehenden Alert-Gruppe“

Um einen neuen Alert zu einer bereits bestehenden Alert-Gruppe hinzuzufügen, müssen Sie die Gruppe aktualisieren, indem Sie den vollständigen Konfigurations-Request-Body bereitstellen.

  1. Rufen Sie die bestehende Konfiguration ab: Rufen Sie zuerst das aktuelle Setup Ihrer Alert-Gruppe ab, indem Sie eine GET-Anfrage ausführen (wie oben gezeigt). Kopieren Sie die JSON-Antwort.

  2. Passen Sie den Payload an: Fügen Sie Ihre neue Alert-Regel zum rules-Array im kopierten JSON-Payload hinzu.

  3. Aktualisieren Sie die Alert-Gruppe: Senden Sie den geänderten JSON-Payload über eine HTTP-PUT-Anfrage, um die Gruppe zu aktualisieren (ersetzen Sie <GROUP_NAME> durch den Namen Ihrer spezifischen Alert-Gruppe):

    Terminal-Fenster
    stackit curl -X PUT "[https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/logs-alertgroups/](https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/logs-alertgroups/)<GROUP_NAME>" \
    -H "accept: application/json" \
    -H "Content-Type: application/json" \
    --data '<YOUR_MODIFIED_JSON_PAYLOAD>'