gdg
gdg copied to clipboard
Add support to backup/restore alert rules
Problem: I use grafana alerting system where I put alert rules in grafana directly. I would like them also to be backed-up like everything else
Solution: Having a way to backup alert rules like dashboards, datasources, etc
alternatives: grafana alerts exporter. this is a bit basic though, and I already appreciate very much gdg. I would like to be able to use only gdg for both dashboards and alert rules
There's a few tickets that are somewhat blocked right now. There's an official go client built based on the swagger / OpenAPI definition that's being worked on. https://github.com/grafana/grafana/issues/47827.
Once that's finalized, I plan on moving GDG over to it which opens up a lot more options as to what to support.
Currently we're using: https://github.com/grafana-tools/sdk. Anything on there I'm happy to add which is usually trivial. Otherwise need to patch the SDK, wait for upstream to pull that in. Once those changes are approved I can pull them into GDG.
I'll check in with the grafana team to see what the status is. Though I assume with the ticket still open it's not official yet.
This is no longer blocked, will try to prioritize this, please vote on any feature you really want to see worked on.
@fayak I'm going to merge all these changes into a single ticket. https://github.com/esnet/gdg/issues/134 I think will encompass all of these changes. Please watch that ticket
Setup
With
- gdg 0.5.1
To backup Grafana v7.2.0
I run
gdg backup alertnotifications download
gdg backup connections download
gdg backup dashboards download
gdg backup folders download
gdg backup organizations download
gdg backup teams download
gdg backup users download
To restore in Grafana v7.5.17
I run
gdg backup organizations upload
gdg backup folders upload
gdg backup teams upload
gdg backup users upload
gdg backup connections upload
gdg backup alertnotifications upload
gdg backup dashboards upload
Problem
In Grafana v7.5.17
where I restored from the Grafana v7.2.0
backup, although I'm able to see the the alerts configured in individual panels in the Alert
tab when I edit the panel, I cannot see any alert rule under http://<grafana_url>/alerting/list
Moreover, the "heart" icon is missing from the panel that has the configured alert
Would you know why this might happen and how to solve it ?
UPDATE
While trying different things I noticed that upon saving (without changing anything) the restored dashboards brings back the alert heart icon on the panel it was configured against as well as the the alert rules in the alert rule list
Investigating further led me to discover that Grafana actualy has a different JSON schema when exporting/importing through the UI interface and another one through the API
My assumption is that gdg uses chromium the dashboard/import API instead of the grafana dashboard api (api/dashboards/db
) which causes the issue
Fix
In order to fix the alert issue I redownloaded all dashboard through the Grafana HTTP api this time and reuploaded them through the same api endpoint after merging the json with the following {overwrite: true, dashboard: {id: null}}
based on this gist
- https://gist.github.com/crisidev/bd52bdcc7f029be2f295
Using jq
in the same way but using the gdg downloaded dashboard instead of the ones downloaded from the Grafana http API does not work because they don't have the same schema and produces the following error
-
[{"fieldNames":["Dashboard"],"classification":"RequiredError","message":"Required"}]
If one performs the jq operation and opens the edited json will realize that there is no top-level dashboard
object and the operation just adds a nested object with the provided key values
UPDATE
Moved to new issue under : https://github.com/esnet/gdg/issues/247