The Grafana API for alerting is in a state of flux and it is not currently capable of supporting
- Export existing Grafana Managed Alerts from Grafana A
- Import Grafana Managed Alerts to Grafana B
It is possible to export via a db migration script but there are a few caveats
- dashboardUid folderUid must be identical in Grafana A and Grafana B.
- datasources must be identical in Grafana A and Grafana B.
If Grafana provisioning was used to migrate dashboards and folders from Grafana A to
Grafana B, then all you need to do is export/import the contents of the alert_rule
table. This script is has been tested with Grafana 9.3.0. This script will be obsolete
when Grafana 9.4.0 ships and Grafana 9.4.0-beta has better support for alert rule export/import.
Make sure your python environment has requirements.txt dependencies installed. This script was tested with Python 3.10 and probably won't run on Python 2.x.
Create a .env file that has your import/export DB connection credentials. This script uses postgres but it can support mysql or sqllite, may require adding db package to python environment.
import_db_connect_string=postgresql://[username:password]@localhost:5432/grafanaA
export_db_connect_string=postgresql://[username:password]@localhost:5432/grafanaB
Create dashboards.yaml entries for all folders that contain alerts you would like to migrate.
Make sure Grafana A and Grafana B have the same datasource instances. The following items need to be the same in both servers:
- name
- type
- uid
Run alert_migration.py. If there are no errors, then you should see new alerts in Grafana B.
python ./alert_migration.py
- No alerts in Grafana B - If there is a folder or datasource definition mismatch then you will see WARN messages in the grafana logs.
- SQL errors - The script will either migrate ALL alerts or rollback. Duplicate
alert_rule
ids are the most common reason for script failure.