mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
WIP: 添加更多的占位符以支持基于服务器状态指标构造自定义的HTTP请求
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"crypto/md5" // #nosec
|
||||
"encoding/hex"
|
||||
"log"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -143,10 +145,24 @@ func SendNotification(notificationTag string, desc string, mutable bool) {
|
||||
log.Println("尝试通知", n.Name)
|
||||
}
|
||||
for _, n := range NotificationList[notificationTag] {
|
||||
if err := n.Send(desc); err != nil {
|
||||
server := findServerInMsg(desc)
|
||||
ns := model.NotificationServerBundle{
|
||||
Notification: n,
|
||||
Server: server,
|
||||
}
|
||||
if err := ns.Send(desc); err != nil {
|
||||
log.Println("NEZHA>> 向 ", n.Name, " 发送通知失败:", err)
|
||||
} else {
|
||||
log.Println("NEZHA>> 向 ", n.Name, " 发送通知成功:")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// findServerInMsg 通过msg字符串中的$ServerID$ 返回Server对象 未找到会返回nil
|
||||
func findServerInMsg(msg string) *model.Server {
|
||||
reg1 := regexp.MustCompile(`^\$\d+`)
|
||||
reg2 := regexp.MustCompile(`[^$]+`)
|
||||
ServerIDStr := reg2.FindString(reg1.FindString(msg))
|
||||
ServerID, _ := strconv.ParseUint(ServerIDStr, 10, 64)
|
||||
return ServerList[ServerID]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user