🚸 IP 变更提醒增强

This commit is contained in:
naiba 2021-06-22 14:05:36 +08:00
parent d59acfa824
commit 365148e0ac
6 changed files with 53 additions and 22 deletions

View File

@ -1,7 +1,7 @@
<div align="center"> <div align="center">
<img width="500" style="max-width:100%" src="resource/static/brand.png" title="哪吒监控"> <img width="500" style="max-width:100%" src="resource/static/brand.png" title="哪吒监控">
<br><br> <br><br>
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.8.2&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.6.1-brightgreen?style=for-the-badge&logo=linux"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.8.3&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.6.1-brightgreen?style=for-the-badge&logo=linux">
<br> <br>
<br> <br>
<p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p> <p>:trollface: <b>哪吒监控</b> 一站式轻监控轻运维系统。支持系统状态、HTTP(SSL 证书变更、即将到期、到期)、TCP、Ping 监控报警,命令批量执行和计划任务。</p>

View File

@ -449,6 +449,7 @@ type settingForm struct {
EnableIPChangeNotification string EnableIPChangeNotification string
IgnoredIPNotification string IgnoredIPNotification string
Oauth2Type string Oauth2Type string
Cover uint8
} }
func (ma *memberAPI) updateSetting(c *gin.Context) { func (ma *memberAPI) updateSetting(c *gin.Context) {
@ -461,6 +462,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
return return
} }
dao.Conf.EnableIPChangeNotification = sf.EnableIPChangeNotification == "on" dao.Conf.EnableIPChangeNotification = sf.EnableIPChangeNotification == "on"
dao.Conf.Cover = sf.Cover
dao.Conf.IgnoredIPNotification = sf.IgnoredIPNotification dao.Conf.IgnoredIPNotification = sf.IgnoredIPNotification
dao.Conf.Site.Brand = sf.Title dao.Conf.Site.Brand = sf.Title
dao.Conf.Site.Theme = sf.Theme dao.Conf.Site.Theme = sf.Theme

View File

