code refactor, use NotifyBuiltinChannels to control
This commit is contained in:
parent
6d27da8ad8
commit
b25c523528
|
@ -70,8 +70,8 @@ Batch = 5
|
|||
[Alerting]
|
||||
TemplatesDir = "./etc/template"
|
||||
NotifyConcurrency = 10
|
||||
# use builtin go code notify by default
|
||||
NotifyBuiltinEnable = true
|
||||
# use builtin go code notify
|
||||
NotifyBuiltinChannels = ["email", "dingtalk", "wecom", "feishu"]
|
||||
|
||||
[Alerting.CallScript]
|
||||
# built in sending capability in go code
|
||||
|
|
|
@ -153,13 +153,13 @@ type SMTPConfig struct {
|
|||
}
|
||||
|
||||
type Alerting struct {
|
||||
TemplatesDir string
|
||||
NotifyConcurrency int
|
||||
NotifyBuiltinEnable bool
|
||||
CallScript CallScript
|
||||
CallPlugin CallPlugin
|
||||
RedisPub RedisPub
|
||||
Webhook Webhook
|
||||
TemplatesDir string
|
||||
NotifyConcurrency int
|
||||
NotifyBuiltinChannels []string
|
||||
CallScript CallScript
|
||||
CallPlugin CallPlugin
|
||||
RedisPub RedisPub
|
||||
Webhook Webhook
|
||||
}
|
||||
|
||||
type CallScript struct {
|
||||
|
|
|
@ -19,6 +19,7 @@ import (
|
|||
"github.com/toolkits/pkg/file"
|
||||
"github.com/toolkits/pkg/logger"
|
||||
"github.com/toolkits/pkg/runner"
|
||||
"github.com/toolkits/pkg/slice"
|
||||
|
||||
"github.com/didi/nightingale/v5/src/models"
|
||||
"github.com/didi/nightingale/v5/src/pkg/sys"
|
||||
|
@ -123,7 +124,7 @@ func handleNotice(notice Notice, bs []byte) {
|
|||
|
||||
alertingCallPlugin(bs)
|
||||
|
||||
if !config.C.Alerting.NotifyBuiltinEnable {
|
||||
if len(config.C.Alerting.NotifyBuiltinChannels) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -173,6 +174,10 @@ func handleNotice(notice Notice, bs []byte) {
|
|||
continue
|
||||
}
|
||||
|
||||
if !slice.ContainsString(config.C.Alerting.NotifyBuiltinChannels, "email") {
|
||||
continue
|
||||
}
|
||||
|
||||
subject, has := notice.Tpls["subject.tpl"]
|
||||
if !has {
|
||||
subject = "subject.tpl not found"
|
||||
|
@ -189,6 +194,10 @@ func handleNotice(notice Notice, bs []byte) {
|
|||
continue
|
||||
}
|
||||
|
||||
if !slice.ContainsString(config.C.Alerting.NotifyBuiltinChannels, "dingtalk") {
|
||||
continue
|
||||
}
|
||||
|
||||
content, has := notice.Tpls["dingtalk.tpl"]
|
||||
if !has {
|
||||
content = "dingtalk.tpl not found"
|
||||
|
@ -205,6 +214,10 @@ func handleNotice(notice Notice, bs []byte) {
|
|||
continue
|
||||
}
|
||||
|
||||
if !slice.ContainsString(config.C.Alerting.NotifyBuiltinChannels, "wecom") {
|
||||
continue
|
||||
}
|
||||
|
||||
content, has := notice.Tpls["wecom.tpl"]
|
||||
if !has {
|
||||
content = "wecom.tpl not found"
|
||||
|
@ -218,6 +231,10 @@ func handleNotice(notice Notice, bs []byte) {
|
|||
continue
|
||||
}
|
||||
|
||||
if !slice.ContainsString(config.C.Alerting.NotifyBuiltinChannels, "feishu") {
|
||||
continue
|
||||
}
|
||||
|
||||
content, has := notice.Tpls["feishu.tpl"]
|
||||
if !has {
|
||||
content = "feishu.tpl not found"
|
||||
|
|
Loading…
Reference in New Issue