Compare commits

...

1 Commits

Author SHA1 Message Date
ning
cc709540cf feat: support webhook proxy configuration 2024-12-20 14:34:56 +08:00
2 changed files with 15 additions and 8 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/ccfos/nightingale/v6/alert/astats"
"github.com/ccfos/nightingale/v6/models"
"github.com/ccfos/nightingale/v6/pkg/ctx"
"github.com/ccfos/nightingale/v6/pkg/poster"
"github.com/toolkits/pkg/logger"
)
@@ -59,11 +60,17 @@ func sendWebhook(webhook *models.Webhook, event interface{}, stats *astats.Stats
if webhook != nil {
insecureSkipVerify = webhook.SkipVerify
}
transport := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecureSkipVerify},
}
if poster.UseProxy(conf.Url) {
transport.Proxy = http.ProxyFromEnvironment
}
client := http.Client{
Timeout: time.Duration(conf.Timeout) * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: insecureSkipVerify},
},
Timeout: time.Duration(conf.Timeout) * time.Second,
Transport: transport,
}
stats.AlertNotifyTotal.WithLabelValues(channel).Inc()

View File

@@ -63,7 +63,7 @@ func GetByUrl[T any](url string, cfg conf.CenterApi) (T, error) {
Timeout: time.Duration(cfg.Timeout) * time.Millisecond,
}
if useProxy(url) {
if UseProxy(url) {
client.Transport = ProxyTransporter
}
@@ -147,7 +147,7 @@ func PostByUrl[T any](url string, cfg conf.CenterApi, v interface{}) (t T, err e
Timeout: time.Duration(cfg.Timeout) * time.Millisecond,
}
if useProxy(url) {
if UseProxy(url) {
client.Transport = ProxyTransporter
}
@@ -195,7 +195,7 @@ var ProxyTransporter = &http.Transport{
Proxy: http.ProxyFromEnvironment,
}
func useProxy(url string) bool {
func UseProxy(url string) bool {
// N9E_PROXY_URL=oapi.dingtalk.com,feishu.com
patterns := os.Getenv("N9E_PROXY_URL")
if patterns != "" {
@@ -228,7 +228,7 @@ func PostJSON(url string, timeout time.Duration, v interface{}, retries ...int)
Timeout: timeout,
}
if useProxy(url) {
if UseProxy(url) {
client.Transport = ProxyTransporter
}