可选的通知信息 IP 不打码

This commit is contained in:
naiba 2022-02-19 14:29:06 +08:00
parent e82ffd466a
commit 520f8d2170
7 changed files with 49 additions and 30 deletions

View File

@ -4,7 +4,7 @@
<br> <br>
<small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small> <small><i>LOGO designed by <a href="https://xio.ng" target="_blank">熊大</a> .</i></small>
<br><br> <br><br>
<img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.12.9&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.8.1-brightgreen?style=for-the-badge&logo=linux"> <img src="https://img.shields.io/github/workflow/status/naiba/nezha/Dashboard%20image?label=Dash%20v0.12.10&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.8.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>
@ -161,7 +161,7 @@ URL 里面也可放置占位符,请求时会进行简单的字符串替换。
- 默认主题更改进度条颜色示例 - 默认主题更改进度条颜色示例
``` ```html
<style> <style>
.ui.fine.progress> .bar { .ui.fine.progress> .bar {
background-color: pink !important; background-color: pink !important;
@ -171,7 +171,7 @@ URL 里面也可放置占位符,请求时会进行简单的字符串替换。
- DayNight 主题更改进度条颜色、修改页脚示例(来自 [@hyt-allen-xu](https://github.com/hyt-allen-xu) - DayNight 主题更改进度条颜色、修改页脚示例(来自 [@hyt-allen-xu](https://github.com/hyt-allen-xu)
``` ```html
<style> <style>
.ui.fine.progress> .progress-bar { .ui.fine.progress> .progress-bar {
background-color: #00a7d0 !important; background-color: #00a7d0 !important;
@ -188,7 +188,7 @@ URL 里面也可放置占位符,请求时会进行简单的字符串替换。
- 默认主题修改 LOGO、修改页脚示例来自 [@iLay1678](https://github.com/iLay1678) - 默认主题修改 LOGO、修改页脚示例来自 [@iLay1678](https://github.com/iLay1678)
``` ```html
<style> <style>
.right.menu>a{ .right.menu>a{
visibility: hidden; visibility: hidden;
@ -214,7 +214,7 @@ URL 里面也可放置占位符,请求时会进行简单的字符串替换。
- hotaru 主题更改背景图片示例 - hotaru 主题更改背景图片示例
``` ```html
<style> <style>
.hotaru-cover { .hotaru-cover {
background: url(https://s3.ax1x.com/2020/12/08/DzHv6A.jpg) center; background: url(https://s3.ax1x.com/2020/12/08/DzHv6A.jpg) center;

View File

@ -503,15 +503,17 @@ func (ma *memberAPI) logout(c *gin.Context) {
} }
type settingForm struct { type settingForm struct {
Title string Title string
Admin string Admin string
Theme string Theme string
CustomCode string CustomCode string
ViewPassword string ViewPassword string
EnableIPChangeNotification string IgnoredIPNotification string
IgnoredIPNotification string GRPCHost string
GRPCHost string Cover uint8
Cover uint8
EnableIPChangeNotification string
EnablePlainIPInNotification string
} }
func (ma *memberAPI) updateSetting(c *gin.Context) { func (ma *memberAPI) updateSetting(c *gin.Context) {
@ -524,6 +526,7 @@ func (ma *memberAPI) updateSetting(c *gin.Context) {
return return
} }
singleton.Conf.EnableIPChangeNotification = sf.EnableIPChangeNotification == "on" singleton.Conf.EnableIPChangeNotification = sf.EnableIPChangeNotification == "on"
singleton.Conf.EnablePlainIPInNotification = sf.EnablePlainIPInNotification == "on"
singleton.Conf.Cover = sf.Cover singleton.Conf.Cover = sf.Cover
singleton.Conf.GRPCHost = sf.GRPCHost singleton.Conf.GRPCHost = sf.GRPCHost
singleton.Conf.IgnoredIPNotification = sf.IgnoredIPNotification singleton.Conf.IgnoredIPNotification = sf.IgnoredIPNotification

View File

@ -35,12 +35,14 @@ type Config struct {
ClientID string ClientID string
ClientSecret string ClientSecret string
} }
HTTPPort uint HTTPPort uint
GRPCPort uint GRPCPort uint
GRPCHost string GRPCHost string
EnableIPChangeNotification bool ProxyGRPCPort uint
ProxyGRPCPort uint TLS bool
TLS bool
EnableIPChangeNotification bool
EnablePlainIPInNotification bool
// IP变更提醒 // IP变更提醒
Cover uint8 // 覆盖范围 Cover uint8 // 覆盖范围

View File

@ -53,12 +53,18 @@
value="{{.Conf.IgnoredIPNotification}}"> value="{{.Conf.IgnoredIPNotification}}">
</div> </div>
<div class="field"> <div class="field">
<div class="ui nf-ssl checkbox"> <div class="ui nf-ssl checkbox ip-change">
<input name="EnableIPChangeNotification" type="checkbox" tabindex="0" class="hidden"> <input name="EnableIPChangeNotification" type="checkbox" tabindex="0" class="hidden">
<label>启用</label> <label>启用</label>
</div> </div>
</div> </div>
</div> </div>
<div class="field">
<div class="ui nf-ssl checkbox plain-ip">
<input name="EnablePlainIPInNotification" type="checkbox" tabindex="0" class="hidden">
<label>通知信息IP不打码</label>
</div>
</div>
<button class="ui button" type="submit">保存</button> <button class="ui button" type="submit">保存</button>
</form> </form>
</div> </div>
@ -97,10 +103,12 @@
return false; return false;
}) })
$('.checkbox').checkbox() $('.checkbox').checkbox()
$('#settingForm').find("select[name=Cover]") $('#settingForm').find("select[name=Cover]").val({{.Conf.Cover }});
.val({{.Conf.Cover }});
{{if .Conf.EnableIPChangeNotification}} {{if .Conf.EnableIPChangeNotification}}
$('.checkbox').checkbox('set checked') $('.checkbox.ip-change').checkbox('set checked')
{{ end }}
{{if .Conf.EnablePlainIPInNotification}}
$('.checkbox.plain-ip').checkbox('set checked')
{{ end }} {{ end }}
</script> </script>
{{end}} {{end}}

View File

@ -6,7 +6,6 @@ import (
"time" "time"
"github.com/naiba/nezha/model" "github.com/naiba/nezha/model"
"github.com/naiba/nezha/pkg/utils"
pb "github.com/naiba/nezha/proto" pb "github.com/naiba/nezha/proto"
"github.com/naiba/nezha/service/singleton" "github.com/naiba/nezha/service/singleton"
) )
@ -106,7 +105,7 @@ func (s *NezhaHandler) ReportSystemInfo(c context.Context, r *pb.Host) (*pb.Rece
singleton.ServerList[clientID].Host.IP != host.IP { singleton.ServerList[clientID].Host.IP != host.IP {
singleton.SendNotification(fmt.Sprintf( singleton.SendNotification(fmt.Sprintf(
"[IP变更] %s 旧IP%s新IP%s。", "[IP变更] %s 旧IP%s新IP%s。",
singleton.ServerList[clientID].Name, utils.IPDesensitize(singleton.ServerList[clientID].Host.IP), utils.IPDesensitize(host.IP)), true) singleton.ServerList[clientID].Name, singleton.IPDesensitize(singleton.ServerList[clientID].Host.IP), singleton.IPDesensitize(host.IP)), true)
} }
// 判断是否是机器重启,如果是机器重启要录入最后记录的流量里面 // 判断是否是机器重启,如果是机器重启要录入最后记录的流量里面

View File

@ -7,7 +7,6 @@ import (
"time" "time"
"github.com/naiba/nezha/model" "github.com/naiba/nezha/model"
"github.com/naiba/nezha/pkg/utils"
) )
const ( const (
@ -140,11 +139,11 @@ func checkStatus() {
max, passed := alert.Check(alertsStore[alert.ID][server.ID]) max, passed := alert.Check(alertsStore[alert.ID][server.ID])
if !passed { if !passed {
alertsPrevState[alert.ID][server.ID] = _RuleCheckFail alertsPrevState[alert.ID][server.ID] = _RuleCheckFail
message := fmt.Sprintf("[主机故障] %s(%s) 规则:%s", server.Name, utils.IPDesensitize(server.Host.IP), alert.Name) message := fmt.Sprintf("[主机故障] %s(%s) 规则:%s", server.Name, IPDesensitize(server.Host.IP), alert.Name)
go SendNotification(message, true) go SendNotification(message, true)
} else { } else {
if alertsPrevState[alert.ID][server.ID] == _RuleCheckFail { if alertsPrevState[alert.ID][server.ID] == _RuleCheckFail {
message := fmt.Sprintf("[主机恢复] %s(%s) 规则:%s", server.Name, utils.IPDesensitize(server.Host.IP), alert.Name) message := fmt.Sprintf("[主机恢复] %s(%s) 规则:%s", server.Name, IPDesensitize(server.Host.IP), alert.Name)
go SendNotification(message, true) go SendNotification(message, true)
} }
alertsPrevState[alert.ID][server.ID] = _RuleCheckPass alertsPrevState[alert.ID][server.ID] = _RuleCheckPass

View File

@ -10,10 +10,11 @@ import (
"gorm.io/gorm" "gorm.io/gorm"
"github.com/naiba/nezha/model" "github.com/naiba/nezha/model"
"github.com/naiba/nezha/pkg/utils"
pb "github.com/naiba/nezha/proto" pb "github.com/naiba/nezha/proto"
) )
var Version = "v0.12.9" // !!记得修改 README 中的 badge 版本!! var Version = "v0.12.10" // !!记得修改 README 中的 badge 版本!!
var ( var (
Conf *model.Config Conf *model.Config
@ -84,3 +85,10 @@ func CronTrigger(cr model.Cron) func() {
} }
} }
} }
func IPDesensitize(ip string) string {
if Conf.EnablePlainIPInNotification {
return ip
}
return utils.IPDesensitize(ip)
}