Skip to content

Commit

Permalink
NAT64 的机器一直报 IP 变更,加忽略!
Browse files Browse the repository at this point in the history
  • Loading branch information
naiba committed Apr 7, 2021
1 parent 40b9ffd commit 3300152
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 21 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<div align="center" style="background-color: white">
<img width="500" style="max-width:100%" src="https://raw.githubusercontent.com/naiba/nezha/master/resource/static/brand.png" title="哪吒监控">
<br><br>
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.4.14&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.4.9-brightgreen?style=for-the-badge&logo=linux">
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.4.15&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/github/v/release/naiba/nezha?color=brightgreen&label=Agent&style=for-the-badge&logo=github">&nbsp;<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Agent%20release?label=Agent%20CI&logo=github&style=for-the-badge">&nbsp;<img src="https://img.shields.io/badge/Installer-v0.4.10-brightgreen?style=for-the-badge&logo=linux">
<br>
<p>:trollface: 哪吒监控 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p>
</div>

\>> QQ 交流群: ~~955957790~~ 各式心态的人都有,解散了省心,**自2021年3月26起不再提供任何支持,接受PR,但不再更新。**
\>> QQ 交流群: ~~955957790~~ 已解散,**自2021年3月26起不再提供技术支持,接受PR。**
\>> 交流论坛:正在选型搭建中…… 欢迎想建设社区的铁子与奶爸取得联系。

\>> [我们的用户](https://www.google.com/search?q="powered+by+哪吒监控%7C哪吒面板"&filter=0) (Google)

Expand Down
2 changes: 2 additions & 0 deletions cmd/dashboard/controller/member_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ type settingForm struct {
CustomCode string
ViewPassword string
EnableIPChangeNotification string
IgnoredIPNotification string
Oauth2Type string
}

Expand All @@ -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
Expand Down
20 changes: 19 additions & 1 deletion model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"

"github.com/fsnotify/fsnotify"
"github.com/spf13/viper"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions resource/template/dashboard/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
<label>前台查看密码</label>
<input type="text" name="ViewPassword" placeholder="" value="{{.Conf.Site.ViewPassword}}">
</div>
<div class="field">
<label>IP 变更忽略</label>
<input type="text" name="IgnoredIPNotification" placeholder="服务器ID 以逗号隔开 1001,1002,1003" value="{{.Conf.IgnoredIPNotification}}">
</div>
<div class="field">
<div class="ui nf-ssl checkbox">
<input name="EnableIPChangeNotification" type="checkbox" tabindex="0" class="hidden">
Expand Down
30 changes: 14 additions & 16 deletions script/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
;;

[nN][oO]|[nN])
echo "不使用中国镜像"
;;
*)
echo "使用中国镜像"
CN=true
;;
[yY][eE][sS] | [yY])
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"
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion service/dao/dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion service/rpc/nezha.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package rpc
import (
"context"
"fmt"
"log"
"strings"
"time"

Expand All @@ -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()
}
Expand Down Expand Up @@ -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 != "" &&
Expand Down

0 comments on commit 3300152

Please sign in to comment.