Reputation: 11
I started using Grafana API for creating new alerts and I start to lose it...
My goal:
Results of using "/api/v1/provisioning/alert-rules/:uid/export " endpoint
According to the Grafna documentation, I need to use the /api/v1/provisioning/alert-rules/:uid/export
endpoint to get the JSON appropriate for provisioning.
But whenever I get this JSON and edit only the 'title' and 'uid' ('I set 'uid' to null). then I POST this modifed JSON via API and I recive
Error : 400, ErrorMessage: {"message":"invalid alert rule: no queries or expressions are found","traceID":""}
But I didn't even edit the query or expressions, I only edited the title and I set the alert uid to null for example.
Documentation: https://grafana.com/docs/grafana/latest/alerting/set-up/provision-alerting-resources/export-alerting-resources/
JSON I get from the /export endpoint
{
"apiVersion": 1,
"groups": [
{
"orgId": 1,
"name": "1min",
"folder": "test",
"interval": "1m",
"rules": [
{
"uid": "xxx",
"title": "tester",
"condition": "C",
"data": [
{
"refId": "A",
"relativeTimeRange": {
"from": 600,
"to": 0
},
"datasourceUid": "xxxxx",
"model": {
"datasource": {
"type": "influxdb",
"uid": "xxxx"
},
"groupBy": [
{
"params": [
"$__interval"
],
"type": "time"
},
{
"params": [
"null"
],
"type": "fill"
}
],
"intervalMs": 1000,
"maxDataPoints": 43200,
"measurement": "Amount",
"orderByTime": "ASC",
"policy": "default",
"query": "SELECT count(\"value\") FROM \"Amount_counter\" WHERE (\"currency\"::tag = 'BIT') AND $timeFilter GROUP BY time($__interval) fill(null)",
"rawQuery": true,
"refId": "A",
"resultFormat": "time_series",
"select": [
[
{
"params": [
"value"
],
"type": "field"
},
{
"params": [],
"type": "count"
}
]
],
"tags": [
{
"key": "currency::tag",
"operator": "=",
"value": "BIT"
}
]
}
},
{
"refId": "B",
"relativeTimeRange": {
"from": 600,
"to": 0
},
"datasourceUid": "__expr__",
"model": {
"conditions": [
{
"evaluator": {
"params": [],
"type": "gt"
},
"operator": {
"type": "and"
},
"query": {
"params": [
"B"
]
},
"reducer": {
"params": [],
"type": "last"
},
"type": "query"
}
],
"datasource": {
"type": "__expr__",
"uid": "__expr__"
},
"expression": "A",
"intervalMs": 1000,
"maxDataPoints": 43200,
"reducer": "sum",
"refId": "B",
"settings": {
"mode": "dropNN"
},
"type": "reduce"
}
},
{
"refId": "C",
"relativeTimeRange": {
"from": 600,
"to": 0
},
"datasourceUid": "__expr__",
"model": {
"conditions": [
{
"evaluator": {
"params": [
5
],
"type": "gt"
},
"operator": {
"type": "and"
},
"query": {
"params": [
"C"
]
},
"reducer": {
"params": [],
"type": "last"
},
"type": "query"
}
],
"datasource": {
"type": "__expr__",
"uid": "__expr__"
},
"expression": "B",
"intervalMs": 1000,
"maxDataPoints": 43200,
"refId": "C",
"type": "threshold"
}
}
],
"noDataState": "NoData",
"execErrState": "Error",
"for": "5m",
"labels": {
"owner": "me",
"severity": "warning"
},
"isPaused": false
}
]
}
]
}
Results of using "/api/v1/provisioning/alert-rules/:uid"
I started downloading JSON via endpoint/api/v1/provisioning/alert-rules/:uid
but according to the documentation "Note that the JSON format from most of the following endpoints is not fully compatible with provisioning via configuration JSON files." But guess what... I downoland it from the endpoint, I edit the title and query, set up 'id' and 'uid' to 'null' (so it can be automaticly assigned for new alert) and it worked.
Documentation: https://grafana.com/docs/grafana/latest/developers/http_api/alerting_provisioning/
My Question I don't understand why this is happening, it should work the other way around. Can someone explain to me why I am getting an "Error" when trying to send JSON which should be suitable for provisioning?
Upvotes: 0
Views: 107