🎓 A1Learner
🔍
0 of 50 lessons completed

Grafana: Contact Points and Notification Policies

A contact point is the place a Grafana alert sends its notification. A notification policy decides which alerts go to which contact point.

List the contact points with the API

Grafana stores contact points in its own database. Before any receiver exists, the list is empty.

curl -s -u admin:admin http://127.0.0.1:13105/api/v1/provisioning/contact-points

Create a webhook contact point

A webhook contact point posts the alert as JSON to a URL you control.

curl -s -X POST -u admin:admin -H 'Content-Type: application/json' -d '{"name":"webhook-lab","type":"webhook","settings":{"url":"http://127.0.0.1:19126/hook"}}' http://127.0.0.1:13105/api/v1/provisioning/contact-points

Point the default policy at the webhook

The default policy starts with an empty receiver. This call points it at the new contact point.

curl -s -X PUT -u admin:admin -H 'Content-Type: application/json' -d '{"receiver":"webhook-lab","group_by":["grafana_folder","alertname"]}' http://127.0.0.1:13105/api/v1/provisioning/policies

Example

curl -s -u admin:admin http://127.0.0.1:13105/api/v1/provisioning/contact-points | python3 -c "import json,sys; print([c['name'] for c in json.load(sys.stdin)])"

Key points

  • Contact point: a named receiver for alerts, such as an email address or a webhook URL.
  • Grafana sends the alert to the contact point when the alert rule fires.
  • Notification policy: a set of rules that matches alerts by label and picks a contact point.
  • A policy can route critical alerts to one receiver and warning alerts to another.
  • Labels on the alert decide the route, so label discipline matters here too.
  • Prometheus alerting fires rules in Prometheus and sends them to Alertmanager.
  • Grafana alerting fires rules in Grafana and sends them through its own contact points.
  • Use Prometheus alerting when the alerts live with the Prometheus rules and Alertmanager.
  • Use Grafana alerting when the alert needs data from more than one data source.

In this example, Grafana lists the contact points on the lab server and the list holds one entry, the webhook-lab receiver created earlier. The alert pipeline now has a real destination. A firing alert with the matching label reaches that webhook instead of going nowhere.

Note

One alert should reach one receiver. Two routes for the same alert mean two pages for one problem.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

What does a notification policy decide in Grafana alerting?