@@ -26,11 +26,32 @@ type Rule struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ValidationError struct {
|
type ValidationError struct {
|
||||||
Reason string
|
Reason string
|
||||||
|
Err error
|
||||||
|
Alertid int64
|
||||||
|
DashboardId int64
|
||||||
|
PanelId int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ValidationError) Error() string {
|
func (e ValidationError) Error() string {
|
||||||
return e.Reason
|
extraInfo := ""
|
||||||
|
if e.Alertid != 0 {
|
||||||
|
extraInfo = fmt.Sprintf("%s AlertId: %v", extraInfo, e.Alertid)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e.PanelId != 0 {
|
||||||
|
extraInfo = fmt.Sprintf("%s PanelId: %v ", extraInfo, e.PanelId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e.DashboardId != 0 {
|
||||||
|
extraInfo = fmt.Sprintf("%s DashboardId: %v", extraInfo, e.DashboardId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if e.Err != nil {
|
||||||
|
return fmt.Sprintf("%s %s%s", e.Err.Error(), e.Reason, extraInfo)
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("Failed to extract alert.Reason: %s %s", e.Reason, extraInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -83,7 +104,7 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) {
|
|||||||
for _, v := range ruleDef.Settings.Get("notifications").MustArray() {
|
for _, v := range ruleDef.Settings.Get("notifications").MustArray() {
|
||||||
jsonModel := simplejson.NewFromAny(v)
|
jsonModel := simplejson.NewFromAny(v)
|
||||||
if id, err := jsonModel.Get("id").Int64(); err != nil {
|
if id, err := jsonModel.Get("id").Int64(); err != nil {
|
||||||
return nil, ValidationError{Reason: "Invalid notification schema"}
|
return nil, ValidationError{Reason: "Invalid notification schema", DashboardId: model.DashboardId, Alertid: model.Id, PanelId: model.PanelId}
|
||||||
} else {
|
} else {
|
||||||
model.Notifications = append(model.Notifications, id)
|
model.Notifications = append(model.Notifications, id)
|
||||||
}
|
}
|
||||||
@@ -93,10 +114,10 @@ func NewRuleFromDBAlert(ruleDef *m.Alert) (*Rule, error) {
|
|||||||
conditionModel := simplejson.NewFromAny(condition)
|
conditionModel := simplejson.NewFromAny(condition)
|
||||||
conditionType := conditionModel.Get("type").MustString()
|
conditionType := conditionModel.Get("type").MustString()
|
||||||
if factory, exist := conditionFactories[conditionType]; !exist {
|
if factory, exist := conditionFactories[conditionType]; !exist {
|
||||||
return nil, ValidationError{Reason: "Unknown alert condition: " + conditionType}
|
return nil, ValidationError{Reason: "Unknown alert condition: " + conditionType, DashboardId: model.DashboardId, Alertid: model.Id, PanelId: model.PanelId}
|
||||||
} else {
|
} else {
|
||||||
if queryCondition, err := factory(conditionModel, index); err != nil {
|
if queryCondition, err := factory(conditionModel, index); err != nil {
|
||||||
return nil, err
|
return nil, ValidationError{Err: err, DashboardId: model.DashboardId, Alertid: model.Id, PanelId: model.PanelId}
|
||||||
} else {
|
} else {
|
||||||
model.Conditions = append(model.Conditions, queryCondition)
|
model.Conditions = append(model.Conditions, queryCondition)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user