forked from grafana/grafonnet-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
alert_condition.libsonnet
47 lines (47 loc) · 1.41 KB
/
alert_condition.libsonnet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{
/**
* Returns a new condition of alert of graph panel.
* Currently the only condition type that exists is a Query condition
* that allows to specify a query letter, time range and an aggregation function.
*
* @name alertCondition.new
*
* @param evaluatorParams Value of threshold
* @param evaluatorType Type of threshold
* @param operatorType Operator between conditions
* @param queryRefId The letter defines what query to execute from the Metrics tab
* @param queryTimeStart Begging of time range
* @param queryTimeEnd End of time range
* @param reducerParams Params of an aggregation function
* @param reducerType Name of an aggregation function
*
* @return A json that represents a condition of alert
*/
new(
evaluatorParams=[],
evaluatorType='gt',
operatorType='and',
queryRefId='A',
queryTimeEnd='now',
queryTimeStart='5m',
reducerParams=[],
reducerType='avg',
)::
{
evaluator: {
params: if std.type(evaluatorParams) == 'array' then evaluatorParams else [evaluatorParams],
type: evaluatorType,
},
operator: {
type: operatorType,
},
query: {
params: [queryRefId, queryTimeStart, queryTimeEnd],
},
reducer: {
params: if std.type(reducerParams) == 'array' then reducerParams else [reducerParams],
type: reducerType,
},
type: 'query',
},
}