mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-05 13:10:07 +00:00
🚸 [dashboard v0.3.8] improve: 不过滤的通知
This commit is contained in:
@@ -134,7 +134,7 @@ func checkStatus() {
|
||||
max, desc := alert.Check(alertsStore[alert.ID][server.ID])
|
||||
if desc != "" {
|
||||
message := fmt.Sprintf("报警规则:%s,服务器:%s(%s),%s,逮到咯,快去看看!", alert.Name, server.Name, server.Host.IP, desc)
|
||||
go SendNotification(message)
|
||||
go SendNotification(message, true)
|
||||
}
|
||||
// 清理旧数据
|
||||
if max > 0 && max < len(alertsStore[alert.ID][server.ID]) {
|
||||
@@ -144,36 +144,37 @@ func checkStatus() {
|
||||
}
|
||||
}
|
||||
|
||||
func SendNotification(desc string) {
|
||||
// 通知防骚扰策略
|
||||
nID := hex.EncodeToString(md5.New().Sum([]byte(desc)))
|
||||
var flag bool
|
||||
if cacheN, has := dao.Cache.Get(nID); has {
|
||||
nHistory := cacheN.(NotificationHistory)
|
||||
// 每次提醒都增加一倍等待时间,最后每天最多提醒一次
|
||||
if time.Now().After(nHistory.Until) {
|
||||
flag = true
|
||||
nHistory.Duration *= 2
|
||||
if nHistory.Duration > time.Hour*24 {
|
||||
nHistory.Duration = time.Hour * 24
|
||||
func SendNotification(desc string, muteable bool) {
|
||||
if muteable {
|
||||
// 通知防骚扰策略
|
||||
nID := hex.EncodeToString(md5.New().Sum([]byte(desc)))
|
||||
var flag bool
|
||||
if cacheN, has := dao.Cache.Get(nID); has {
|
||||
nHistory := cacheN.(NotificationHistory)
|
||||
// 每次提醒都增加一倍等待时间,最后每天最多提醒一次
|
||||
if time.Now().After(nHistory.Until) {
|
||||
flag = true
|
||||
nHistory.Duration *= 2
|
||||
if nHistory.Duration > time.Hour*24 {
|
||||
nHistory.Duration = time.Hour * 24
|
||||
}
|
||||
nHistory.Until = time.Now().Add(nHistory.Duration)
|
||||
// 缓存有效期加 10 分钟
|
||||
dao.Cache.Set(nID, nHistory, nHistory.Duration+time.Minute*10)
|
||||
}
|
||||
nHistory.Until = time.Now().Add(nHistory.Duration)
|
||||
// 缓存有效期加 10 分钟
|
||||
dao.Cache.Set(nID, nHistory, nHistory.Duration+time.Minute*10)
|
||||
} else {
|
||||
// 新提醒直接通知
|
||||
flag = true
|
||||
dao.Cache.Set(nID, NotificationHistory{
|
||||
Duration: firstNotificationDelay,
|
||||
Until: time.Now().Add(firstNotificationDelay),
|
||||
}, firstNotificationDelay+time.Minute*10)
|
||||
}
|
||||
} else {
|
||||
// 新提醒直接通知
|
||||
flag = true
|
||||
dao.Cache.Set(nID, NotificationHistory{
|
||||
Duration: firstNotificationDelay,
|
||||
Until: time.Now().Add(firstNotificationDelay),
|
||||
}, firstNotificationDelay+time.Minute*10)
|
||||
}
|
||||
|
||||
if !flag {
|
||||
return
|
||||
if !flag {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 发出通知
|
||||
notificationsLock.RLock()
|
||||
defer notificationsLock.RUnlock()
|
||||
|
||||
Reference in New Issue
Block a user