Skip to content

Commit

Permalink
Add global alertmanager email smtp details
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv committed Feb 26, 2024
1 parent 75a0b25 commit c1f6ace
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
5 changes: 5 additions & 0 deletions api/v1/config_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
29 changes: 19 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,17 +752,26 @@ func DefaultGlobalConfig() GlobalConfig {

defaultSMTPFrom := constants.GetOrDefaultEnv("ALERTMANAGER_SMTP_FROM", "[email protected]")

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/"),
}
}

Expand Down

0 comments on commit c1f6ace

Please sign in to comment.