Annotations not activated when importing dashboard JSON

I am trying to programmatically add annotations to panels. They should query PostgreSQL and display annotations in my panels. I am able to create panels programmatically, and to add annotation for my datasource configured for Postgres. When I add annotations through Grafana UI everything if fine. I create same JSON as exported from Grafana, and post it programmatically via REST API. Panel gets created/updated but annotations won’t appear, and UI shows an empty list of annotations. Same thing happens when I simply import JSON produced by Grafana export: panel is re-created but annotations are not displayed. ‘View JSON’ for imported dashboard shows all annotations setup but it is just being ignored.

Can anyone help me, or confirm that annotations are possible to add only through user interface? For me that would be the end of the project because our system includes thousands of remote controllers and it is not feasible to setup them all by hand.

Here is the JSON I used. Despite somewhat involved SQL code for annotations, it works when installed thru the GUI.

{
“annotations”: [
{
“builtIn”: 1,
“datasource”: “-- Grafana --”,
“enable”: true,
“hide”: true,
“iconColor”: “rgba(0, 0, 255, 1)”,
“limit”: 100,
“name”: “Annotations & Alerts”,
“showIn”: 0,
“type”: “dashboard”
},
{
“datasource”: “ffa_datasource”,
“enable”: true,
“hide”: true,
“iconColor”: “rgba(255,0, 0, 1)”,
“limit”: 100,
“name”: “fire”,
“rawQuery”: “\n select \n min(time1) as time, \n max(time1) as timeend, \n ‘ALARM: fire in aa’ as text, \n ‘fire’ as tags \n from ( \n select \n max(t2.t) as time0, \n min(t1.t) as time1 \n from \n ts___water_meter as t1, \n ts___water_meter as t2 \n where\n __timeFilter(t1.t) \n and t1.rtu_descriptor_id=1 \n and t2.rtu_descriptor_id=1 \n and t1.alarms_bit_1>t2.alarms_bit_1 \n and t1.t>t2.t \n group by t1.t \n order by t1.t\n ) as innerselect \n group by time0", "showIn": 79, "tags": [], "type": "tags" } ], "editable": true, "gnetId": null, "graphTooltip": 0, "id": 79, "links": [], "panels": [ { "aliasColors": {}, "bars": false, "dashLength": 10, "dashes": false, "datasource": "ffa_datasource", "description": "", "fieldConfig": { "defaults": { "custom": {} }, "overrides": [] }, "fill": 1, "fillGradient": 0, "gridPos": { "h": 10, "w": 12, "x": 0, "y": 0 }, "hiddenSeries": false, "id": 1, "legend": { "avg": false, "current": false, "max": false, "min": false, "show": true, "total": false, "values": false }, "lines": true, "linewidth": 1, "nullPointMode": "null", "options": { "alertThreshold": true }, "percentage": false, "pluginVersion": "7.3.7", "pointradius": 2, "points": false, "renderer": "flot", "seriesOverrides": [], "spaceLength": 10, "stack": false, "steppedLine": false, "targets": [ { "format": "time_series", "group": [], "metricColumn": "none", "rawQuery": false, "rawSql": "SELECT\n t AS \"time\",\n x,\n y,\n z\n FROM ts___water_meter\nWHERE\n __timeFilter(t) AND\n rtu_descriptor_id = 1\nORDER BY 1”,
“refId”: “A”,
“select”: [
[
{
“params”: [
“x”
],
“type”: “column”
}
],
[
{
“params”: [
“y”
],
“type”: “column”
}
],
[
{
“params”: [
“z”
],
“type”: “column”
}
]
],
“table”: “ts___water_meter”,
“timeColumn”: “t”,
“timeColumnType”: “timestamptz”,
“where”: [
{
“name”: “$__timeFilter”,
“params”: [],
“type”: “macro”
},
{
“datatype”: “int4”,
“name”: “”,
“params”: [
“rtu_descriptor_id”,
“=”,
1
],
“type”: “expression”
}
]
}
],
“thresholds”: [],
“timeFrom”: null,
“timeRegions”: [],
“timeShift”: null,
“title”: “aa”,
“tooltip”: {
“shared”: true,
“sort”: 0,
“value_type”: “individual”
},
“type”: “graph”,
“xaxis”: {
“buckets”: null,
“mode”: “time”,
“name”: null,
“show”: true,
“values”: []
},
“yaxes”: [
{
“format”: “short”,
“label”: null,
“logBase”: 1,
“max”: null,
“min”: null,
“show”: true
},
{
“format”: “short”,
“label”: null,
“logBase”: 1,
“max”: null,
“min”: null,
“show”: true
}
],
“yaxis”: {
“align”: false,
“alignLevel”: null
}
}
],
“refresh”: false,
“schemaVersion”: 26,
“style”: “dark”,
“tags”: [
“templated”
],
“templating”: {
“list”: []
},
“time”: {
“from”: “2021-01-28T12:53:20.251Z”,
“to”: “2021-01-28T17:01:32.237Z”
},
“timepicker”: {
“hidden”: false
},
“timezone”: “browser”,
“title”: “FFA”,
“uid”: “OoyHJWTMz”,
“version”: 21
}

1 Like

Did you ever get this to work?
I’m struggling with the same.

This topic was automatically closed after 365 days. New replies are no longer allowed.