Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to backup/restore alert rules #108

Closed
fayak opened this issue Oct 14, 2022 · 4 comments
Closed

Add support to backup/restore alert rules #108

fayak opened this issue Oct 14, 2022 · 4 comments

Comments

@fayak
Copy link

fayak commented Oct 14, 2022

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

@safaci2000
Copy link
Contributor

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. grafana/grafana#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.

@safaci2000 safaci2000 added the BLOCKED blocked, cannot be implemented due to an external factor. label Oct 14, 2022
@safaci2000 safaci2000 removed the BLOCKED blocked, cannot be implemented due to an external factor. label Mar 30, 2023
@safaci2000
Copy link
Contributor

This is no longer blocked, will try to prioritize this, please vote on any feature you really want to see worked on.

@safaci2000
Copy link
Contributor

@fayak I'm going to merge all these changes into a single ticket. #134 I think will encompass all of these changes. Please watch that ticket

@laertis
Copy link

laertis commented Feb 13, 2024

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

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 : #247

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants