fix(notify): include server name in monitor alert email

This commit is contained in:
2026-09-17 08:16:10 +00:00
parent 64dbad1d20
commit 590c369d36
2 changed files with 28 additions and 1 deletions
+11 -1
View File
@@ -27,7 +27,7 @@ func dispatchSMTP(ch models.NotificationChannel, ev Event) error {
}
return sender.SendMonitorAlert(to, mail.MonitorEvent{
MonitorName: ev.MonitorName,
MonitorName: smtpAlertName(ev),
Type: ev.Type,
OldStatus: ev.OldStatus,
NewStatus: ev.NewStatus,
@@ -36,3 +36,13 @@ func dispatchSMTP(ch models.NotificationChannel, ev Event) error {
Down: ev.NewStatus == models.StatusDown,
})
}
// smtpAlertName is the name shown in the alert email. mail.MonitorEvent (in
// vantage-shared) has no ServerName field, so the server is folded into the
// name the same way title() folds it into the notification title.
func smtpAlertName(ev Event) string {
if ev.ServerName == "" {
return ev.MonitorName
}
return fmt.Sprintf("%s on %s", ev.MonitorName, ev.ServerName)
}
+17
View File
@@ -0,0 +1,17 @@
package notify
import "testing"
func TestSMTPAlertNameIncludesServerName(t *testing.T) {
ev := Event{MonitorName: "Disk full", ServerName: "web-01"}
if got, want := smtpAlertName(ev), "Disk full on web-01"; got != want {
t.Fatalf("smtpAlertName = %q, want %q", got, want)
}
}
func TestSMTPAlertNameWithoutServerNameUnchanged(t *testing.T) {
ev := Event{MonitorName: "Site"}
if got, want := smtpAlertName(ev), "Site"; got != want {
t.Fatalf("smtpAlertName = %q, want %q", got, want)
}
}