Alerting: Fix email image embedding on Windows. (#56766)

The email notifier was incorrectly handling Windows filepaths. This is
fixed by using the `path/filepath` package.
This commit is contained in:
Joe Blubaugh 2022-10-13 10:24:00 +08:00 committed by GitHub
parent 254bb0c99e
commit c7c640d903
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,6 +6,7 @@ import (
"net/url"
"os"
"path"
"path/filepath"
"github.com/prometheus/alertmanager/template"
"github.com/prometheus/alertmanager/types"
@ -116,7 +117,7 @@ func (en *EmailNotifier) Notify(ctx context.Context, alerts ...*types.Alert) (bo
} else if len(image.Path) != 0 {
_, err := os.Stat(image.Path)
if err == nil {
data.Alerts[index].EmbeddedImage = path.Base(image.Path)
data.Alerts[index].EmbeddedImage = filepath.Base(image.Path)
embeddedFiles = append(embeddedFiles, image.Path)
} else {
en.log.Warn("failed to get image file for email attachment", "file", image.Path, "err", err)