通知内 IP 脱敏

This commit is contained in:
naiba
2021-05-27 20:48:12 +08:00
parent 06914eed99
commit 2b05dcfc23
9 changed files with 76 additions and 8 deletions

View File

@@ -7,6 +7,7 @@ import (
"time"
"github.com/naiba/nezha/model"
"github.com/naiba/nezha/pkg/utils"
)
// 报警规则
@@ -100,7 +101,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)
message := fmt.Sprintf("报警规则:%s服务器%s(%s),逮到咯,快去看看!", alert.Name, server.Name, utils.IPDesensitize(server.Host.IP))
go SendNotification(message, true)
}
// 清理旧数据

View File

@@ -69,7 +69,7 @@ func CronTrigger(c *model.Cron) {
Type: model.TaskTypeCommand,
})
} else {
SendNotification(fmt.Sprintf("计划任务:%s服务器%d 离线,无法执行。", c.Name, c.Servers[j]), false)
SendNotification(fmt.Sprintf("计划任务:%s服务器%s 离线,无法执行。", c.Name, ServerList[c.Servers[j]].Name), false)
}
}
}

View File

@@ -275,7 +275,9 @@ func (ss *ServiceSentinel) worker() {
}
stateStr := getStateStr(upPercent)
if Conf.Debug {
log.Println("服务监控上报:", ss.monitors[mh.MonitorID].Target, stateStr, "上报者:", r.Reporter, "是否正常:", mh.Successful, "请求输出:", mh.Data)
ServerLock.RLock()
log.Println("服务监控上报:", ss.monitors[mh.MonitorID].Target, stateStr, "上报者:", ServerList[r.Reporter].Name, "是否正常:", mh.Successful, "请求输出:", mh.Data)
ServerLock.RUnlock()
}
if stateStr == "故障" || stateStr != ss.lastStatus[mh.MonitorID] {
ss.monitorsLock.RLock()

View File

@@ -31,11 +31,13 @@ func (s *NezhaHandler) ReportTask(c context.Context, r *pb.TaskResult) (*pb.Rece
defer dao.CronLock.RUnlock()
cr := dao.Crons[r.GetId()]
if cr != nil {
dao.ServerLock.RLock()
defer dao.ServerLock.RUnlock()
if cr.PushSuccessful && r.GetSuccessful() {
dao.SendNotification(fmt.Sprintf("成功计划任务:%s ,服务器:%d,日志:\n%s", cr.Name, clientID, r.GetData()), false)
dao.SendNotification(fmt.Sprintf("成功计划任务:%s ,服务器:%s,日志:\n%s", cr.Name, dao.ServerList[clientID].Name, r.GetData()), false)
}
if !r.GetSuccessful() {
dao.SendNotification(fmt.Sprintf("失败计划任务:%s ,服务器:%d,日志:\n%s", cr.Name, clientID, r.GetData()), false)
dao.SendNotification(fmt.Sprintf("失败计划任务:%s ,服务器:%s,日志:\n%s", cr.Name, dao.ServerList[clientID].Name, r.GetData()), false)
}
dao.DB.Model(cr).Updates(model.Cron{
LastExecutedAt: time.Now().Add(time.Second * -1 * time.Duration(r.GetDelay())),