mirror of
https://github.com/grafana/grafana.git
synced 2024-11-27 03:11:01 -06:00
feat(alerting): more aggressive requirements for parsing alertrules
This commit is contained in:
parent
8b05af2f90
commit
6121d15ba7
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||
"github.com/grafana/grafana/pkg/services/alerting/transformers"
|
||||
@ -63,7 +64,16 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
|
||||
model.State = ruleDef.State
|
||||
model.Frequency = ruleDef.Frequency
|
||||
|
||||
model.NotificationGroups = []int64{1, 2}
|
||||
ngs := ruleDef.Settings.Get("notificationGroups").MustString()
|
||||
var ids []int64
|
||||
for _, v := range strings.Split(ngs, ",") {
|
||||
id, err := strconv.Atoi(v)
|
||||
if err == nil {
|
||||
ids = append(ids, int64(id))
|
||||
}
|
||||
}
|
||||
|
||||
model.NotificationGroups = ids
|
||||
|
||||
critical := ruleDef.Settings.Get("crit")
|
||||
model.Critical = Level{
|
||||
@ -78,6 +88,10 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
|
||||
}
|
||||
|
||||
model.Transform = ruleDef.Settings.Get("transform").Get("type").MustString()
|
||||
if model.Transform == "" {
|
||||
return nil, fmt.Errorf("missing transform")
|
||||
}
|
||||
|
||||
model.TransformParams = *ruleDef.Settings.Get("transform")
|
||||
|
||||
if model.Transform == "aggregation" {
|
||||
@ -91,7 +105,6 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
|
||||
DatasourceId: query.Get("datasourceId").MustInt64(),
|
||||
From: query.Get("from").MustString(),
|
||||
To: query.Get("to").MustString(),
|
||||
Aggregator: query.Get("agg").MustString(),
|
||||
}
|
||||
|
||||
if model.Query.Query == "" {
|
||||
|
@ -55,7 +55,7 @@ func TestAlertRuleModel(t *testing.T) {
|
||||
"datasourceId": 1
|
||||
},
|
||||
"transform": {
|
||||
"method": "avg",
|
||||
"type": "avg",
|
||||
"name": "aggregation"
|
||||
}
|
||||
}
|
||||
|
@ -132,12 +132,10 @@ func (e *Engine) resultHandler() {
|
||||
|
||||
result.State = alertstates.Critical
|
||||
result.Description = fmt.Sprintf("Failed to run check after %d retires, Error: %v", maxAlertExecutionRetries, result.Error)
|
||||
//e.reactToState(result)
|
||||
e.responseHandler.Handle(result)
|
||||
}
|
||||
} else {
|
||||
result.AlertJob.ResetRetry()
|
||||
//e.reactToState(result)
|
||||
e.responseHandler.Handle(result)
|
||||
}
|
||||
}
|
||||
|
@ -52,8 +52,8 @@ func TestAlertRuleExtraction(t *testing.T) {
|
||||
"to": "now"
|
||||
},
|
||||
"transform": {
|
||||
"method": "avg",
|
||||
"type": "aggregation"
|
||||
"type": "avg",
|
||||
"name": "aggregation"
|
||||
},
|
||||
"warn": {
|
||||
"value": 10,
|
||||
@ -87,7 +87,7 @@ func TestAlertRuleExtraction(t *testing.T) {
|
||||
"to": "now"
|
||||
},
|
||||
"transform": {
|
||||
"method": "avg",
|
||||
"type": "avg",
|
||||
"name": "aggregation"
|
||||
},
|
||||
"warn": {
|
||||
|
@ -47,7 +47,6 @@ type Level struct {
|
||||
type AlertQuery struct {
|
||||
Query string
|
||||
DatasourceId int64
|
||||
Aggregator string
|
||||
From string
|
||||
To string
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user