mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
🚸 [dashboard v0.3.8] improve: 不过滤的通知
This commit is contained in:
parent
e30bdbb87c
commit
175eb996d3
@ -1,6 +1,6 @@
|
||||
# 哪吒面板
|
||||
|
||||
![dashboard](https://img.shields.io/badge/管理面板-v0.3.7-brightgreen?style=for-the-badge&logo=github) ![Agent release](https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github)
|
||||
![dashboard](https://img.shields.io/badge/管理面板-v0.3.8-brightgreen?style=for-the-badge&logo=github) ![Agent release](https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github)
|
||||
|
||||
系统状态监控报警、API(SSL证书变更、即将到期、到期)/TCP端口存活/PING 监控、计划任务(可以定时在Agent上执行命令,备份、重启、What ever you want)、极省资源,64M 服务器也能装 agent。
|
||||
|
||||
|
@ -281,7 +281,7 @@ func (ma *memberAPI) addOrEditCron(c *gin.Context) {
|
||||
Type: model.TaskTypeCommand,
|
||||
})
|
||||
} else {
|
||||
alertmanager.SendNotification(fmt.Sprintf("计划任务:%s,服务器:%d 离线,无法执行。", cr.Name, cr.Servers[j]))
|
||||
alertmanager.SendNotification(fmt.Sprintf("计划任务:%s,服务器:%d 离线,无法执行。", cr.Name, cr.Servers[j]), false)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -90,7 +90,7 @@ func loadCrons() {
|
||||
Type: model.TaskTypeCommand,
|
||||
})
|
||||
} else {
|
||||
alertmanager.SendNotification(fmt.Sprintf("计划任务:%s,服务器:%d 离线,无法执行。", cr.Name, cr.Servers[j]))
|
||||
alertmanager.SendNotification(fmt.Sprintf("计划任务:%s,服务器:%d 离线,无法执行。", cr.Name, cr.Servers[j]), false)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -10,7 +10,7 @@
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>计划</label>
|
||||
<input type="text" name="Scheduler" placeholder="* 3 * * *(每天3点)">
|
||||
<input type="text" name="Scheduler" placeholder="0 3 * * *(每天3点)">
|
||||
</div>
|
||||
<div class="field">
|
||||
<label>命令</label>
|
||||
|
@ -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()
|
||||
|
@ -34,7 +34,7 @@ var CronLock sync.RWMutex
|
||||
var Crons map[uint64]*model.Cron
|
||||
var Cron *cron.Cron
|
||||
|
||||
var Version = "v0.3.7"
|
||||
var Version = "v0.3.8"
|
||||
|
||||
func ReSortServer() {
|
||||
ServerLock.RLock()
|
||||
|
@ -52,7 +52,7 @@ func (s *NezhaHandler) ReportTask(c context.Context, r *pb.TaskResult) (*pb.Rece
|
||||
if errMsg != "" {
|
||||
var monitor model.Monitor
|
||||
dao.DB.First(&monitor, "id = ?", r.GetId())
|
||||
alertmanager.SendNotification(fmt.Sprintf("服务监控:%s %s", monitor.Name, errMsg))
|
||||
alertmanager.SendNotification(fmt.Sprintf("服务监控:%s %s", monitor.Name, errMsg), true)
|
||||
}
|
||||
}
|
||||
if r.GetType() == model.TaskTypeCommand {
|
||||
@ -62,10 +62,10 @@ func (s *NezhaHandler) ReportTask(c context.Context, r *pb.TaskResult) (*pb.Rece
|
||||
cr := dao.Crons[r.GetId()]
|
||||
if cr != nil {
|
||||
if cr.PushSuccessful && r.GetSuccessful() {
|
||||
alertmanager.SendNotification(fmt.Sprintf("成功计划任务:%s ,服务器:%d,日志:\n%s", cr.Name, clientID, r.GetData()))
|
||||
alertmanager.SendNotification(fmt.Sprintf("成功计划任务:%s ,服务器:%d,日志:\n%s", cr.Name, clientID, r.GetData()), false)
|
||||
}
|
||||
if !r.GetSuccessful() {
|
||||
alertmanager.SendNotification(fmt.Sprintf("失败计划任务:%s ,服务器:%d,日志:\n%s", cr.Name, clientID, r.GetData()))
|
||||
alertmanager.SendNotification(fmt.Sprintf("失败计划任务:%s ,服务器:%d,日志:\n%s", cr.Name, clientID, r.GetData()), false)
|
||||
}
|
||||
dao.DB.Model(cr).Updates(model.Cron{
|
||||
LastExecutedAt: time.Now().Add(time.Second * -1 * time.Duration(r.GetDelay())),
|
||||
@ -129,7 +129,7 @@ func (s *NezhaHandler) ReportSystemInfo(c context.Context, r *pb.Host) (*pb.Rece
|
||||
dao.ServerList[clientID].Host.IP != host.IP {
|
||||
alertmanager.SendNotification(fmt.Sprintf(
|
||||
"IP变更提醒 服务器:%s ,旧IP:%s,新IP:%s。",
|
||||
dao.ServerList[clientID].Name, dao.ServerList[clientID].Host.IP, host.IP))
|
||||
dao.ServerList[clientID].Name, dao.ServerList[clientID].Host.IP, host.IP), true)
|
||||
}
|
||||
dao.ServerList[clientID].Host = &host
|
||||
return &pb.Receipt{Proced: true}, nil
|
||||
|
Loading…
Reference in New Issue
Block a user