ソースを参照

feat(alerting): add serie name to failed alert description

bergquist 9 年 前
コミット
4e1f801f6c

+ 1 - 0
pkg/models/alerts.go

@@ -122,5 +122,6 @@ type AlertResult struct {
 	State       string
 	ActualValue float64
 	Duration    float64
+	Description string
 	Rule        AlertRule
 }

+ 1 - 7
pkg/services/alerting/alerting.go

@@ -3,7 +3,6 @@ package alerting
 import (
 	"time"
 
-	"fmt"
 	"github.com/grafana/grafana/pkg/bus"
 	"github.com/grafana/grafana/pkg/log"
 	m "github.com/grafana/grafana/pkg/models"
@@ -103,12 +102,7 @@ func (this *Scheduler) HandleResponses() {
 		cmd := m.UpdateAlertStateCommand{
 			AlertId:  response.Id,
 			NewState: response.State,
-		}
-
-		if cmd.NewState != m.AlertStateOk {
-			cmd.Info = fmt.Sprintf("Actual value: %1.2f", response.ActualValue)
-		} else {
-			cmd.Info = "Alert is OK!"
+			Info:     response.Description,
 		}
 
 		if err := bus.Dispatch(&cmd); err != nil {

+ 3 - 1
pkg/services/alerting/executor.go

@@ -102,6 +102,7 @@ func (this *ExecutorImpl) ValidateRule(rule m.AlertRule, series m.TimeSeriesSlic
 				State:       m.AlertStateCritical,
 				Id:          rule.Id,
 				ActualValue: aggValue,
+				Description: fmt.Sprintf("Actual value: %1.2f for %s", aggValue, serie.Name),
 				Rule:        rule,
 			}
 		}
@@ -110,11 +111,12 @@ func (this *ExecutorImpl) ValidateRule(rule m.AlertRule, series m.TimeSeriesSlic
 			return &m.AlertResult{
 				State:       m.AlertStateWarn,
 				Id:          rule.Id,
+				Description: fmt.Sprintf("Actual value: %1.2f for %s", aggValue, serie.Name),
 				ActualValue: aggValue,
 				Rule:        rule,
 			}
 		}
 	}
 
-	return &m.AlertResult{State: m.AlertStateOk, Id: rule.Id, Rule: rule}
+	return &m.AlertResult{State: m.AlertStateOk, Id: rule.Id, Rule: rule, Description: "Alert is OK!"}
 }