From fc9a65d18c4ada6f7b4168a6c99b2a8e7536faec Mon Sep 17 00:00:00 2001 From: Akkia Date: Sun, 24 Apr 2022 21:21:03 +0800 Subject: [PATCH 1/2] =?UTF-8?q?update:=20#SERVER.IP#=E4=BB=85=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E4=B8=80=E4=B8=AAIP(=E4=BC=98=E5=85=88=E8=BF=94?= =?UTF-8?q?=E5=9B=9Eipv4=E5=9C=B0=E5=9D=80)=EF=BD=9C=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=8E=B7=E5=8F=96ipv4=E4=B8=8Eipv6=E5=9C=B0=E5=9D=80=E7=9A=84?= =?UTF-8?q?=E5=8D=A0=E4=BD=8D=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/notification.go | 32 +++++++++++++++++-- resource/template/component/notification.html | 2 +- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/model/notification.go b/model/notification.go index 448d31b..4606c52 100644 --- a/model/notification.go +++ b/model/notification.go @@ -159,11 +159,37 @@ func (ns *NotificationServerBundle) Send(message string) error { // replaceParamInString 替换字符串中的占位符 func replaceParamsInString(s *Server, str string, message string, mod func(string) string) string { + // IP处理 + ipv4 := "" + ipv6 := "" + validIP := "" + if s != nil { + ipList := strings.Split(s.Host.IP, "/") + if len(ipList) > 1 { + // 双栈 + ipv4 = ipList[0] + ipv6 = ipList[1] + validIP = ipv4 + } else if len(ipList) == 1 { + // 仅ipv4|ipv6 + if strings.Contains(ipList[0], ":") { + ipv6 = ipList[0] + validIP = ipv6 + } else { + ipv4 = ipList[0] + validIP = ipv4 + } + } + } + if mod != nil { str = strings.ReplaceAll(str, "#NEZHA#", mod(message)) if s != nil { + str = strings.ReplaceAll(str, "#SERVER.NAME#", mod(s.Name)) - str = strings.ReplaceAll(str, "#SERVER.IP#", mod(s.Host.IP)) + str = strings.ReplaceAll(str, "#SERVER.IP#", mod(validIP)) + str = strings.ReplaceAll(str, "#SERVER.IPV4#", mod(ipv4)) + str = strings.ReplaceAll(str, "#SERVER.IPV6#", mod(ipv6)) str = strings.ReplaceAll(str, "#SERVER.CPU#", mod(fmt.Sprintf("%f", s.State.CPU))) str = strings.ReplaceAll(str, "#SERVER.MEM#", mod(fmt.Sprintf("%d", s.State.MemUsed))) str = strings.ReplaceAll(str, "#SERVER.SWAP#", mod(fmt.Sprintf("%d", s.State.SwapUsed))) @@ -182,7 +208,9 @@ func replaceParamsInString(s *Server, str string, message string, mod func(strin str = strings.ReplaceAll(str, "#NEZHA#", message) if s != nil { str = strings.ReplaceAll(str, "#SERVER.NAME#", s.Name) - str = strings.ReplaceAll(str, "#SERVER.IP#", s.Host.IP) + str = strings.ReplaceAll(str, "#SERVER.IP#", validIP) + str = strings.ReplaceAll(str, "#SERVER.IPV4#", ipv4) + str = strings.ReplaceAll(str, "#SERVER.IPV6#", ipv6) str = strings.ReplaceAll(str, "#SERVER.CPU#", fmt.Sprintf("%f", s.State.CPU)) str = strings.ReplaceAll(str, "#SERVER.MEM#", fmt.Sprintf("%d", s.State.MemUsed)) str = strings.ReplaceAll(str, "#SERVER.SWAP#", fmt.Sprintf("%d", s.State.SwapUsed)) diff --git a/resource/template/component/notification.html b/resource/template/component/notification.html index 4df0923..98086ae 100644 --- a/resource/template/component/notification.html +++ b/resource/template/component/notification.html @@ -36,7 +36,7 @@
- +
From 55a439a17d7ffdfc59f26da990a79220df629c56 Mon Sep 17 00:00:00 2001 From: naiba Date: Sun, 24 Apr 2022 21:29:45 +0800 Subject: [PATCH 2/2] dashboard v0.12.24 --- README.md | 2 +- service/singleton/singleton.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f843be4..4787fe5 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@
LOGO designed by 熊大 .

-    +   

:trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,计划任务和在线终端。

diff --git a/service/singleton/singleton.go b/service/singleton/singleton.go index 0b4fd44..116171e 100644 --- a/service/singleton/singleton.go +++ b/service/singleton/singleton.go @@ -12,7 +12,7 @@ import ( "github.com/naiba/nezha/pkg/utils" ) -var Version = "v0.12.23" // !!记得修改 README 中的 badge 版本!! +var Version = "v0.12.24" // !!记得修改 README 中的 badge 版本!! var ( Conf *model.Config