Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
refactor: split Proxmox disk health alerts
rcourtman8457be3cb69f
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.mdindex c7bbc699ff..ecef95ba7e 100644--- a/docs/release-control/v6/internal/subsystems/alerts.md+++ b/docs/release-control/v6/internal/subsystems/alerts.md@@ -63,6 +63,7 @@ operator-facing alert routing behavior for live runtime alerts.41. `internal/alerts/node.go`42. `internal/alerts/host.go`43. `internal/alerts/backup_snapshot.go`+44. `internal/alerts/disk_health.go`## Shared Boundaries@@ -267,6 +268,11 @@ evaluation, backup rollup age evaluation, backup inventory readiness, PVEtemplate subject matching, namespace disambiguation, and snapshot/backup activealert cleanup; future backup or snapshot alert behavior should extend thatowner rather than expanding the central Manager file.+Proxmox disk health alert evaluation now lives in+`internal/alerts/disk_health.go`. That file owns Proxmox disk canonical+identity, disk health assessment alerts, known-firmware health suppression, and+SSD wearout alerts; future Proxmox disk-health behavior should extend that+checker owner rather than expanding the central Manager file.Commercial alert handoffs now follow the same shared navigation boundary.`frontend-modern/src/components/Alerts/InvestigateAlertButton.tsx` may resolvethe canonical `ai_alerts` destination from the shared license/commercialdiff --git a/internal/alerts/alerts.go b/internal/alerts/alerts.goindex 83bcf4ff2a..fee3158eac 100644--- a/internal/alerts/alerts.go+++ b/internal/alerts/alerts.go@@ -18,7 +18,6 @@ import ("github.com/rcourtman/pulse-go-rewrite/internal/storagehealth""github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources""github.com/rcourtman/pulse-go-rewrite/internal/utils"- "github.com/rcourtman/pulse-go-rewrite/pkg/proxmox""github.com/rs/zerolog/log")@@ -2978,20 +2977,6 @@ func (m *Manager) applyThresholdOverride(base ThresholdConfig, override Thresholreturn result}-func proxmoxDiskCanonicalResourceID(instance, node, devPath string) string {- return fmt.Sprintf("%s:%s:disk:%s", strings.TrimSpace(instance), strings.TrimSpace(node), sanitizeAlertKey(devPath))-}--func proxmoxDiskAlertMetadata(disk proxmox.Disk) map[string]interface{} {- return map[string]interface{}{- "disk_path": disk.DevPath,- "disk_model": disk.Model,- "disk_serial": disk.Serial,- "disk_type": disk.Type,- "disk_size": disk.Size,- }-}-// ensureHysteresisThreshold ensures a threshold has hysteresis configuredfunc ensureHysteresisThreshold(threshold *HysteresisThreshold) *HysteresisThreshold {if threshold == nil {@@ -3882,150 +3867,6 @@ func (m *Manager) cleanupStaleMaps() {}}-// CheckDiskHealth checks disk health and creates alerts if needed-func (m *Manager) CheckDiskHealth(instance, node string, disk proxmox.Disk) {- // Create unique alert ID for this disk- alertID := fmt.Sprintf("disk-health-%s-%s-%s", instance, node, disk.DevPath)- wearoutAlertID := fmt.Sprintf("disk-wearout-%s-%s-%s", instance, node, disk.DevPath)- resourceID := fmt.Sprintf("%s-%s", node, disk.DevPath)- resourceName := fmt.Sprintf("%s (%s)", disk.Model, disk.DevPath)- canonicalResourceID := proxmoxDiskCanonicalResourceID(instance, node, disk.DevPath)- resourceType := unifiedresources.ResourceType("proxmox-disk")- canonicalHealthAlertID := buildCanonicalStateID(canonicalResourceID, canonicalResourceID+"-health")- canonicalWearoutAlertID := buildCanonicalStateID(canonicalResourceID, canonicalResourceID+"-wearout")-- clearDiskAlert := func(ids ...string) {- seen := make(map[string]struct{}, len(ids))- for _, id := range ids {- if id == "" {- continue- }- if _, exists := seen[id]; exists {- continue- }- seen[id] = struct{}{}- m.clearAlert(id)- }- }-- // Check if disk health is not PASSED- normalizedHealth := strings.ToUpper(strings.TrimSpace(disk.Health))- healthCheckNeeded := normalizedHealth != "" && normalizedHealth != "UNKNOWN" && normalizedHealth != "PASSED" && normalizedHealth != "OK"-- // Skip health alerts for drives with known firmware bugs that cause false reports- // These drives may report FAILED status due to firmware issues even when healthy- // We still monitor wearout below, which is more reliable for these drives- if healthCheckNeeded && storagehealth.HasKnownFirmwareBug(disk.Model) {- log.Debug().- Str("node", node).- Str("disk", disk.DevPath).- Str("model", disk.Model).- Str("health", disk.Health).- Msg("Skipping health alert for drive with known firmware bug - health status unreliable")-- // Clear any existing health alert since we now recognize this is a false positive.- // Older installs may still have the legacy alert key persisted on disk.- clearDiskAlert(alertID, canonicalHealthAlertID)- healthCheckNeeded = false // Skip to wearout check- }-- if healthCheckNeeded {- spec, err := buildCanonicalHealthAssessmentSpec(canonicalResourceID+"-health", canonicalResourceID, resourceName, resourceType, "proxmox-disk-health", nil, false)- if err != nil {- log.Warn().- Err(err).- Str("node", node).- Str("disk", disk.DevPath).- Msg("Skipping invalid canonical proxmox disk health spec")- } else {- metadata := proxmoxDiskAlertMetadata(disk)- metadata["disk_health"] = disk.Health-- _, _ = m.evaluateCanonicalStatefulAlert(canonicalStatefulAlertParams{- Spec: spec,- Evidence: alertspecs.AlertEvidence{- ObservedAt: time.Now(),- HealthAssessment: &alertspecs.HealthAssessmentEvidence{- Signal: "proxmox-disk-health",- Severity: alertspecs.AlertSeverityCritical,- Codes: []string{normalizedHealth},- },- },- AlertID: alertID,- AlertType: "disk-health",- ResourceID: resourceID,- ResourceName: resourceName,- Node: node,- Instance: instance,- Message: fmt.Sprintf("Disk health check failed: %s", disk.Health),- Metadata: metadata,- AddToRecent: true,- AddToHistory: true,- })-- log.Error().- Str("node", node).- Str("disk", disk.DevPath).- Str("model", disk.Model).- Str("health", disk.Health).- Msg("Disk health alert created")- }- } else {- // Disk is healthy, clear alert if it exists- clearDiskAlert(alertID, canonicalHealthAlertID)- }-- // Check for low wearout (SSD life remaining)- if disk.Wearout > 0 && disk.Wearout < 10 {- message := fmt.Sprintf("SSD has less than 10%% life remaining (%d%% wearout)", disk.Wearout)- spec, err := buildCanonicalSeverityThresholdSpecWithDirection(canonicalResourceID+"-wearout", canonicalResourceID, resourceName, resourceType, "wearout-remaining", alertspecs.ThresholdDirectionBelow, 10, 0, false)- if err != nil {- log.Warn().- Err(err).- Str("node", node).- Str("disk", disk.DevPath).- Msg("Skipping invalid canonical proxmox disk wearout spec")- } else {- metadata := proxmoxDiskAlertMetadata(disk)- metadata["disk_wearout"] = disk.Wearout-- _, _ = m.evaluateCanonicalStatefulAlert(canonicalStatefulAlertParams{- Spec: spec,- Evidence: alertspecs.AlertEvidence{- ObservedAt: time.Now(),- SeverityThreshold: &alertspecs.SeverityThresholdEvidence{- Metric: "wearout-remaining",- Direction: alertspecs.ThresholdDirectionBelow,- Observed: float64(disk.Wearout),- },- },- AlertID: wearoutAlertID,- AlertType: "disk-wearout",- ResourceID: resourceID,- ResourceName: resourceName,- Node: node,- Instance: instance,- Message: message,- Value: float64(disk.Wearout),- Threshold: 10.0,- Metadata: metadata,- AddToRecent: true,- AddToHistory: true,- })-- log.Warn().- Str("node", node).- Str("disk", disk.DevPath).- Str("model", disk.Model).- Int("wearout", disk.Wearout).- Msg("Disk wearout alert created")- }- } else if disk.Wearout >= 10 {- // Wearout is acceptable, clear alert if it exists- clearDiskAlert(wearoutAlertID, canonicalWearoutAlertID)- }-}-// clearAlertNoLock clears an alert without locking (must be called with lock held)func (m *Manager) clearAlertNoLock(alertID string) {alert, exists := m.getActiveAlertNoLock(alertID)diff --git a/internal/alerts/alerts_test.go b/internal/alerts/alerts_test.goindex e916c468d3..9dc3abd8f3 100644--- a/internal/alerts/alerts_test.go+++ b/internal/alerts/alerts_test.go@@ -332,6 +332,13 @@ func TestBuildBackupPVETemplateSubjectKeyTrimsParts(t *testing.T) {}}+func TestProxmoxDiskCanonicalResourceIDTrimsIdentity(t *testing.T) {+ got := proxmoxDiskCanonicalResourceID(" inst ", " node ", "/dev/sda")+ if got != "inst:node:disk:dev-sda" {+ t.Fatalf("proxmoxDiskCanonicalResourceID() = %q, want %q", got, "inst:node:disk:dev-sda")+ }+}+func TestQuietHoursCategoryForResourceIncidentUsesIncidentCategoryMetadata(t *testing.T) {availability := &Alert{Type: "resource-incident",diff --git a/internal/alerts/disk_health.go b/internal/alerts/disk_health.gonew file mode 100644index 0000000000..e6e147f216--- /dev/null+++ b/internal/alerts/disk_health.go@@ -0,0 +1,171 @@+package alerts++import (+ "fmt"+ "strings"+ "time"++ alertspecs "github.com/rcourtman/pulse-go-rewrite/internal/alerts/specs"+ "github.com/rcourtman/pulse-go-rewrite/internal/storagehealth"+ "github.com/rcourtman/pulse-go-rewrite/internal/unifiedresources"+ "github.com/rcourtman/pulse-go-rewrite/pkg/proxmox"+ "github.com/rs/zerolog/log"+)++func proxmoxDiskCanonicalResourceID(instance, node, devPath string) string {+ return fmt.Sprintf("%s:%s:disk:%s", strings.TrimSpace(instance), strings.TrimSpace(node), sanitizeAlertKey(devPath))+}++func proxmoxDiskAlertMetadata(disk proxmox.Disk) map[string]interface{} {+ return map[string]interface{}{+ "disk_path": disk.DevPath,+ "disk_model": disk.Model,+ "disk_serial": disk.Serial,+ "disk_type": disk.Type,+ "disk_size": disk.Size,+ }+}++// CheckDiskHealth checks disk health and creates alerts if needed+func (m *Manager) CheckDiskHealth(instance, node string, disk proxmox.Disk) {+ // Create unique alert ID for this disk+ alertID := fmt.Sprintf("disk-health-%s-%s-%s", instance, node, disk.DevPath)+ wearoutAlertID := fmt.Sprintf("disk-wearout-%s-%s-%s", instance, node, disk.DevPath)+ resourceID := fmt.Sprintf("%s-%s", node, disk.DevPath)+ resourceName := fmt.Sprintf("%s (%s)", disk.Model, disk.DevPath)+ canonicalResourceID := proxmoxDiskCanonicalResourceID(instance, node, disk.DevPath)+ resourceType := unifiedresources.ResourceType("proxmox-disk")+ canonicalHealthAlertID := buildCanonicalStateID(canonicalResourceID, canonicalResourceID+"-health")+ canonicalWearoutAlertID := buildCanonicalStateID(canonicalResourceID, canonicalResourceID+"-wearout")++ clearDiskAlert := func(ids ...string) {+ seen := make(map[string]struct{}, len(ids))+ for _, id := range ids {+ if id == "" {+ continue+ }+ if _, exists := seen[id]; exists {+ continue+ }+ seen[id] = struct{}{}+ m.clearAlert(id)+ }+ }++ // Check if disk health is not PASSED+ normalizedHealth := strings.ToUpper(strings.TrimSpace(disk.Health))+ healthCheckNeeded := normalizedHealth != "" && normalizedHealth != "UNKNOWN" && normalizedHealth != "PASSED" && normalizedHealth != "OK"++ // Skip health alerts for drives with known firmware bugs that cause false reports+ // These drives may report FAILED status due to firmware issues even when healthy+ // We still monitor wearout below, which is more reliable for these drives+ if healthCheckNeeded && storagehealth.HasKnownFirmwareBug(disk.Model) {+ log.Debug().+ Str("node", node).+ Str("disk", disk.DevPath).+ Str("model", disk.Model).+ Str("health", disk.Health).+ Msg("Skipping health alert for drive with known firmware bug - health status unreliable")++ // Clear any existing health alert since we now recognize this is a false positive.+ // Older installs may still have the legacy alert key persisted on disk.+ clearDiskAlert(alertID, canonicalHealthAlertID)+ healthCheckNeeded = false // Skip to wearout check+ }++ if healthCheckNeeded {+ spec, err := buildCanonicalHealthAssessmentSpec(canonicalResourceID+"-health", canonicalResourceID, resourceName, resourceType, "proxmox-disk-health", nil, false)+ if err != nil {+ log.Warn().+ Err(err).+ Str("node", node).+ Str("disk", disk.DevPath).+ Msg("Skipping invalid canonical proxmox disk health spec")+ } else {+ metadata := proxmoxDiskAlertMetadata(disk)+ metadata["disk_health"] = disk.Health++ _, _ = m.evaluateCanonicalStatefulAlert(canonicalStatefulAlertParams{+ Spec: spec,+ Evidence: alertspecs.AlertEvidence{+ ObservedAt: time.Now(),+ HealthAssessment: &alertspecs.HealthAssessmentEvidence{+ Signal: "proxmox-disk-health",+ Severity: alertspecs.AlertSeverityCritical,+ Codes: []string{normalizedHealth},+ },+ },+ AlertID: alertID,+ AlertType: "disk-health",+ ResourceID: resourceID,+ ResourceName: resourceName,+ Node: node,+ Instance: instance,+ Message: fmt.Sprintf("Disk health check failed: %s", disk.Health),+ Metadata: metadata,+ AddToRecent: true,+ AddToHistory: true,+ })++ log.Error().+ Str("node", node).+ Str("disk", disk.DevPath).+ Str("model", disk.Model).+ Str("health", disk.Health).+ Msg("Disk health alert created")+ }+ } else {+ // Disk is healthy, clear alert if it exists+ clearDiskAlert(alertID, canonicalHealthAlertID)+ }++ // Check for low wearout (SSD life remaining)+ if disk.Wearout > 0 && disk.Wearout < 10 {+ message := fmt.Sprintf("SSD has less than 10%% life remaining (%d%% wearout)", disk.Wearout)+ spec, err := buildCanonicalSeverityThresholdSpecWithDirection(canonicalResourceID+"-wearout", canonicalResourceID, resourceName, resourceType, "wearout-remaining", alertspecs.ThresholdDirectionBelow, 10, 0, false)+ if err != nil {+ log.Warn().+ Err(err).+ Str("node", node).+ Str("disk", disk.DevPath).+ Msg("Skipping invalid canonical proxmox disk wearout spec")+ } else {+ metadata := proxmoxDiskAlertMetadata(disk)+ metadata["disk_wearout"] = disk.Wearout++ _, _ = m.evaluateCanonicalStatefulAlert(canonicalStatefulAlertParams{+ Spec: spec,+ Evidence: alertspecs.AlertEvidence{+ ObservedAt: time.Now(),+ SeverityThreshold: &alertspecs.SeverityThresholdEvidence{+ Metric: "wearout-remaining",+ Direction: alertspecs.ThresholdDirectionBelow,+ Observed: float64(disk.Wearout),+ },+ },+ AlertID: wearoutAlertID,+ AlertType: "disk-wearout",+ ResourceID: resourceID,+ ResourceName: resourceName,+ Node: node,+ Instance: instance,+ Message: message,+ Value: float64(disk.Wearout),+ Threshold: 10.0,+ Metadata: metadata,+ AddToRecent: true,+ AddToHistory: true,+ })++ log.Warn().+ Str("node", node).+ Str("disk", disk.DevPath).+ Str("model", disk.Model).+ Int("wearout", disk.Wearout).+ Msg("Disk wearout alert created")+ }+ } else if disk.Wearout >= 10 {+ // Wearout is acceptable, clear alert if it exists+ clearDiskAlert(wearoutAlertID, canonicalWearoutAlertID)+ }+}