2016-06-11 16:13:33 +08:00
|
|
|
package alerting
|
|
|
|
|
|
|
|
|
|
import (
|
2019-01-10 16:35:48 +08:00
|
|
|
"errors"
|
2016-06-11 16:13:33 +08:00
|
|
|
"fmt"
|
2016-06-13 16:40:46 +08:00
|
|
|
"regexp"
|
|
|
|
|
"strconv"
|
2018-11-01 23:04:38 +08:00
|
|
|
"time"
|
2016-06-11 16:13:33 +08:00
|
|
|
|
|
|
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
|
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
|
|
|
)
|
|
|
|
|
|
2019-01-10 16:35:48 +08:00
|
|
|
var (
|
|
|
|
|
ErrFrequencyCannotBeZeroOrLess = errors.New(`"evaluate every" cannot be zero or below`)
|
|
|
|
|
ErrFrequencyCouldNotBeParsed = errors.New(`"evaluate every" field could not be parsed`)
|
|
|
|
|
)
|
|
|
|
|
|
2016-07-27 22:29:28 +08:00
|
|
|
type Rule struct {
|
2016-11-04 18:28:12 +08:00
|
|
|
Id int64
|
|
|
|
|
OrgId int64
|
|
|
|
|
DashboardId int64
|
|
|
|
|
PanelId int64
|
|
|
|
|
Frequency int64
|
|
|
|
|
Name string
|
|
|
|
|
Message string
|
2018-11-01 23:04:38 +08:00
|
|
|
LastStateChange time.Time
|
2018-11-05 18:05:30 +08:00
|
|
|
For time.Duration
|
2016-11-04 18:28:12 +08:00
|
|
|
NoDataState m.NoDataOption
|
2016-11-07 19:42:39 +08:00
|
|
|
ExecutionErrorState m.ExecutionErrorOption
|
2016-11-04 18:28:12 +08:00
|
|
|
State m.AlertStateType
|
|
|
|
|
Conditions []Condition
|
2018-12-14 17:53:50 +08:00
|
|
|
Notifications []string
|
2018-10-01 20:13:03 +08:00
|
|
|
|
|
|
|
|
StateChanges int64
|
2016-07-19 22:15:26 +08:00
|
|
|
}
|
|
|
|
|
|
2016-07-27 22:29:28 +08:00
|
|
|
type ValidationError struct {
|
2016-11-15 18:47:44 +08:00
|
|
|
Reason string
|
|
|
|
|
Err error
|
|
|
|
|
Alertid int64
|
|
|
|
|
DashboardId int64
|
|
|
|
|
PanelId int64
|
2016-07-21 19:09:12 +08:00
|
|
|
}
|
|
|
|
|
|
2016-07-27 22:29:28 +08:00
|
|
|
func (e ValidationError) Error() string {
|
2018-10-13 13:53:28 +08:00
|
|
|
extraInfo := e.Reason
|
2016-11-15 18:47:44 +08:00
|
|
|
if e.Alertid != 0 {
|
|
|
|
|
extraInfo = fmt.Sprintf("%s AlertId: %v", extraInfo, e.Alertid)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if e.PanelId != 0 {
|
2018-10-13 13:53:28 +08:00
|
|
|
extraInfo = fmt.Sprintf("%s PanelId: %v", extraInfo, e.PanelId)
|
2016-11-15 18:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if e.DashboardId != 0 {
|
|
|
|
|
extraInfo = fmt.Sprintf("%s DashboardId: %v", extraInfo, e.DashboardId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if e.Err != nil {
|
2018-10-13 13:53:28 +08:00
|
|
|
return fmt.Sprintf("Alert validation error: %s%s", e.Err.Error(), extraInfo)
|
2016-11-15 18:47:44 +08:00
|
|
|
}
|
|
|
|
|
|
2018-10-13 13:53:28 +08:00
|
|
|
return fmt.Sprintf("Alert validation error: %s", extraInfo)
|
2016-07-21 19:09:12 +08:00
|
|
|
}
|
|
|
|
|
|
2016-06-13 16:40:46 +08:00
|
|
|
var (
|
2018-04-17 02:19:19 +08:00
|
|
|
ValueFormatRegex = regexp.MustCompile(`^\d+`)
|
|
|
|
|
UnitFormatRegex = regexp.MustCompile(`\w{1}$`)
|
2016-06-13 16:40:46 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var unitMultiplier = map[string]int{
|
|
|
|
|
"s": 1,
|
|
|
|
|
"m": 60,
|
|
|
|
|
"h": 3600,
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 23:36:30 +08:00
|
|
|
func getTimeDurationStringToSeconds(str string) (int64, error) {
|
2016-06-13 16:40:46 +08:00
|
|
|
multiplier := 1
|
|
|
|
|
|
2016-10-11 23:36:30 +08:00
|
|
|
matches := ValueFormatRegex.FindAllString(str, 1)
|
|
|
|
|
|
|
|
|
|
if len(matches) <= 0 {
|
2019-01-10 16:35:48 +08:00
|
|
|
return 0, ErrFrequencyCouldNotBeParsed
|
2016-10-11 23:36:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value, err := strconv.Atoi(matches[0])
|
|
|
|
|
if err != nil {
|
|
|
|
|
return 0, err
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-10 16:35:48 +08:00
|
|
|
if value == 0 {
|
|
|
|
|
return 0, ErrFrequencyCannotBeZeroOrLess
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-13 16:40:46 +08:00
|
|
|
unit := UnitFormatRegex.FindAllString(str, 1)[0]
|
|
|
|
|
|
|
|
|
|
if val, ok := unitMultiplier[unit]; ok {
|
|
|
|
|
multiplier = val
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 23:36:30 +08:00
|
|
|
return int64(value * multiplier), nil
|
2016-06-12 04:33:02 +08:00
|
|
|
}
|
|
|
|
|
|
2016-07-27 22:29:28 +08:00
|
|
|
func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) {
|
|
|
|
|
model := &Rule{}
|
2016-06-11 16:13:33 +08:00
|
|
|
model.Id = ruleDef.Id
|
|
|
|
|
model.OrgId = ruleDef.OrgId
|
2016-07-26 18:29:52 +08:00
|
|
|
model.DashboardId = ruleDef.DashboardId
|
|
|
|
|
model.PanelId = ruleDef.PanelId
|
2016-06-11 16:13:33 +08:00
|
|
|
model.Name = ruleDef.Name
|
2016-08-12 16:12:04 +08:00
|
|
|
model.Message = ruleDef.Message
|
2016-07-22 19:14:09 +08:00
|
|
|
model.State = ruleDef.State
|
2018-11-01 23:04:38 +08:00
|
|
|
model.LastStateChange = ruleDef.NewStateDate
|
2018-11-05 18:05:30 +08:00
|
|
|
model.For = ruleDef.For
|
2016-10-22 16:54:50 +08:00
|
|
|
model.NoDataState = m.NoDataOption(ruleDef.Settings.Get("noDataState").MustString("no_data"))
|
2016-11-07 19:42:39 +08:00
|
|
|
model.ExecutionErrorState = m.ExecutionErrorOption(ruleDef.Settings.Get("executionErrorState").MustString("alerting"))
|
2018-10-02 17:19:09 +08:00
|
|
|
model.StateChanges = ruleDef.StateChanges
|
2016-06-11 16:13:33 +08:00
|
|
|
|
2019-01-10 16:35:48 +08:00
|
|
|
model.Frequency = ruleDef.Frequency
|
|
|
|
|
// frequency cannot be zero since that would not execute the alert rule.
|
|
|
|
|
// so we fallback to 60 seconds if `Freqency` is missing
|
|
|
|
|
if model.Frequency == 0 {
|
|
|
|
|
model.Frequency = 60
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 22:15:26 +08:00
|
|
|
for _, v := range ruleDef.Settings.Get("notifications").MustArray() {
|
2016-07-26 18:29:52 +08:00
|
|
|
jsonModel := simplejson.NewFromAny(v)
|
2018-12-20 23:12:47 +08:00
|
|
|
if id, err := jsonModel.Get("id").Int64(); err == nil {
|
2019-01-02 16:34:07 +08:00
|
|
|
model.Notifications = append(model.Notifications, fmt.Sprintf("%09d", id))
|
2018-12-20 23:12:47 +08:00
|
|
|
} else {
|
|
|
|
|
if uid, err := jsonModel.Get("uid").String(); err != nil {
|
2019-01-02 16:34:07 +08:00
|
|
|
return nil, ValidationError{Reason: "Neither id nor uid is specified, " + err.Error(), DashboardId: model.DashboardId, Alertid: model.Id, PanelId: model.PanelId}
|
2018-12-20 23:12:47 +08:00
|
|
|
} else {
|
|
|
|
|
model.Notifications = append(model.Notifications, uid)
|
|
|
|
|
}
|
2016-06-23 22:07:23 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-22 03:54:12 +08:00
|
|
|
for index, condition := range ruleDef.Settings.Get("conditions").MustArray() {
|
2016-07-19 22:15:26 +08:00
|
|
|
conditionModel := simplejson.NewFromAny(condition)
|
2016-07-27 22:18:10 +08:00
|
|
|
conditionType := conditionModel.Get("type").MustString()
|
Outdent code after if block that ends with return (golint)
This commit fixes the following golint warnings:
pkg/bus/bus.go:64:9: if block ends with a return statement, so drop this else and outdent its block
pkg/bus/bus.go:84:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:137:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:177:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:183:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:199:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:208:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/components/dynmap/dynmap.go:236:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:242:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:257:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:263:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:278:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:284:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:299:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:331:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:350:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:356:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:366:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:390:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:396:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:405:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:427:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:433:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:442:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:459:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:465:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:474:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:491:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:497:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:506:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:523:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:529:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:538:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:555:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:561:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:570:12: if block ends with a return statement, so drop this else and outdent its block
pkg/login/ldap.go:55:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/login/ldap_test.go:372:10: if block ends with a return statement, so drop this else and outdent its block
pkg/middleware/middleware_test.go:213:12: if block ends with a return statement, so drop this else and outdent its block
pkg/plugins/dashboard_importer.go:153:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:39:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:121:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:210:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:235:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/eval_context.go:111:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:92:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:98:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:122:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:108:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:118:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:121:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifiers/telegram.go:94:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/annotation.go:34:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/annotation.go:99:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/dashboard_test.go:107:13: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/plugin_setting.go:78:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/preferences.go:91:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/user.go:50:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/migrator/migrator.go:106:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/migrator/postgres_dialect.go:48:10: if block ends with a return statement, so drop this else and outdent its block
pkg/tsdb/time_range.go:59:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/time_range.go:67:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/cloudwatch/metric_find_query.go:225:9: if block ends with a return statement, so drop this else and outdent its block
pkg/util/filepath.go:68:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
2018-04-28 04:42:49 +08:00
|
|
|
factory, exist := conditionFactories[conditionType]
|
|
|
|
|
if !exist {
|
2016-11-15 18:47:44 +08:00
|
|
|
return nil, ValidationError{Reason: "Unknown alert condition: " + conditionType, DashboardId: model.DashboardId, Alertid: model.Id, PanelId: model.PanelId}
|
2016-07-19 22:15:26 +08:00
|
|
|
}
|
Outdent code after if block that ends with return (golint)
This commit fixes the following golint warnings:
pkg/bus/bus.go:64:9: if block ends with a return statement, so drop this else and outdent its block
pkg/bus/bus.go:84:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:137:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:177:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:183:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:199:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:208:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/components/dynmap/dynmap.go:236:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:242:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:257:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:263:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:278:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:284:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:299:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:331:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:350:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:356:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:366:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:390:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:396:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:405:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:427:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:433:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:442:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:459:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:465:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:474:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:491:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:497:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:506:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:523:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:529:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:538:12: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:555:9: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:561:10: if block ends with a return statement, so drop this else and outdent its block
pkg/components/dynmap/dynmap.go:570:12: if block ends with a return statement, so drop this else and outdent its block
pkg/login/ldap.go:55:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/login/ldap_test.go:372:10: if block ends with a return statement, so drop this else and outdent its block
pkg/middleware/middleware_test.go:213:12: if block ends with a return statement, so drop this else and outdent its block
pkg/plugins/dashboard_importer.go:153:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:39:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/dashboards_updater.go:121:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:210:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/plugins/plugins.go:235:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/eval_context.go:111:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:92:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:98:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifier.go:122:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:108:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:118:10: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/rule.go:121:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/alerting/notifiers/telegram.go:94:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/annotation.go:34:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/annotation.go:99:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/dashboard_test.go:107:13: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/plugin_setting.go:78:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/preferences.go:91:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/user.go:50:10: if block ends with a return statement, so drop this else and outdent its block
pkg/services/sqlstore/migrator/migrator.go:106:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/services/sqlstore/migrator/postgres_dialect.go:48:10: if block ends with a return statement, so drop this else and outdent its block
pkg/tsdb/time_range.go:59:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/time_range.go:67:9: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
pkg/tsdb/cloudwatch/metric_find_query.go:225:9: if block ends with a return statement, so drop this else and outdent its block
pkg/util/filepath.go:68:11: if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
2018-04-28 04:42:49 +08:00
|
|
|
queryCondition, err := factory(conditionModel, index)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, ValidationError{Err: err, DashboardId: model.DashboardId, Alertid: model.Id, PanelId: model.PanelId}
|
|
|
|
|
}
|
|
|
|
|
model.Conditions = append(model.Conditions, queryCondition)
|
2016-06-11 16:13:33 +08:00
|
|
|
}
|
|
|
|
|
|
2016-07-19 22:15:26 +08:00
|
|
|
if len(model.Conditions) == 0 {
|
2018-10-13 14:15:23 +08:00
|
|
|
return nil, ValidationError{Reason: "Alert is missing conditions"}
|
2016-06-11 16:13:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return model, nil
|
|
|
|
|
}
|
2016-07-27 22:18:10 +08:00
|
|
|
|
2016-07-27 22:29:28 +08:00
|
|
|
type ConditionFactory func(model *simplejson.Json, index int) (Condition, error)
|
2016-07-27 22:18:10 +08:00
|
|
|
|
2018-04-28 04:14:36 +08:00
|
|
|
var conditionFactories = make(map[string]ConditionFactory)
|
2016-07-27 22:18:10 +08:00
|
|
|
|
|
|
|
|
func RegisterCondition(typeName string, factory ConditionFactory) {
|
|
|
|
|
conditionFactories[typeName] = factory
|
|
|
|
|
}
|