From 330015290fd65a55833bc9ec98cbe942cd96c7a6 Mon Sep 17 00:00:00 2001 From: naiba Date: Wed, 7 Apr 2021 21:11:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?NAT64=20=E7=9A=84=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E4=B8=80=E7=9B=B4=E6=8A=A5=20IP=20=E5=8F=98=E6=9B=B4=EF=BC=8C?= =?UTF-8?q?=E5=8A=A0=E5=BF=BD=E7=95=A5=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 5 +++-- cmd/dashboard/controller/member_api.go | 2 ++ model/config.go | 20 ++++++++++++++++- resource/template/dashboard/setting.html | 4 ++++ script/install.sh | 28 +++++++++++------------- service/dao/dao.go | 2 +- service/rpc/nezha.go | 5 ++++- 7 files changed, 46 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 221cd15..82befbc 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,13 @@


-    +   

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

-\>> QQ 交流群: ~~955957790~~ 各式心态的人都有,解散了省心,**自2021年3月26起不再提供任何支持,接受PR,但不再更新。** +\>> QQ 交流群: ~~955957790~~ 已解散,**自2021年3月26起不再提供技术支持,接受PR。** +\>> 交流论坛:正在选型搭建中…… 欢迎想建设社区的铁子与奶爸取得联系。 \>> [我们的用户](https://www.google.com/search?q="powered+by+哪吒监控%7C哪吒面板"&filter=0) (Google) diff --git a/cmd/dashboard/controller/member_api.go b/cmd/dashboard/controller/member_api.go index 1ef2fca..e557cc9 100644 --- a/cmd/dashboard/controller/member_api.go +++ b/cmd/dashboard/controller/member_api.go @@ -447,6 +447,7 @@ type settingForm struct { CustomCode string ViewPassword string EnableIPChangeNotification string + IgnoredIPNotification string Oauth2Type string } @@ -460,6 +461,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) { return } dao.Conf.EnableIPChangeNotification = sf.EnableIPChangeNotification == "on" + dao.Conf.IgnoredIPNotification = sf.IgnoredIPNotification dao.Conf.Site.Brand = sf.Title dao.Conf.Site.Theme = sf.Theme dao.Conf.Site.CustomCode = sf.CustomCode diff --git a/model/config.go b/model/config.go index 2edfcbd..81bbb1e 100644 --- a/model/config.go +++ b/model/config.go @@ -4,6 +4,8 @@ import ( "fmt" "io/ioutil" "os" + "strconv" + "strings" "github.com/fsnotify/fsnotify" "github.com/spf13/viper" @@ -33,8 +35,10 @@ type Config struct { HTTPPort uint GRPCPort uint EnableIPChangeNotification bool + IgnoredIPNotification string // 忽略IP变更提醒的服务器列表 - v *viper.Viper + v *viper.Viper + IgnoredIPNotificationServerIDs map[uint64]struct{} } func (c *Config) Read(path string) error { @@ -54,6 +58,8 @@ func (c *Config) Read(path string) error { c.Site.Theme = "default" } + c.updateIgnoredIPNotificationID() + c.v.OnConfigChange(func(in fsnotify.Event) { c.v.Unmarshal(c) fmt.Println("配置文件更新,重载配置", c) @@ -63,7 +69,19 @@ func (c *Config) Read(path string) error { return nil } +func (c *Config) updateIgnoredIPNotificationID() { + c.IgnoredIPNotificationServerIDs = make(map[uint64]struct{}) + splitedIDs := strings.Split(c.IgnoredIPNotification, ",") + for i := 0; i < len(splitedIDs); i++ { + id, _ := strconv.ParseUint(splitedIDs[i], 10, 64) + if id > 0 { + c.IgnoredIPNotificationServerIDs[id] = struct{}{} + } + } +} + func (c *Config) Save() error { + c.updateIgnoredIPNotificationID() data, err := yaml.Marshal(c) if err != nil { return err diff --git a/resource/template/dashboard/setting.html b/resource/template/dashboard/setting.html index 5896751..39b769b 100644 --- a/resource/template/dashboard/setting.html +++ b/resource/template/dashboard/setting.html @@ -27,6 +27,10 @@ +
+ + +
diff --git a/script/install.sh b/script/install.sh index 0175309..aec2ab6 100755 --- a/script/install.sh +++ b/script/install.sh @@ -11,7 +11,7 @@ NZ_BASE_PATH="/opt/nezha" NZ_DASHBOARD_PATH="${NZ_BASE_PATH}/dashboard" NZ_AGENT_PATH="${NZ_BASE_PATH}/agent" NZ_AGENT_SERVICE="/etc/systemd/system/nezha-agent.service" -NZ_VERSION="v0.4.9" +NZ_VERSION="v0.4.10" red='\033[0;31m' green='\033[0;32m' @@ -47,21 +47,21 @@ pre_check() { echo "根据ip.sb提供的信息,当前IP可能在中国" read -r -p "是否选用中国镜像完成安装? [Y/n] " input case $input in - [yY][eE][sS]|[yY]) - echo "使用中国镜像" - CN=true - ;; + [yY][eE][sS] | [yY]) + echo "使用中国镜像" + CN=true + ;; - [nN][oO]|[nN]) - echo "不使用中国镜像" - ;; - *) - echo "使用中国镜像" - CN=true - ;; + [nN][oO] | [nN]) + echo "不使用中国镜像" + ;; + *) + echo "使用中国镜像" + CN=true + ;; esac fi - + if [[ -z "${CN}" ]]; then GITHUB_RAW_URL="raw.githubusercontent.com/naiba/nezha/master" GITHUB_URL="github.com" @@ -72,8 +72,6 @@ pre_check() { GITHUB_URL="dn-dao-github-mirror.daocloud.io" Get_Docker_URL="get.daocloud.io/docker" Get_Docker_Argu=" -s docker --mirror Aliyun" - echo "写入/etc/hosts 52.68.132.128 ghcr.io" - echo "52.68.132.128 ghcr.io" >> /etc/hosts fi } diff --git a/service/dao/dao.go b/service/dao/dao.go index ec385f8..a68d2b1 100644 --- a/service/dao/dao.go +++ b/service/dao/dao.go @@ -13,7 +13,7 @@ import ( pb "github.com/naiba/nezha/proto" ) -var Version = "v0.4.14" // !!记得修改 README 重的 badge 版本!! +var Version = "v0.4.15" // !!记得修改 README 重的 badge 版本!! const ( SnapshotDelay = 3 diff --git a/service/rpc/nezha.go b/service/rpc/nezha.go index ac23add..6539f9b 100644 --- a/service/rpc/nezha.go +++ b/service/rpc/nezha.go @@ -3,6 +3,7 @@ package rpc import ( "context" "fmt" + "log" "strings" "time" @@ -27,7 +28,7 @@ func (s *NezhaHandler) ReportTask(c context.Context, r *pb.TaskResult) (*pb.Rece if strings.HasPrefix(r.GetData(), "SSL证书错误:") { // 排除 i/o timeont、connection timeout、EOF 错误 if !strings.HasSuffix(r.GetData(), "timeout") && - r.GetData() != "EOF" && + !strings.HasSuffix(r.GetData(), "EOF") && !strings.HasSuffix(r.GetData(), "timed out") { errMsg = r.GetData() } @@ -130,7 +131,9 @@ func (s *NezhaHandler) ReportSystemInfo(c context.Context, r *pb.Host) (*pb.Rece host := model.PB2Host(r) dao.ServerLock.RLock() defer dao.ServerLock.RUnlock() + log.Println(dao.Conf.IgnoredIPNotificationServerIDs) if dao.Conf.EnableIPChangeNotification && + dao.Conf.IgnoredIPNotificationServerIDs[clientID] != struct{}{} && dao.ServerList[clientID].Host != nil && dao.ServerList[clientID].Host.IP != "" && host.IP != "" && From da4083db2f32c7ce97f8c0dc1fb2254985040982 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=82=A6=E2=82=B3=C5=82=E0=B8=BF=E2=82=B3?= Date: Wed, 7 Apr 2021 15:13:55 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 82befbc..c6a6675 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@

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

-\>> QQ 交流群: ~~955957790~~ 已解散,**自2021年3月26起不再提供技术支持,接受PR。** +\>> QQ 交流群: ~~955957790~~ 已解散,**自2021年3月26起不再提供技术支持,接受PR。**
\>> 交流论坛:正在选型搭建中…… 欢迎想建设社区的铁子与奶爸取得联系。 \>> [我们的用户](https://www.google.com/search?q="powered+by+哪吒监控%7C哪吒面板"&filter=0) (Google)