feat: Update notification type in UptimeService based on monitor status changes

This commit is contained in:
Wikid82
2025-11-24 04:10:02 +00:00
parent 9f54438955
commit 7da561de56
2 changed files with 10 additions and 1 deletions
+9 -1
View File
@@ -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")
}
}