converge delete
This commit is contained in:
parent
a1b4344943
commit
733da1ea94
|
@ -199,6 +199,11 @@ func DelEventOlder(ts int64, batch int) error {
|
|||
return err
|
||||
}
|
||||
|
||||
func EventDelById(id interface{}) error {
|
||||
_, err := DB["mon"].Where("id=?", id).Delete(new(Event))
|
||||
return err
|
||||
}
|
||||
|
||||
func EventAlertUpgradeUnMarshal(str string) (EventAlertUpgrade, error) {
|
||||
var obj EventAlertUpgrade
|
||||
if strings.TrimSpace(str) == "" {
|
||||
|
|
|
@ -246,7 +246,11 @@ func EventCurGet(col string, value interface{}) (*EventCur, error) {
|
|||
}
|
||||
|
||||
func (e *EventCur) EventIgnore() error {
|
||||
_, err := DB["mon"].Exec("delete from event_cur where id=?", e.Id)
|
||||
return EventCurDelById(e.Id)
|
||||
}
|
||||
|
||||
func EventCurDelById(id interface{}) error {
|
||||
_, err := DB["mon"].Where("id=?", id).Delete(new(EventCur))
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -277,12 +277,6 @@ func needUpgrade(event *models.Event) bool {
|
|||
}
|
||||
|
||||
func SetEventStatus(event *models.Event, status string) {
|
||||
if err := models.SaveEventStatus(event.Id, status); err != nil {
|
||||
logger.Errorf("set event status fail, event: %+v, status: %v, err:%v", event, status, err)
|
||||
} else {
|
||||
logger.Infof("set event status succ, event hasid: %v, status: %v", event.HashId, status)
|
||||
}
|
||||
|
||||
if event.EventType == config.ALERT {
|
||||
if err := models.SaveEventCurStatus(event.HashId, status); err != nil {
|
||||
logger.Errorf("set event_cur status fail, event: %+v, status: %v, err:%v", event, status, err)
|
||||
|
@ -290,6 +284,22 @@ func SetEventStatus(event *models.Event, status string) {
|
|||
logger.Infof("set event_cur status succ, event hashid: %v, status: %v", event.HashId, status)
|
||||
}
|
||||
}
|
||||
|
||||
if config.Get().Cleaner.Converge && status == models.STATUS_CONVERGE {
|
||||
// 已收敛的告警,直接从库里删了,不保留了
|
||||
if err := models.EventDelById(event.Id); err != nil {
|
||||
logger.Errorf("converge_del fail, id: %v, hash id: %v, error: %v", event.Id, event.HashId, err)
|
||||
} else {
|
||||
logger.Infof("converge_del succ, id: %v, hash id: %v", event.Id, event.HashId)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err := models.SaveEventStatus(event.Id, status); err != nil {
|
||||
logger.Errorf("set event status fail, event: %+v, status: %v, err:%v", event, status, err)
|
||||
} else {
|
||||
logger.Infof("set event status succ, event hasid: %v, status: %v", event.HashId, status)
|
||||
}
|
||||
}
|
||||
|
||||
func getUserIds(users, groups string) ([]int64, error) {
|
||||
|
|
|
@ -38,8 +38,9 @@ type mergeSection struct {
|
|||
}
|
||||
|
||||
type cleanerSection struct {
|
||||
Days int `yaml:"days"`
|
||||
Batch int `yaml:"batch"`
|
||||
Days int `yaml:"days"`
|
||||
Batch int `yaml:"batch"`
|
||||
Converge bool `yaml:"converge"`
|
||||
}
|
||||
|
||||
type queueSection struct {
|
||||
|
@ -169,8 +170,9 @@ func Parse(ymlfile string) error {
|
|||
})
|
||||
|
||||
viper.SetDefault("cleaner", map[string]interface{}{
|
||||
"days": 31,
|
||||
"batch": 100,
|
||||
"days": 31,
|
||||
"batch": 100,
|
||||
"converge": true, // 历史告警的数据库表,对于已收敛的告警,默认删掉,不保留,省得告警太多
|
||||
})
|
||||
|
||||
err = viper.Unmarshal(&yaml)
|
||||
|
|
Loading…
Reference in New Issue