diff --git a/pkg/health/health.go b/pkg/health/health.go index b296c63..b49ba9e 100644 --- a/pkg/health/health.go +++ b/pkg/health/health.go @@ -403,13 +403,14 @@ func GetHealthCheckFunc(gvk schema.GroupVersionKind) func(obj *unstructured.Unst return getScrapeConfigHealth // case "ScrapePlugin": } - // case "mission-control.flanksource.com": - // switch gvk.Kind { - // case "Notification": - // case "Playbook": - // case "NotificationSilence": - // case "Connection": - // } + case "mission-control.flanksource.com": + switch gvk.Kind { + case "Notification": + return getNotificationHealth + // case "Playbook": + // case "NotificationSilence": + // case "Connection": + } case "kustomize.toolkit.fluxcd.io", "helm.toolkit.fluxcd.io", "source.toolkit.fluxcd.io": return GetDefaultHealth case "cert-manager.io": diff --git a/pkg/health/health_flanksource.go b/pkg/health/health_flanksource.go index 3454568..b118618 100644 --- a/pkg/health/health_flanksource.go +++ b/pkg/health/health_flanksource.go @@ -108,3 +108,48 @@ func getScrapeConfigHealth(obj *unstructured.Unstructured) (*HealthStatus, error return status, nil } + +func getNotificationHealth(obj *unstructured.Unstructured) (*HealthStatus, error) { + failedCount, _, err := unstructured.NestedInt64(obj.Object, "status", "failed") + if err != nil { + return nil, err + } + + pendingCount, _, err := unstructured.NestedInt64(obj.Object, "status", "pending") + if err != nil { + return nil, err + } + + errorMessage, _, err := unstructured.NestedString(obj.Object, "status", "error") + if err != nil { + return nil, err + } + + sentCount, _, err := unstructured.NestedInt64(obj.Object, "status", "sent") + if err != nil { + return nil, err + } + + var h Health = HealthUnknown + if sentCount > 0 { + h = HealthHealthy + if failedCount > 0 || pendingCount > 0 { + h = HealthWarning + } + } else { + if pendingCount > 0 { + h = HealthWarning + } + if failedCount > 0 { + h = HealthUnhealthy + } + } + + status := &HealthStatus{Health: h} + + if errorMessage != "" { + status.Message = errorMessage + } + + return status, nil +}