From c1f6acebd16346407e9241c594eafb96b89f4902 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Mon, 26 Feb 2024 21:35:06 +0530 Subject: [PATCH] Add global alertmanager email smtp details --- api/v1/config_api.go | 5 +++++ config/config.go | 29 +++++++++++++++++++---------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/api/v1/config_api.go b/api/v1/config_api.go index d159e601..604f8aa6 100644 --- a/api/v1/config_api.go +++ b/api/v1/config_api.go @@ -299,6 +299,11 @@ func (api *API) testReceiver(w http.ResponseWriter, req *http.Request) { } } else if receiver.EmailConfigs != nil { emailConfig := receiver.EmailConfigs[0] + emailConfig.From = defaultGlobalConfig.SMTPFrom + emailConfig.Smarthost = defaultGlobalConfig.SMTPSmarthost + emailConfig.AuthUsername = defaultGlobalConfig.SMTPAuthUsername + emailConfig.AuthPassword = defaultGlobalConfig.SMTPAuthPassword + emailConfig.RequireTLS = &defaultGlobalConfig.SMTPRequireTLS notifier := email.New(emailConfig, tmpl, api.logger) ctx := getCtx(receiver.Name) dummyAlert := getDummyAlert() diff --git a/config/config.go b/config/config.go index 4b4a68b9..546a3417 100644 --- a/config/config.go +++ b/config/config.go @@ -752,17 +752,26 @@ func DefaultGlobalConfig() GlobalConfig { defaultSMTPFrom := constants.GetOrDefaultEnv("ALERTMANAGER_SMTP_FROM", "alertmanager@signoz.io") + defaultSMTPUsername := constants.GetOrDefaultEnv("ALERTMANAGER_SMTP_AUTH_USERNAME", "") + defaultSMTPPassword := constants.GetOrDefaultEnv("ALERTMANAGER_SMTP_AUTH_PASSWORD", "") + defaultSMTPAuthSecret := constants.GetOrDefaultEnv("ALERTMANAGER_SMTP_AUTH_SECRET", "") + defaultSMTPAuthIdentity := constants.GetOrDefaultEnv("ALERTMANAGER_SMTP_AUTH_IDENTITY", "") + return GlobalConfig{ - ResolveTimeout: resolveTimeout, - HTTPConfig: &defaultHTTPConfig, - SMTPSmarthost: defaultSMTPSmarthost, - SMTPFrom: defaultSMTPFrom, - SMTPHello: "localhost", - SMTPRequireTLS: true, - PagerdutyURL: mustParseURL("https://events.pagerduty.com/v2/enqueue"), - OpsGenieAPIURL: mustParseURL("https://api.opsgenie.com/"), - WeChatAPIURL: mustParseURL("https://qyapi.weixin.qq.com/cgi-bin/"), - VictorOpsAPIURL: mustParseURL("https://alert.victorops.com/integrations/generic/20131114/alert/"), + ResolveTimeout: resolveTimeout, + HTTPConfig: &defaultHTTPConfig, + SMTPSmarthost: defaultSMTPSmarthost, + SMTPFrom: defaultSMTPFrom, + SMTPAuthUsername: defaultSMTPUsername, + SMTPAuthPassword: Secret(defaultSMTPPassword), + SMTPAuthSecret: Secret(defaultSMTPAuthSecret), + SMTPAuthIdentity: defaultSMTPAuthIdentity, + SMTPHello: "localhost", + SMTPRequireTLS: true, + PagerdutyURL: mustParseURL("https://events.pagerduty.com/v2/enqueue"), + OpsGenieAPIURL: mustParseURL("https://api.opsgenie.com/"), + WeChatAPIURL: mustParseURL("https://qyapi.weixin.qq.com/cgi-bin/"), + VictorOpsAPIURL: mustParseURL("https://alert.victorops.com/integrations/generic/20131114/alert/"), } }