@ -17,6 +17,11 @@ const (
ConfigTypeGitee = "gitee" ConfigTypeGitee = "gitee"
) )
const (
ConfigCoverAll = iota
ConfigCoverIgnoreAll
)
type Config struct { type Config struct {
Debug bool Debug bool
Site struct { Site struct {
@ -35,10 +40,13 @@ type Config struct {
HTTPPort uint HTTPPort uint
GRPCPort uint GRPCPort uint
EnableIPChangeNotification bool EnableIPChangeNotification bool
IgnoredIPNotification string // 忽略IP变更提醒的服务器列表
// IP变更提醒
Cover uint8 // 覆盖范围
IgnoredIPNotification string // 特定服务器
v *viper.Viper v *viper.Viper
IgnoredIPNotificationServerIDs map[uint64]struct{} IgnoredIPNotificationServerIDs map[uint64]bool
} }
func (c *Config) Read(path string) error { func (c *Config) Read(path string) error {
@ -70,12 +78,12 @@ func (c *Config) Read(path string) error {
} }
func (c *Config) updateIgnoredIPNotificationID() { func (c *Config) updateIgnoredIPNotificationID() {
c.IgnoredIPNotificationServerIDs = make(map[uint64]struct{}) c.IgnoredIPNotificationServerIDs = make(map[uint64]bool)
splitedIDs := strings.Split(c.IgnoredIPNotification, ",") splitedIDs := strings.Split(c.IgnoredIPNotification, ",")
for i := 0; i < len(splitedIDs); i++ { for i := 0; i < len(splitedIDs); i++ {
id, _ := strconv.ParseUint(splitedIDs[i], 10, 64) id, _ := strconv.ParseUint(splitedIDs[i], 10, 64)
if id > 0 { if id > 0 {
c.IgnoredIPNotificationServerIDs[id] = struct{}{} c.IgnoredIPNotificationServerIDs[id] = true
} }
} }
} }

View File

@ -11,8 +11,10 @@
<div class="field"> <div class="field">
<label>登录类型</label> <label>登录类型</label>
<select name="Oauth2Type"> <select name="Oauth2Type">
<option value="github"{{if eq .Conf.Oauth2.Type "github"}} selected="selected"{{end}}>GitHub</option> <option value="github" {{if eq .Conf.Oauth2.Type "github" }} selected="selected" {{end}}>GitHub
<option value="gitee"{{if eq .Conf.Oauth2.Type "gitee"}} selected="selected"{{end}}>Gitee</option> </option>
<option value="gitee" {{if eq .Conf.Oauth2.Type "gitee" }} selected="selected" {{end}}>Gitee
</option>
</select> </select>
</div> </div>
<div class="field"> <div class="field">
@ -22,9 +24,12 @@
<div class="field"> <div class="field">
<label>前台主题</label> <label>前台主题</label>
<select name="Theme"> <select name="Theme">
<option value="default"{{if eq .Conf.Site.Theme "default"}} selected="selected"{{end}}>默认主题</option> <option value="default" {{if eq .Conf.Site.Theme "default" }} selected="selected" {{end}}>默认主题
<option value="daynight"{{if eq .Conf.Site.Theme "daynight"}} selected="selected"{{end}}>JackieSung DayNight</option> </option>
<option value="hotaru"{{if eq .Conf.Site.Theme "hotaru"}} selected="selected"{{end}}>CokeMine Hotaru</option> <option value="daynight" {{if eq .Conf.Site.Theme "daynight" }} selected="selected" {{end}}>
JackieSung DayNight</option>
<option value="hotaru" {{if eq .Conf.Site.Theme "hotaru" }} selected="selected" {{end}}>CokeMine
Hotaru</option>
</select> </select>
</div> </div>
<div class="field"> <div class="field">
@ -36,13 +41,26 @@
<input type="text" name="ViewPassword" placeholder="" value="{{.Conf.Site.ViewPassword}}"> <input type="text" name="ViewPassword" placeholder="" value="{{.Conf.Site.ViewPassword}}">
</div> </div>
<div class="field"> <div class="field">
<label>IP 变更忽略</label> <label>IP 变更提醒</label>
<input type="text" name="IgnoredIPNotification" placeholder="服务器ID 以逗号隔开 1001,1002,1003" value="{{.Conf.IgnoredIPNotification}}"> </div>
<div class="ui segment">
<div class="field">
<label>覆盖范围</label>
<select name="Cover" class="ui fluid dropdown">
<option value=0>覆盖所有,仅特定服务器不提醒</option>
<option value=1>忽略所有,仅提醒特定服务器</option>
</select>
</div>
<div class="field">
<label>特定服务器</label>
<input type="text" name="IgnoredIPNotification" placeholder="服务器ID 以逗号隔开 1001,1002,1003"
value="{{.Conf.IgnoredIPNotification}}">
</div> </div>
<div class="field"> <div class="field">
<div class="ui nf-ssl checkbox"> <div class="ui nf-ssl checkbox">
<input name="EnableIPChangeNotification" type="checkbox" tabindex="0" class="hidden"> <input name="EnableIPChangeNotification" type="checkbox" tabindex="0" class="hidden">
<label>开启 IP 变更提醒</label> <label>启用</label>
</div>
</div> </div>
</div> </div>
<button class="ui button" type="submit">保存</button> <button class="ui button" type="submit">保存</button>
@ -82,6 +100,8 @@
return false; return false;
}) })
$('.checkbox').checkbox() $('.checkbox').checkbox()
$('#settingForm').find("select[name=Cover]")
.val({{.Conf.Cover}});
{{ if .Conf.EnableIPChangeNotification}} {{ if .Conf.EnableIPChangeNotification}}
$('.checkbox').checkbox('set checked') $('.checkbox').checkbox('set checked')
{{ end }} {{ end }}

View File

@ -13,7 +13,7 @@ import (
pb "github.com/naiba/nezha/proto" pb "github.com/naiba/nezha/proto"
) )
var Version = "v0.8.2" // !!记得修改 README 中的 badge 版本!! var Version = "v0.8.3" // !!记得修改 README 中的 badge 版本!!
const ( const (
SnapshotDelay = 3 SnapshotDelay = 3

View File

@ -86,7 +86,8 @@ func (s *NezhaHandler) ReportSystemInfo(c context.Context, r *pb.Host) (*pb.Rece
dao.ServerLock.RLock() dao.ServerLock.RLock()
defer dao.ServerLock.RUnlock() defer dao.ServerLock.RUnlock()
if dao.Conf.EnableIPChangeNotification && if dao.Conf.EnableIPChangeNotification &&
dao.Conf.IgnoredIPNotificationServerIDs[clientID] != struct{}{} && ((dao.Conf.Cover == model.ConfigCoverAll && !dao.Conf.IgnoredIPNotificationServerIDs[clientID]) ||
(dao.Conf.Cover == model.ConfigCoverIgnoreAll && dao.Conf.IgnoredIPNotificationServerIDs[clientID])) &&
dao.ServerList[clientID].Host != nil && dao.ServerList[clientID].Host != nil &&
dao.ServerList[clientID].Host.IP != "" && dao.ServerList[clientID].Host.IP != "" &&
host.IP != "" && host.IP != "" &&