I am creating an alert for grafana using this endpoint POST /api/v1/provisioning/alert-rules
with the bellow request body. The created alert is shown in the UI, but on the health column it's showing either an error, with the message failed to execute conditions: data source not found
, or nodata
.
The alert structure used is: a query, like sum by(instance) (<metric>{job=<jobname>}), a expression of type reducer and a expression of type math.
Grafana version: 9.1.6
Request body:
{
orgID: 1,
folderUID: '<fodler_uid>',
ruleGroup: '<rule_group>',
title: '<alert_name>/de6835e3-148f-4cef-9b53-9fcf0afa1f65',
condition: 'C',
noDataState: 'NoData',
execErrState: 'Error',
data: [
{
refId: 'A',
queryType: '',
relativeTimeRange: { from: 300, to: 0 },
datasourceUid: '<datasource_id>',
model: {
expr: 'sum by(instance) (<metric_name>{job="<environment_name>"})',
hide: false,
intervalMs: 1000,
maxDataPoints: 43200,
refId: 'A'
}
},
{
refId: 'B',
queryType: '',
relativeTimeRange: { from: 0, to: 0 },
datasourceUid: '-100',
model: {
conditions: [
{
evaluator: { params: [ 3 ], type: 'gt' },
operator: { type: 'and' },
query: { params: [ 'A' ] },
reducer: { params: [], type: 'last' },
type: 'query'
}
],
datasource: { type: '__expr__', uid: '-100' },
expression: 'A',
hide: false,
intervalMs: 1000,
maxDataPoints: 43200,
reducer: 'last',
refId: 'B',
type: 'reduce'
}
},
{
refId: 'C',
queryType: '',
relativeTimeRange: { from: 0, to: 0 },
datasourceUid: '-100',
model: {
conditions: [
{
evaluator: { params: [ 0, 0 ], type: 'gt' },
operator: { type: 'and' },
query: { params: [ 'B' ] },
reducer: { params: [], type: 'avg' },
type: 'query'
}
],
datasource: { name: 'Expression', type: '__expr__', uid: '__expr__' },
expression: '$B > 100',
intervalMs: 1000,
maxDataPoints: 43200,
refId: 'C',
type: 'math'
}
}
],
for: '1m',
annotations: {},
labels: {}
}
I've tried using the post object that is send from grafana when a alert is created from UI. Also I've tried to modify my object with the properties from the UI request object. I've expected a working alert, but in these cases the api returns a bad request.
I don't know what I am missing. Thanks in advance.