Files
pulse/internal/api/external_probe_notifications.go
T
2026-07-29 20:09:23 +01:00

35 lines
1.2 KiB
Go

package api
import (
"strings"
"github.com/rcourtman/pulse-go-rewrite/internal/alerts"
"github.com/rcourtman/pulse-go-rewrite/internal/relay"
)
// externalProbePushNotification keeps mobile payloads deliberately generic:
// alert metadata selects the event, while infrastructure names and addresses
// remain inside the self-hosted Pulse instance.
func externalProbePushNotification(
alert *alerts.Alert,
hasProbeAssignments func(string) bool,
) (relay.PushNotificationPayload, bool) {
if alert == nil || alert.Metadata == nil {
return relay.PushNotificationPayload{}, false
}
code, _ := alert.Metadata["incidentCode"].(string)
source, _ := alert.Metadata["incidentSource"].(string)
probeSpecific := strings.TrimSpace(code) == alerts.ExternalProbeUnavailableIncidentCode &&
strings.TrimSpace(source) == alerts.ExternalProbeIncidentSource
hostOffline := false
if alert.Type == alerts.HostOfflineAlertType && hasProbeAssignments != nil {
hostID, _ := alert.Metadata["hostId"].(string)
hostOffline = hasProbeAssignments(strings.TrimSpace(hostID))
}
if !probeSpecific && !hostOffline {
return relay.PushNotificationPayload{}, false
}
return relay.NewExternalProbeUnavailableNotification(alert.ID), true
}