feat: Update notification type in UptimeService based on monitor status changes
This commit is contained in:
@@ -161,8 +161,16 @@ func (s *UptimeService) checkMonitor(monitor models.UptimeMonitor) {
|
||||
// Send Notification if status changed
|
||||
if oldStatus != "pending" && oldStatus != status {
|
||||
title := fmt.Sprintf("Monitor %s is %s", monitor.Name, status)
|
||||
|
||||
nType := models.NotificationTypeInfo
|
||||
if status == "down" {
|
||||
nType = models.NotificationTypeError
|
||||
} else if status == "up" {
|
||||
nType = models.NotificationTypeSuccess
|
||||
}
|
||||
|
||||
s.NotificationService.Create(
|
||||
models.NotificationTypeInfo,
|
||||
nType,
|
||||
title,
|
||||
fmt.Sprintf("Monitor %s changed status from %s to %s. Latency: %dms. Message: %s", monitor.Name, oldStatus, status, latency, msg),
|
||||
)
|
||||
|
||||
@@ -116,6 +116,7 @@ func TestUptimeService_CheckAll(t *testing.T) {
|
||||
assert.Equal(t, 1, len(notifications), "Should have 1 notification now")
|
||||
if len(notifications) > 0 {
|
||||
assert.Contains(t, notifications[0].Message, upHost.DomainNames, "Notification should mention the host")
|
||||
assert.Equal(t, models.NotificationTypeError, notifications[0].Type, "Notification type should be error for DOWN event")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user