Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/notifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ type WebhookConfig struct {
HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`

// URL to send POST request to.
URL *URL `yaml:"url" json:"url"`
URL *SecretURL `yaml:"url" json:"url"`

// MaxAlerts is the maximum number of alerts to be sent per webhook message.
// Alerts exceeding this threshold will be truncated. Setting this to 0
// allows an unlimited number of alerts.
Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,7 @@ The webhook receiver allows configuring a generic receiver.
[ send_resolved: <boolean> | default = true ]

# The endpoint to send HTTP POST requests to.
url: <string>
url: <secret>

# The HTTP client's configuration.
[ http_config: <http_config> | default = global.http_config ]
Expand Down
2 changes: 1 addition & 1 deletion notify/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (n *Notifier) Notify(ctx context.Context, alerts ...*types.Alert) (bool, er

resp, err := notify.PostJSON(ctx, n.client, n.conf.URL.String(), &buf)
if err != nil {
return true, err
return true, notify.RedactURL(err)
}
defer notify.Drain(resp)

Expand Down
20 changes: 19 additions & 1 deletion notify/webhook/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestWebhookRetry(t *testing.T) {
}
notifier, err := New(
&config.WebhookConfig{
URL: &config.URL{URL: u},
URL: &config.SecretURL{URL: u},
HTTPConfig: &commoncfg.HTTPClientConfig{},
},
test.CreateTmpl(t),
Expand Down Expand Up @@ -98,3 +98,21 @@ func TestWebhookTruncateAlerts(t *testing.T) {
require.Len(t, truncatedAlerts, 10)
require.EqualValues(t, numTruncated, 0)
}

func TestWebhookRedactedURL(t *testing.T) {
ctx, u, fn := test.GetContextWithCancelingURL()
defer fn()

secret := "secret"
notifier, err := New(
&config.WebhookConfig{
URL: &config.SecretURL{URL: u},
HTTPConfig: &commoncfg.HTTPClientConfig{},
},
test.CreateTmpl(t),
log.NewNopLogger(),
)
require.NoError(t, err)

test.AssertNotifyLeaksNoSecret(ctx, t, notifier, secret)
}