Hello I struggle to convert the response from an API call of an alert created manually (see it at the end of this post) to an alert provisioning file like there is an example here: Create and manage alerting resources using file provisioning | Grafana documentation.
I ended up having a look at this post, which contains a similar working example: Grafana requires time range for alert rule creation with instant PromQL quieriy - #6 by knikos
Please find below the alert provisioning file I created. The error seen in the log is “Error:failed to execute conditions: failed to execute query A: bad_data: 1:1: parse error: no expression found in input”. Does someone has a clue to fix it?
alert provisioning file
apiVersion: 1
groups:
- orgId: 1
name: disk-pressure
folder: alerts
interval: 60s
rules:
- uid: kappa_id_1
title: Disk Pressure
condition: B
data:
- refId: A
datasourceUid: 'PCB1AD6408E75C168'
queryType: ''
relativeTimeRange:
from: 600
to: 0
model:
editorMode: code
expression: "sum(kube_node_status_condition) by (node)"
intervalMs: 1000
maxDataPoints: 43200
refId: A
legendFormat: __auto
range: true
- refId: B
queryType: ''
relativeTimeRange:
from: 0
to: 0
datasourceUid: "-100"
model:
conditions:
- evaluator:
params:
- 0.5
type: gt
operator:
type: and
query:
params:
- A
reducer:
type: max
type: query
datasource:
type: __expr__
uid: "-100"
expression: A
intervalMs: 1000
maxDataPoints: 43200
refId: B
type: classic_conditions
noDataState: NoData
for: 20s
annotations:
summary: "Disk pressure"
labels:
team: pressure
json response from the API call /api/v1/provisioning/alert-rules/xDkNqSJVk
{
"id": 1,
"uid": "xDkNqSJVk",
"orgID": 1,
"folderUID": "CaCIqI1Vz",
"ruleGroup": "system",
"title": "Disk pressure",
"condition": "B",
"data": [
{
"refId": "A",
"queryType": "",
"relativeTimeRange": {
"from": 600,
"to": 0
},
"datasourceUid": "PCB1AD6408E75C168",
"model": {
"editorMode": "code",
"expr": "sum(kube_node_status_condition) by (node)",
"hide": false,
"intervalMs": 1000,
"legendFormat": "__auto",
"maxDataPoints": 43200,
"range": true,
"refId": "A"
}
},
{
"refId": "B",
"queryType": "",
"relativeTimeRange": {
"from": 0,
"to": 0
},
"datasourceUid": "-100",
"model": {
"conditions": [
{
"evaluator": {
"params": [
0.5,
0
],
"type": "gt"
},
"operator": {
"type": "and"
},
"query": {
"params": [
"A"
]
},
"reducer": {
"params": [
],
"type": "max"
},
"type": "query"
}
],
"datasource": {
"name": "Expression",
"type": "__expr__",
"uid": "__expr__"
},
"expression": "A",
"hide": false,
"intervalMs": 1000,
"maxDataPoints": 43200,
"refId": "B",
"type": "classic_conditions"
}
}
],
"updated": "2023-02-13T10:44:02Z",
"noDataState": "NoData",
"execErrState": "Alerting",
"for": "20s",
"annotations": {
"summary": "Disk pressure"
},
"labels": {
"type": "pressure"
}
}