/var/lib/grafana/dashboards/ files lose their Alerts when loaded

Good day, I am very keen to get a reproducible installation of Grafana (via scripted automation) for a dashboard (/var/lib/grafana/dashboards/mydash.json) that includes Alerts. Unfortunately, it seems like alerts and notifications are lost, never activated on first startup of Grafana in this case.

First I built a working Grafana dashboard in 4.2.0.1. I included Alerts via Notification to Slack in this dashboard. Tested and it’s all good. Then I exported the dashboard as a JSON file.

Through cluster setup automation, I’m building another cluster, installing Grafana + Graphite on a brand-new node, and then:

  1. Adding the graphite data source to Grafana via curl to API; /api/datasources Works great!
  2. Adding the slack notification channel to Grafana via curl to API: /api/alert-notifications Works great!
  3. Replacing all $DS_GRAPHITE with ‘graphite’ in mydash.json and then placing into /var/lib/grafana/dashboards (path enabled in grafana.ini). Works great. On login I see my dashboard is available automatically.

BUT… the alerts that I had first placed into the dashboard don’t work. In particular, I see the red line and shading on my chart, but the ‘Heart’ icon shows as white (i.e. not active). If I edit the chart, the Alerts area only shows ‘Create Alert’ button, not the existing Alert to edit.

WORKAROUND: If I Save As the mydash.json in Grafana to a new dashboard, then re-create all the alerts, then save that again, in a few minutes the Heart indicators go green telling me that the copied dashboard with new alerts is executing them.

QUESTION: How can one import (into a completely new install of Grafana) both a dashboard and all its working alerts?

Sadly Grafana is not supporting alerting for file based dashboards.

We are depricating dashboard.json feature, replacing it with something that can sync dashboards from file to dashboards in database (and prevent changes in UI). The dashboard.json feature is a bit broken right now as these dashboard have no dashboard id and cannot be starred and set as home dashboard, so we are going to redesign this and deprecate it.

In the mean time I recommend you use this tool to import / sync dashboard from file to Grafana db:

2 Likes