Skip to content

How to manage Alert Receivers via API

Last updated on

You can configure the following possible receivers:

  • email
  • webhook (Google Chat, Microsoft Teams or other)
  • Opsgenie

To create an email receiver, execute a POST request to the receiver endpoint. With the following HTTP message body, you have the minimum configuration to add a new email receiver:

Terminal window
stackit curl -X POST "https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/alertconfigs/receivers" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data '{"name":"MyEmailReceiver","emailConfigs":[{"to":"emailTo@your-company.com"}]}'

Per default, Observability will send all messages from a STACKIT Observability email address. Optionally, you can configure your own email address as the sender address. In this case, you need to provide SMTP credentials in your request body:

{
"name": "MyEmailReceiver",
"emailConfigs": [
{
"to": "emailTo@your-company.com",
"from": "observability-alerting@your-company.com",
"smarthost": "your-company.com",
"authUsername": "username",
"authPassword": "password",
"authIdentity": "yourIdentity"
}
]
}

More information about the API and the request body can be found in the API documentation.

You will also need to create an alert config route for the receiver you just created. Ensure the "receiver" name matches the one you defined above.

Terminal window
stackit curl -X POST "https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/alertconfigs/routes" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data '{"receiver":"MyEmailReceiver","groupBy":["LatencyHigh"],"groupWait":"30s","groupInterval":"5m","repeatInterval":"4h"}'

More information on the expected request body can be found in the API documentation.

You can use any compatible webhook. To create a webhook receiver, execute a POST request to the receiver endpoint. Below is an example of a complete command for a custom webhook:

Terminal window
stackit curl -X POST "https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/alertconfigs/receivers" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data '{"name":"MyWebhookReceiver","webHookConfigs":[{"url":"https://your-webhook-url.com"}]}'

If you are using Google Chat or Microsoft Teams, replace the JSON data in the --data parameter with one of the following structures (notice the specific parameters for each platform). More information can be found in the API documentation.

{
"name": "MyGoogleChatWebhookReceiver",
"webHookConfigs": [
{
"googleChat": true,
"url": "https://chat.googleapis.com/v1/spaces/xxx/messages?key=xxx&token=xxx"
}
]
}
{
"name": "MyMsTeamsWebhookReceiver",
"webHookConfigs": [
{
"msTeams": true,
"url": "https://your-teams-webhook-url.com"
}
]
}

Just like with the email receiver, you need to create an alert config route for the webhook receiver you just created. Please make sure to use the exact same name of the receiver.

Terminal window
stackit curl -X POST "https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/alertconfigs/routes" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data '{"receiver":"MyReceiverName","groupBy":["LatencyHigh"],"groupWait":"30s","groupInterval":"5m","repeatInterval":"4h"}'

You can also configure your own Opsgenie. With the following HTTP message body, you have the minimum configuration to add a new Opsgenie receiver:

Terminal window
stackit curl -X POST "https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/alertconfigs/receivers" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data '{"name":"MyOpsGenieReceiver","opsgenieConfigs":[{"apiKey":"yourApiKey","apiUrl":"yourApiURL","tags":"TagsYouWantToHave","httpConfig":{"proxyUrl":"yourProxyServerURL"}}]}'

More information about the API and the request body can be found in the API documentation.

Terminal window
stackit curl -X POST "https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/alertconfigs/routes" \
-H "accept: application/json" \
-H "Content-Type: application/json" \
--data '{"receiver":"MyOpsGenieReceiver","groupBy":["LatencyHigh"],"groupWait":"30s","groupInterval":"5m","repeatInterval":"4h"}'

Basic syntax checking is provided by the Observability API.

Grafana visualizes triggered Alerts:

  • Log in to Grafana.
  • Select the function Explore.
  • Select the data source Thanos.
  • Choose the metric ALERTS.
  • Visualize the metric by clicking Run query.

If you don’t get any emails, please check your SPAM folder. Sometimes mail agents filter alert emails because they contain hyperlinks. Additionally, you should check if you’re using a global configuration for all email receivers. If yes, verify the global section of the response from the GET Alertconfigs endpoint. It should look like the response example in the next chapter.

By default, Observability sends all emails from a STACKIT Observability address. You can optionally configure your own email as a sender address. In this case, you need to provide SMTP credentials. You can either configure your individual email sender address globally or on a per-email receiver basis. To set it globally, use the global section of the body sent to the PUT Alertconfigs endpoint.

{
"route": {
"receiver": "email-example-receiver",
"groupWait": "30s",
"groupInterval": "5m",
"repeatInterval": "4h"
},
"receivers": [
{
"name": "email-example-receiver",
"emailConfigs": [
{
"to": "your-email@example.com",
"sendResolved": true
}
]
}
]
}

Afterward, you can check the configuration using the GET Alertconfigs endpoint. You should see a global section as shown below. Attributes masked by ***** indicate that our credentials will be used to send emails.

"global": {
"resolveTimeout": "5m",
"smtpFrom": "our-email@example.com",
"smtpSmarthost": "*****",
"smtpAuthUsername": "*****",
"smtpAuthPassword": "*****",
"smtpAuthIdentity": "*****"
}

You can consult the API documentation to learn how to configure and update an existing recipient.

To read all your receiver configurations, execute an HTTP GET request using stackit curl:

Terminal window
stackit curl -X GET "https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/alertconfigs/receivers" \
-H "accept: application/json"

More information on this can be found in the API documentation.

To delete a specific receiver configuration, execute an HTTP DELETE request to the exact receiver endpoint (replace RECEIVER_NAME with your specific receiver):

Terminal window
stackit curl -X DELETE "https://argus.api.eu01.stackit.cloud/v1/projects/$PROJECT_ID/instances/$INSTANCE_ID/alertconfigs/receivers/$RECEIVER_NAME" \
-H "accept: application/json"