support max notify number
This commit is contained in:
parent
6a366acc74
commit
c951f7d822
|
@ -243,6 +243,7 @@ CREATE TABLE `alert_rule` (
|
|||
`notify_channels` varchar(255) not null default '' comment 'split by space: sms voice email dingtalk wecom',
|
||||
`notify_groups` varchar(255) not null default '' comment 'split by space: 233 43',
|
||||
`notify_repeat_step` int not null default 0 comment 'unit: min',
|
||||
`notify_max_number` int not null default 0 comment '',
|
||||
`recover_duration` int not null default 0 comment 'unit: s',
|
||||
`callbacks` varchar(255) not null default '' comment 'split by space: http://a.com/api/x http://a.com/api/y',
|
||||
`runbook_url` varchar(255),
|
||||
|
|
|
@ -45,6 +45,7 @@ type AlertCurEvent struct {
|
|||
NotifyUsersObj []*User `json:"notify_users_obj" gorm:"-"` // for notify.py
|
||||
LastEvalTime int64 `json:"last_eval_time" gorm:"-"` // for notify.py 上次计算的时间
|
||||
LastSentTime int64 `json:"last_sent_time" gorm:"-"` // 上次发送时间
|
||||
NotifyCurNumber int `json:"notify_cur_number"` // notify: current number
|
||||
}
|
||||
|
||||
func (e *AlertCurEvent) TableName() string {
|
||||
|
|
|
@ -41,6 +41,7 @@ type AlertRule struct {
|
|||
NotifyGroupsObj []UserGroup `json:"notify_groups_obj" gorm:"-"` // for fe
|
||||
NotifyGroupsJSON []string `json:"notify_groups" gorm:"-"` // for fe
|
||||
NotifyRepeatStep int `json:"notify_repeat_step"` // notify repeat interval, unit: min
|
||||
NotifyMaxNumber int `json:"notify_max_number"` // notify: max number
|
||||
RecoverDuration int64 `json:"recover_duration"` // unit: s
|
||||
Callbacks string `json:"-"` // split by space: http://a.com/api/x http://a.com/api/y'
|
||||
CallbacksJSON []string `json:"callbacks" gorm:"-"` // for fe
|
||||
|
|
|
@ -364,7 +364,19 @@ func (r RuleEval) fireEvent(event *models.AlertCurEvent) {
|
|||
|
||||
// 之前发送过告警了,这次是否要继续发送,要看是否过了通道静默时间
|
||||
if event.LastEvalTime > fired.LastSentTime+int64(r.rule.NotifyRepeatStep)*60 {
|
||||
r.pushEventToQueue(event)
|
||||
if r.rule.NotifyMaxNumber == 0 {
|
||||
// 最大可以发送次数如果是0,表示不想限制最大发送次数,一直发即可
|
||||
r.pushEventToQueue(event)
|
||||
} else {
|
||||
// 有最大发送次数的限制,就要看已经发了几次了,是否达到了最大发送次数
|
||||
if fired.NotifyCurNumber >= r.rule.NotifyMaxNumber {
|
||||
return
|
||||
} else {
|
||||
event.NotifyCurNumber = fired.NotifyCurNumber + 1
|
||||
r.pushEventToQueue(event)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
r.pushEventToQueue(event)
|
||||
|
|
Loading…
Reference in New Issue