NGalert / Grafana 8 alert feature: How to export / import alerts as yml/json?

Thanks for the script!

I was able to export the alerts to json. I am trying to import this exported json into different grafana instance. In the exported json i saw datasoruceuid (which is uid of datasource so no issue here) but where will i get uid and namespace_uid information? What other changes to json file i need to make?

Thanks
M

I was able to use the API to GET all my alerts (created manually in the Grafana UI) by logging into Grafana and then using: http://[IP_ADDRESS]/api/ruler/grafana/api/v1/rules. This gave me a json that contained all of my alerts created in Grafana. I then tried to upload that json directly into another env using curl -XPOST -H "Authorization: Bearer [MY_TOKEN]" -i [MY_URL]/api/v1/provisioning/alert-rules --data-binary @./api-log-alerts.json -H "Content-Type: application/json which failed because the API does not take the entire group at a time (WE NEED THAT FEATURE!). So I created a new JSON with a single rule (that I cut and pasted from the rules section of the main file), and was able to upload the file after a couple fixes to remove non-mandetory fields, and I got this response:

HTTP/1.1 201 Created
Cache-Control: no-cache
Content-Type: application/json
Expires: -1
Pragma: no-cache
X-Content-Type-Options: nosniff
X-Frame-Options: deny
X-Xss-Protection: 1; mode=block
Date: Thu, 26 Jan 2023 17:25:53 GMT
Content-Length: 1452
Via: 1.1 google

The interesting thing is that the alert created with the API command DOES NOT APPEAR in the Grafana UI Alert console list [MY_URL]/alerting/list and it does not appear in the API call to get all of the alerts, but they are still firing!!!

Has anyone here successfully created an alert using the API? Is there a way to configure these as config files in my cluster so they just exist when I deploy the pod?

Thanks

(post deleted by author)

I tried to move alerts from one Grafana instance to another and it didnā€™t work.
as mentioned above, I managed to use the API to GET all alerts however when we tried to POST them to other Grafana instance it didnā€™t work. even when we tried to POST only one alert it didnā€™t appear in Grafana GUI.
I use Grafana ver 9.2.2

Hello! This feature is in development, and you can follow its progress here https://github.com/grafana/grafana/pull/58623

Did you find out how to do this?

Hi! This feature is available in Grafana 9.4. Create and manage alerts: 12 ways it's easier in Grafana Alerting

i am trying
I have the same issue. Any updateā€¦?

how to imported the alerts in grafana 9.4 version

Is there a way to import exported alerts (9.4 version)?

Hello. yes, It is possible, check this file: values.yaml and then search for ā€œalertingā€ and you will find your answer

1 Like