From 7da561de5677aa18ce66a736128dc712e968cc61 Mon Sep 17 00:00:00 2001 From: Wikid82 Date: Mon, 24 Nov 2025 04:10:02 +0000 Subject: [PATCH] feat: Update notification type in UptimeService based on monitor status changes --- backend/internal/services/uptime_service.go | 10 +++++++++- backend/internal/services/uptime_service_test.go | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) 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") } }