fix(notify): include server name in monitor alert email
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user