fix(alerting): minor fix

This commit is contained in:
Torkel Ödegaard 2016-07-19 09:28:49 +02:00
parent b0fe69822a
commit 0f555d6ab5
3 changed files with 7 additions and 7 deletions

View File

@ -11,7 +11,7 @@ type AlertState struct {
Id int64 `json:"-"`
OrgId int64 `json:"-"`
AlertId int64 `json:"alertId"`
NewState string `json:"newState"`
State string `json:"state"`
Created time.Time `json:"created"`
Info string `json:"info"`
TriggeredAlerts *simplejson.Json `json:"triggeredAlerts"`
@ -19,7 +19,7 @@ type AlertState struct {
func (this *UpdateAlertStateCommand) IsValidState() bool {
for _, v := range alertstates.ValidStates {
if this.NewState == v {
if this.State == v {
return true
}
}
@ -31,7 +31,7 @@ func (this *UpdateAlertStateCommand) IsValidState() bool {
type UpdateAlertStateCommand struct {
AlertId int64 `json:"alertId" binding:"Required"`
OrgId int64 `json:"orgId" binding:"Required"`
NewState string `json:"newState" binding:"Required"`
State string `json:"state" binding:"Required"`
Info string `json:"info"`
TriggeredAlerts *simplejson.Json `json:"triggeredAlerts"`

View File

@ -29,7 +29,7 @@ func (handler *ResultHandlerImpl) Handle(result *AlertResult) {
if handler.shouldUpdateState(result) {
cmd := &m.UpdateAlertStateCommand{
AlertId: result.AlertJob.Rule.Id,
NewState: result.State,
State: result.State,
Info: result.Description,
OrgId: result.AlertJob.Rule.OrgId,
TriggeredAlerts: simplejson.NewFromAny(result.TriggeredAlerts),
@ -62,7 +62,7 @@ func (handler *ResultHandlerImpl) shouldUpdateState(result *AlertResult) bool {
lastExecution := query.Result.Created
asdf := result.StartTime.Add(time.Minute * -15)
olderThen15Min := lastExecution.Before(asdf)
changedState := query.Result.NewState != result.State
changedState := query.Result.State != result.State
return changedState || olderThen15Min
}

View File

@ -47,13 +47,13 @@ func SetNewAlertState(cmd *m.UpdateAlertStateCommand) error {
return fmt.Errorf("Could not find alert")
}
alert.State = cmd.NewState
alert.State = cmd.State
sess.Id(alert.Id).Update(&alert)
alertState := m.AlertState{
AlertId: cmd.AlertId,
OrgId: cmd.OrgId,
NewState: cmd.NewState,
State: cmd.State,
Info: cmd.Info,
Created: time.Now(),
TriggeredAlerts: cmd.TriggeredAlerts,