mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Apply suggestions from code review
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
parent
95d3e75b00
commit
7f95800c5f
@ -198,7 +198,10 @@ func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json,
|
||||
validationWarnings := strings.Builder{}
|
||||
for _, validator := range validators {
|
||||
ok, reason := validator.aFunc(alert)
|
||||
if !ok {
|
||||
if ok {
|
||||
continue
|
||||
}
|
||||
|
||||
switch validator.aSeverity {
|
||||
case alertError:
|
||||
if validationErrors.Len() > 0 {
|
||||
@ -212,7 +215,6 @@ func (e *DashAlertExtractor) getAlertFromPanels(jsonWithPanels *simplejson.Json,
|
||||
validationWarnings.WriteString(reason)
|
||||
}
|
||||
}
|
||||
}
|
||||
if validationErrors.String() != "" {
|
||||
return nil, ValidationError{Reason: validationErrors.String()}
|
||||
}
|
||||
@ -238,17 +240,21 @@ func validAlertJSON(alert *models.Alert) (ok bool, reason string) {
|
||||
warnings := strings.Builder{}
|
||||
for _, v := range alert.Settings.Get("notifications").MustArray() {
|
||||
jsonModel := simplejson.NewFromAny(v)
|
||||
if id, err := jsonModel.Get("id").Int64(); err == nil {
|
||||
_, err := translateNotificationIDToUID(id, alert.OrgId)
|
||||
id, err := jsonModel.Get("id").Int64()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if _, err := translateNotificationIDToUID(id, alert.OrgId); err == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
ok = false
|
||||
if warnings.Len() > 0 {
|
||||
warnings.WriteString("\n")
|
||||
}
|
||||
warnings.WriteString(fmt.Sprintf("Alert contains notification identified by incorrect id, alertName=%v, panelId=%v, notificationId=%v", alert.Name, alert.PanelId, id))
|
||||
}
|
||||
}
|
||||
}
|
||||
reason = warnings.String()
|
||||
return ok, reason
|
||||
}
|
||||
@ -309,7 +315,7 @@ func (e *DashAlertExtractor) ValidateAlerts() error {
|
||||
aFunc: func(alert *models.Alert) (ok bool, reason string) {
|
||||
ok = alert.OrgId != 0 && alert.PanelId != 0
|
||||
if !ok {
|
||||
reason = fmt.Sprintf("Panel id is not correct, alertName=%v, panelId=%v", alert.Name, alert.PanelId)
|
||||
reason = fmt.Sprintf("Panel ID is not correct, alertName=%v, panelId=%v", alert.Name, alert.PanelId)
|
||||
}
|
||||
return ok, reason
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user