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.

fix(hostagent): clear stale Unraid sync action when resync position is zero

rcourtman28d2413c7178
diff --git a/internal/hostagent/unraid.go b/internal/hostagent/unraid.go
index 24dc7d1242..8fd5d42cc5 100644
--- a/internal/hostagent/unraid.go
+++ b/internal/hostagent/unraid.go
@@ -91,7 +91,7 @@ func parseUnraidStatusOutput(output string) (*agentshost.UnraidStorage, error) {
storage := &agentshost.UnraidStorage{
ArrayState: strings.ToUpper(strings.TrimSpace(fields["mdState"])),
ArrayStarted: strings.EqualFold(strings.TrimSpace(fields["mdState"]), "STARTED"),
- SyncAction: normalizeUnraidSyncAction(fields["mdResyncAction"]),
+ SyncAction: unraidSyncAction(fields),
SyncProgress: unraidSyncProgress(fields),
SyncErrors: parseUnraidInt64Field(fields, "mdResyncCorr"),
NumProtected: parseUnraidIntField(fields, "mdNumProtected"),
@@ -471,6 +471,20 @@ func normalizeUnraidSyncAction(action string) string {
}
}
+// unraidSyncAction returns the active sync action only when a resync is
+// actually running. Unraid's mdResyncAction field can retain its last value
+// after the sync is canceled (e.g., "check" stays set even after the parity
+// check is stopped). The mdResync/mdResyncPos field is the authoritative
+// indicator: it is 0 when no resync is running and non-zero (the current
+// position) when one is active.
+func unraidSyncAction(fields map[string]string) string {
+ pos := parseFirstInt64(fields["mdResyncPos"], fields["mdResync"])
+ if pos <= 0 {
+ return ""
+ }
+ return normalizeUnraidSyncAction(fields["mdResyncAction"])
+}
+
func unraidSyncProgress(fields map[string]string) float64 {
pos := parseFirstInt64(fields["mdResyncPos"], fields["mdResync"])
size := parseFirstInt64(fields["mdResyncSize"], fields["mdSize"])
diff --git a/internal/hostagent/unraid_test.go b/internal/hostagent/unraid_test.go
index db23a77878..659dedfb53 100644
--- a/internal/hostagent/unraid_test.go
+++ b/internal/hostagent/unraid_test.go
@@ -63,6 +63,64 @@ rdevStatus.2=DISK_DSBL
}
}
+func TestParseUnraidStatusOutputStaleSyncAction(t *testing.T) {
+ tests := []struct {
+ name string
+ output string
+ wantSyncAction string
+ }{
+ {
+ name: "sync active reports action",
+ output: `
+mdState=STARTED
+mdResyncAction=check
+mdResyncPos=500
+mdResyncSize=1000
+`,
+ wantSyncAction: "check",
+ },
+ {
+ name: "stale action cleared when position is zero",
+ output: `
+mdState=STARTED
+mdResyncAction=check
+mdResyncPos=0
+mdResyncSize=0
+`,
+ wantSyncAction: "",
+ },
+ {
+ name: "stale action cleared when position fields absent",
+ output: `
+mdState=STARTED
+mdResyncAction=check
+`,
+ wantSyncAction: "",
+ },
+ {
+ name: "idle action always empty",
+ output: `
+mdState=STARTED
+mdResyncAction=idle
+mdResyncPos=500
+`,
+ wantSyncAction: "",
+ },
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ storage, err := parseUnraidStatusOutput(tt.output)
+ if err != nil {
+ t.Fatalf("parseUnraidStatusOutput() error = %v", err)
+ }
+ if storage.SyncAction != tt.wantSyncAction {
+ t.Errorf("SyncAction = %q, want %q", storage.SyncAction, tt.wantSyncAction)
+ }
+ })
+ }
+}
+
func TestParseUnraidStatusOutputSkipsEmptyNoPresentSlots(t *testing.T) {
output := `
mdState=STARTED