Skip to content

armgit / Pulse

Public Imported from GitHub
0

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.

Normalize ZFS device alert resource names

rcourtman933e74e6f4ba
diff --git a/docs/release-control/v6/internal/subsystems/alerts.md b/docs/release-control/v6/internal/subsystems/alerts.md
index b15e3ee7db..5dfe72d89f 100644
--- a/docs/release-control/v6/internal/subsystems/alerts.md
+++ b/docs/release-control/v6/internal/subsystems/alerts.md
@@ -118,6 +118,11 @@ or QNAP md arrays are vendor-managed system volumes rather than customer-facing
storage, and alerts runtime must use those shared rules both to suppress new
RAID incidents and to clear stale suppressed alert IDs even after monitoring
has already normalized those arrays out of canonical host state.
+Storage alert runtime also owns operator-facing resource labels for storage
+incidents. ZFS device alert labels must preserve raw device names such as
+`/dev/sda4`, but must not join pool and device labels with a raw slash because
+device paths can already begin with `/`; browser alert surfaces consume the
+runtime `resourceName` as authored rather than patching storage labels locally.
Alert history persistence is also part of that canonical boundary. The history
manager may choose the owned runtime data directory, but it must normalize that
diff --git a/internal/alerts/alerts.go b/internal/alerts/alerts.go
index a4af61ac7e..098ca0e360 100644
--- a/internal/alerts/alerts.go
+++ b/internal/alerts/alerts.go
@@ -6887,7 +6887,7 @@ func (m *Manager) checkZFSPoolHealth(storage models.Storage) {
AlertType: "zfs-device",
SpecResourceID: storage.ID + "/zfs-pool:" + sanitizeHostComponent(pool.Name) + "/device:" + sanitizeHostComponent(device.Name),
ResourceID: storage.ID,
- ResourceName: fmt.Sprintf("%s (%s/%s)", storage.Name, pool.Name, device.Name),
+ ResourceName: formatZFSDeviceResourceName(storage.Name, pool.Name, device.Name),
ResourceType: unifiedresources.ResourceTypeStorage,
Node: storage.Node,
Instance: storage.Instance,
@@ -6908,6 +6908,25 @@ func (m *Manager) checkZFSPoolHealth(storage models.Storage) {
}
}
+func formatZFSDeviceResourceName(storageName, poolName, deviceName string) string {
+ storageName = strings.TrimSpace(storageName)
+ if storageName == "" {
+ storageName = "storage"
+ }
+
+ parts := make([]string, 0, 2)
+ if poolName = strings.TrimSpace(poolName); poolName != "" {
+ parts = append(parts, poolName)
+ }
+ if deviceName = strings.TrimSpace(deviceName); deviceName != "" {
+ parts = append(parts, deviceName)
+ }
+ if len(parts) == 0 {
+ return storageName
+ }
+ return fmt.Sprintf("%s (%s)", storageName, strings.Join(parts, ", "))
+}
+
// clearAlert removes an alert if it exists
func (m *Manager) clearAlert(alertID string) {
m.mu.Lock()
diff --git a/internal/alerts/alerts_test.go b/internal/alerts/alerts_test.go
index e01d9501bf..094c6d54b0 100644
--- a/internal/alerts/alerts_test.go
+++ b/internal/alerts/alerts_test.go
@@ -11350,6 +11350,40 @@ func TestCheckZFSPoolHealth(t *testing.T) {
}
})
+ t.Run("device path resource name separates pool and device", func(t *testing.T) {
+ m := newTestManager(t)
+
+ storage := models.Storage{
+ ID: "local-zfs",
+ Name: "local-zfs",
+ Node: "pve-node1",
+ ZFSPool: &models.ZFSPool{
+ Name: "data",
+ State: "ONLINE",
+ Devices: []models.ZFSDevice{
+ {Name: "/dev/sda4", State: "ONLINE", ReadErrors: 3, WriteErrors: 0, ChecksumErrors: 5},
+ },
+ },
+ }
+
+ m.checkZFSPoolHealth(storage)
+
+ devicePathAlertID := buildCanonicalStateID(
+ "local-zfs/zfs-pool:data/device:dev-sda4",
+ "local-zfs/zfs-pool:data/device:dev-sda4-health",
+ )
+ m.mu.RLock()
+ alert := testRequireActiveAlert(t, m, devicePathAlertID)
+ m.mu.RUnlock()
+
+ if alert.ResourceName != "local-zfs (data, /dev/sda4)" {
+ t.Fatalf("expected resource name to preserve device path without path-joining labels, got %q", alert.ResourceName)
+ }
+ if strings.Contains(alert.ResourceName, "//") {
+ t.Fatalf("expected resource name not to contain doubled slash, got %q", alert.ResourceName)
+ }
+ })
+
t.Run("device in FAULTED state creates critical alert", func(t *testing.T) {
// t.Parallel()
m := newTestManager(t)