Skip to content

Commit 6b31ee9

Browse files
committed
Update.
1 parent 01e63bf commit 6b31ee9

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

service/singleton/alertsentinel.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,8 @@ func checkTrafficThresholds(alert *model.AlertRule, server *model.Server, rule *
877877
// 发送通知
878878
SafeSendNotification(alert.NotificationTag, message, &muteLabel, server)
879879

880-
// 设置静音缓存,避免短时间内重复发送(1小时
881-
Cache.Set(muteLabel, true, time.Hour)
880+
// 设置静音缓存,避免短时间内重复发送(3小时
881+
Cache.Set(muteLabel, true, time.Hour*3)
882882

883883
// 只发送最高达到的阈值通知
884884
return

service/singleton/notification.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import (
1010
"github.com/xos/serverstatus/model"
1111
)
1212

13-
const firstNotificationDelay = time.Minute * 15
13+
const (
14+
firstNotificationDelay = time.Minute * 15 // 首次通知延迟(保持原有逻辑)
15+
repeatNotificationDelay = time.Hour * 3 // 重复通知间隔:3小时
16+
)
1417

1518
// 通知方式
1619
var (
@@ -145,20 +148,18 @@ func SendNotification(notificationTag string, desc string, muteLabel *string, ex
145148
if muteLabel != nil {
146149
// 将通知方式组名称加入静音标志
147150
muteLabel := *NotificationMuteLabel.AppendNotificationTag(muteLabel, notificationTag)
148-
// 通知防骚扰策略
151+
// 通知防骚扰策略:固定3小时间隔
149152
var flag bool
150153
if cacheN, has := Cache.Get(muteLabel); has {
151154
nHistory := cacheN.(NotificationHistory)
152-
// 每次提醒都增加一倍等待时间,最后每天最多提醒一次
155+
// 检查是否已过3小时间隔
153156
if time.Now().After(nHistory.Until) {
154157
flag = true
155-
nHistory.Duration *= 2
156-
if nHistory.Duration > time.Hour*24 {
157-
nHistory.Duration = time.Hour * 24
158-
}
159-
nHistory.Until = time.Now().Add(nHistory.Duration)
158+
// 固定使用3小时间隔,不再翻倍增长
159+
nHistory.Duration = repeatNotificationDelay
160+
nHistory.Until = time.Now().Add(repeatNotificationDelay)
160161
// 缓存有效期加 10 分钟
161-
Cache.Set(muteLabel, nHistory, nHistory.Duration+time.Minute*10)
162+
Cache.Set(muteLabel, nHistory, repeatNotificationDelay+time.Minute*10)
162163
}
163164
} else {
164165
// 新提醒直接通知
@@ -171,7 +172,7 @@ func SendNotification(notificationTag string, desc string, muteLabel *string, ex
171172

172173
if !flag {
173174
if Conf.Debug {
174-
log.Println("NG>> 静音的重复通知:", desc, muteLabel)
175+
log.Println("NG>> 静音的重复通知(3小时内):", desc, muteLabel)
175176
}
176177
return
177178
}

0 commit comments

Comments
 (0)