I'm setting up a stack of Grafana, Prometheus and the Prometheus alert manager via docker, heavily relying on provisioning of all the configuration such as alert rules, dashboards and so on.
Because I will have to use the Prometheus alert manager, I want Grafana to be configured such, that it sends its alerts to the external alert manager.
Is there a possibility of setting this via any kind of configuration files instead of having to go on the Grafana Page and changing it manually in the Admin tab in Alerting?
I checked around a bit, but neither on the page about Grafana Configuration nor about Alert Provisioning I could find anything that would sound fitting to me.
Thanks.
I found a solution for my problem and I though I'll share it with you in case somebody ever needs something like it.
It is possible to set the necessary config via Grafana's endpoint at http://grafana/api/v1/ngalert/admin_config
, to which you have to post the value '{"alertmanagersChoice":"external"}'
. (respectively internal
for the internal alert manager or all
for both.)
So basically I just define another container in the docker-compose.yml with the curlimages/curl:latest
image, that sends exactly this message to my Grafana container, as soon as it's fully started:
services:
...
grafana:
image: grafana/grafana:latest-ubuntu
healthcheck:
test: ["CMD-SHELL", "curl -f localhost/api/health"]
interval: 10s
retries: 10
...
config_container:
container_name: config_container
depends_on:
grafana:
condition: service_healthy
image: curlimages/curl:latest
networks:
- grafana
command: >-
-X POST --user admin:admin http://grafana/api/v1/ngalert/admin_config -H "Content-Type: application/json" -d '{"alertmanagersChoice":"external"}'
It might not be the perfect solution, as manual changes to the chosen alert manager done via the UI will be overwritten every time I start everything, but for my requirements that's good enough currently.