diff --git a/backend/internal/services/uptime_service.go b/backend/internal/services/uptime_service.go index fe2671f6..f23758fc 100644 --- a/backend/internal/services/uptime_service.go +++ b/backend/internal/services/uptime_service.go @@ -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), ) diff --git a/backend/internal/services/uptime_service_test.go b/backend/internal/services/uptime_service_test.go index c47d8142..57becd9d 100644 --- a/backend/internal/services/uptime_service_test.go +++ b/backend/internal/services/uptime_service_test.go @@ -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") } }