Skip to content

Commit

Permalink
Merge pull request #90 from xiaozhangzhang1/bug-fix
Browse files Browse the repository at this point in the history
Bug fix
  • Loading branch information
70data authored Dec 15, 2020
2 parents 931e065 + b992921 commit 6f9869b
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/alert-gateway/models/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ func (u *Alerts) AlertsHandler(alert *common.Alerts) {
Id int64
Status uint8
}
var updateAlerts []struct {
Id int64
Status uint8
}

a := &alertForQuery{Alert: &elemt}
a.setFields()
Expand All @@ -381,6 +385,18 @@ func (u *Alerts) AlertsHandler(alert *common.Alerts) {
continue
}
} else {
//插入新告警之前,将老的告警的status字段update为3,3不会发告警
_, err := Ormer().Raw("SELECT id,status FROM alert WHERE rule_id =? AND labels=? AND status !=?", a.ruleId, a.label, 0).QueryRows(&updateAlerts)
if len(updateAlerts) > 0 {
//old alert ,updaate status
for _, id := range updateAlerts {
//_, err = Ormer().Raw("DELETE FROM alert WHERE id=?", id.Id).Exec()
_, err = Ormer().Raw("UPDATE alert SET status =? WHERE id=?", 3, id.Id).Exec()
if err != nil {
logs.Error("database update alert error:%s\n", err)
}
}
}
// insert an new alert
var alert Alerts
alert.Id = 0 //reset the "Id" to 0,which is very important:after a record is inserted,the value of "Id" will not be 0,but the auto primary key of the record
Expand All @@ -396,7 +412,7 @@ func (u *Alerts) AlertsHandler(alert *common.Alerts) {
alert.ConfirmedAt = &todayZero
alert.ConfirmedBefore = &todayZero
alert.ResolvedAt = &todayZero
_, err := Ormer().Insert(&alert)
_, err = Ormer().Insert(&alert)
if err != nil {
logs.Error("Insert alter failed:%s", err)
}
Expand Down

0 comments on commit 6f9869b

Please sign in to comment.