Grafana 8 Alerts - Configuring the integrated Alertmanager

TLDR: Is there a way currently, or planned, to create receivers and routes used by the integrated Alertmanager? via provisioning or an API endpoint?

I’ve figured out how to export/import the new rules via the documented API (using POST to /api/ruler/grafana/api/v1/rules/), however, I have not found a way to export receivers/routes (‘Contact Points’ and ‘Notification Policies’, respectively) and create them. There is no API endpoint that I can find, nor any provisioning exposed to do so.

I can see these settings under the “Admin” tab of the Alerting section:

The configuration json in this window is what I need, but when I try and provision a new instance of Grafana with ngalert enabled and paste/save the json in here, it fails as none of the actual objects exist.

As an aside, the API endpoint to POST rules for creation is not idempotent, which I was really hoping for with this new API. This is also the case for the rest of the Grafana API, which is a real pain when trying to provision systems with the same configuration, as we first have to hit the API and pull everything to see if it exists, THEN create objects.

2 Likes

I’ve managed to do it by alertmanager api:

curl -X 'POST' \
  'http://grafana.staged-by-discourse.com/api/alertmanager/grafana/config/api/v1/alerts' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "template_files": {},
  "alertmanager_config": {
    "route": {
      "receiver": "receiverName"
    },
    "templates": null,
    "receivers": [
      {
        "name": "receiverName",
        "grafana_managed_receiver_configs": [
          {
            "name": "receiverName",
            "type": "email",
            "disableResolveMessage": false,
            "settings": {
              "addresses": "<email@gmail.com>",
              "singleEmail": false
            },
            "secureFields": {}
          },
          {
            "name": "receiverName",
            "type": "telegram",
            "disableResolveMessage": false,
            "settings": {
              "chatid": "123456"
            },
            "secureSettings": {
                "bottoken": "bottokenId"
            }
          }
        ]
      }
    ]
  }
}