Merge pull request #3363 from b1zzu/webhook-url-file-trim-space

Trim space from webhook url_file content
This commit is contained in:
Simon Pasquier 2023-05-16 14:58:26 +02:00 committed by GitHub
commit 5adc7369c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 2 deletions

View File

@ -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)

View File

@ -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(