From 140c3d683fe228b5612fd0a726b90a45af28518e Mon Sep 17 00:00:00 2001 From: Davide Bizzarri Date: Tue, 16 May 2023 13:27:22 +0200 Subject: [PATCH] notify/webhook: trim space from url_file content Signed-off-by: Davide Bizzarri --- notify/webhook/webhook.go | 3 ++- notify/webhook/webhook_test.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/notify/webhook/webhook.go b/notify/webhook/webhook.go index a1f8c37dbf..41241569ef 100644 --- a/notify/webhook/webhook.go +++ b/notify/webhook/webhook.go @@ -21,6 +21,7 @@ import ( "io" "net/http" "os" + "strings" "github.com/go-kit/log" "github.com/go-kit/log/level" @@ -110,7 +111,7 @@ func (n *Notifier) Notify(ctx context.Context, alerts ...*types.Alert) (bool, er if err != nil { return false, fmt.Errorf("read url_file: %w", err) } - url = string(content) + url = strings.TrimSpace(string(content)) } resp, err := notify.PostJSON(ctx, n.client, url, &buf) diff --git a/notify/webhook/webhook_test.go b/notify/webhook/webhook_test.go index 682b511485..3e2c1e137c 100644 --- a/notify/webhook/webhook_test.go +++ b/notify/webhook/webhook_test.go @@ -124,7 +124,7 @@ func TestWebhookReadingURLFromFile(t *testing.T) { f, err := os.CreateTemp("", "webhook_url") require.NoError(t, err, "creating temp file failed") - _, err = f.WriteString(u.String()) + _, err = f.WriteString(u.String() + "\n") require.NoError(t, err, "writing to temp file failed") notifier, err := New(