feat(alerting): make sure saved alerts are valid

This commit is contained in:
bergquist 2016-06-09 10:27:23 +02:00
parent a1f97e0b77
commit 544073b7e1
3 changed files with 6 additions and 1 deletions

View File

@ -27,6 +27,10 @@ type AlertRule struct {
Updated time.Time `json:"updated"`
}
func (alertRule *AlertRule) ValidToSave() bool {
return alertRule.Query != "" && alertRule.Frequency != 0 && alertRule.QueryRange != 0 && alertRule.Name != ""
}
func (this *AlertRule) Equals(other *AlertRule) bool {
result := false

View File

@ -65,7 +65,7 @@ func ParseAlertsFromDashboard(cmd *m.SaveDashboardCommand) []*m.AlertRule {
alert.DatasourceId = query.Result.Id
}
if alert.Query != "" {
if alert.ValidToSave() {
alerts = append(alerts, alert)
}
}

View File

@ -64,6 +64,7 @@ func (arr *AlertRuleReader) Fetch() []*AlertRule {
model.Description = ruleDef.Description
model.Aggregator = ruleDef.Aggregator
model.State = ruleDef.State
model.QueryRange = ruleDef.QueryRange
res[i] = model
}