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

The email notifier was incorrectly handling Windows filepaths. This is
fixed by using the `path/filepath` package.

(cherry picked from commit c7c640d903)

Co-authored-by: Joe Blubaugh <joe.blubaugh@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2022-10-13 11:21:20 +08:00
committed by GitHub
co-authored by Joe Blubaugh
parent da5186b07a
commit 17e197634e
@@ -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)