Browse Source

fix(alerting): add missing evaldata field to set state command

bergquist 9 years ago
parent
commit
a23b7f1371
3 changed files with 13 additions and 8 deletions
  1. 6 4
      pkg/models/alert.go
  2. 5 4
      pkg/services/alerting/result_handler.go
  3. 2 0
      pkg/services/sqlstore/alert.go

+ 6 - 4
pkg/models/alert.go

@@ -102,10 +102,12 @@ type SaveAlertsCommand struct {
 }
 
 type SetAlertStateCommand struct {
-	AlertId   int64
-	OrgId     int64
-	State     AlertStateType
-	Error     string
+	AlertId  int64
+	OrgId    int64
+	State    AlertStateType
+	Error    string
+	EvalData *simplejson.Json
+
 	Timestamp time.Time
 }
 

+ 5 - 4
pkg/services/alerting/result_handler.go

@@ -54,10 +54,11 @@ func (handler *DefaultResultHandler) Handle(ctx *EvalContext) {
 		handler.log.Info("New state change", "alertId", ctx.Rule.Id, "newState", ctx.Rule.State, "oldState", oldState)
 
 		cmd := &m.SetAlertStateCommand{
-			AlertId: ctx.Rule.Id,
-			OrgId:   ctx.Rule.OrgId,
-			State:   ctx.Rule.State,
-			Error:   exeuctionError,
+			AlertId:  ctx.Rule.Id,
+			OrgId:    ctx.Rule.OrgId,
+			State:    ctx.Rule.State,
+			Error:    exeuctionError,
+			EvalData: annotationData,
 		}
 
 		if err := bus.Dispatch(cmd); err != nil {

+ 2 - 0
pkg/services/sqlstore/alert.go

@@ -227,6 +227,8 @@ func SetAlertState(cmd *m.SetAlertStateCommand) error {
 		alert.State = cmd.State
 		alert.StateChanges += 1
 		alert.NewStateDate = time.Now()
+		alert.EvalData = cmd.EvalData
+
 		if cmd.Error == "" {
 			alert.ExecutionError = " " //without this space, xorm skips updating this field
 		} else {