Skip to content

Commit

Permalink
Add dummy test alert option for email (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv committed Feb 29, 2024
1 parent 1878bd6 commit eaf816b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
16 changes: 16 additions & 0 deletions api/v1/config_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/notify"
"github.com/prometheus/alertmanager/notify/email"
"github.com/prometheus/alertmanager/notify/msteams"
"github.com/prometheus/alertmanager/notify/opsgenie"
"github.com/prometheus/alertmanager/notify/pagerduty"
Expand Down Expand Up @@ -296,6 +297,21 @@ func (api *API) testReceiver(w http.ResponseWriter, req *http.Request) {
api.respondError(w, apiError{err: err, typ: errorInternal}, fmt.Sprintf("failed to send test message to channel (%s)", receiver.Name))
return
}
} 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()
_, err = notifier.Notify(ctx, &dummyAlert)
if err != nil {
api.respondError(w, apiError{err: err, typ: errorInternal}, fmt.Sprintf("failed to send test message to channel (%s)", receiver.Name))
return
}
} else {
api.respondError(w, apiError{err: fmt.Errorf("invalid receiver type"), typ: errorInternal}, fmt.Sprintf("failed to send test message to channel (%s)", receiver.Name))
return
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", "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/"),
}
}

Expand Down

0 comments on commit eaf816b

Please sign in to comment.