mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
✨ feat: ip change notification close #31
This commit is contained in:
@@ -158,7 +158,7 @@ func checkStatus() {
|
||||
}
|
||||
if flag {
|
||||
message := fmt.Sprintf("报警规则:%s,服务器:%s(%s),%s,逮到咯,快去看看!", alert.Name, server.Name, server.Host.IP, desc)
|
||||
go sendNotification(message)
|
||||
go SendNotification(message)
|
||||
}
|
||||
}
|
||||
// 清理旧数据
|
||||
@@ -169,7 +169,7 @@ func checkStatus() {
|
||||
}
|
||||
}
|
||||
|
||||
func sendNotification(desc string) {
|
||||
func SendNotification(desc string) {
|
||||
notificationsLock.RLock()
|
||||
defer notificationsLock.RUnlock()
|
||||
for i := 0; i < len(notifications); i++ {
|
||||
|
||||
@@ -2,11 +2,13 @@ package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/naiba/nezha/model"
|
||||
pb "github.com/naiba/nezha/proto"
|
||||
"github.com/naiba/nezha/service/alertmanager"
|
||||
"github.com/naiba/nezha/service/dao"
|
||||
)
|
||||
|
||||
@@ -60,6 +62,14 @@ func (s *NezhaHandler) Register(c context.Context, r *pb.Host) (*pb.Receipt, err
|
||||
host := model.PB2Host(r)
|
||||
dao.ServerLock.RLock()
|
||||
defer dao.ServerLock.RUnlock()
|
||||
if dao.ServerList[clientID].Host != nil &&
|
||||
dao.ServerList[clientID].Host.IP != "" &&
|
||||
host.IP != "" &&
|
||||
dao.ServerList[clientID].Host.IP != host.IP {
|
||||
alertmanager.SendNotification(fmt.Sprintf(
|
||||
"服务器:%s IP变更提醒,旧IP:%s,新IP:%s。",
|
||||
dao.ServerList[clientID].Name, dao.ServerList[clientID].Host.IP, host.IP))
|
||||
}
|
||||
dao.ServerList[clientID].Host = &host
|
||||
return &pb.Receipt{Proced: true}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user