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.

Gate RAID rebuild alerts on mdstat operation

rcourtmanaf7d727d459b
diff --git a/internal/ai/tools/data_types.go b/internal/ai/tools/data_types.go
index a8b515394f..5c98899402 100644
--- a/internal/ai/tools/data_types.go
+++ b/internal/ai/tools/data_types.go
@@ -2087,6 +2087,7 @@ type HostRAIDArraySummary struct {
UUID string `json:"uuid,omitempty"`
RebuildPercent float64 `json:"rebuild_percent,omitempty"`
RebuildSpeed string `json:"rebuild_speed,omitempty"`
+ Operation string `json:"operation,omitempty"`
Devices []HostRAIDDeviceSummary `json:"devices"`
}
diff --git a/internal/ai/tools/tools_storage.go b/internal/ai/tools/tools_storage.go
index ba33d13514..ddca85077d 100644
--- a/internal/ai/tools/tools_storage.go
+++ b/internal/ai/tools/tools_storage.go
@@ -1338,6 +1338,7 @@ func (e *PulseToolExecutor) executeGetHostRAIDStatus(_ context.Context, args map
UUID: raid.UUID,
RebuildPercent: raid.RebuildPercent,
RebuildSpeed: raid.RebuildSpeed,
+ Operation: raid.Operation,
Devices: devices,
})
}
diff --git a/internal/alerts/alerts.go b/internal/alerts/alerts.go
index 098ca0e360..23f379c14a 100644
--- a/internal/alerts/alerts.go
+++ b/internal/alerts/alerts.go
@@ -3665,6 +3665,9 @@ func (m *Manager) CheckHost(host models.Host) {
if array.RebuildPercent > 0 {
raidMetadata["raidRebuildPercent"] = array.RebuildPercent
}
+ if array.Operation != "" {
+ raidMetadata["raidOperation"] = array.Operation
+ }
alertID := fmt.Sprintf("host-%s-raid-%s", host.ID, sanitizeRAIDDevice(array.Device))
assessment := storagehealth.AssessHostRAIDArray(array)
diff --git a/internal/alerts/alerts_test.go b/internal/alerts/alerts_test.go
index 094c6d54b0..2ed3594c91 100644
--- a/internal/alerts/alerts_test.go
+++ b/internal/alerts/alerts_test.go
@@ -14833,8 +14833,7 @@ func TestCheckHostComprehensive(t *testing.T) {
}
})
- t.Run("RAID resync triggers rebuilding alert", func(t *testing.T) {
- // t.Parallel()
+ t.Run("RAID recovery operation triggers rebuilding alert", func(t *testing.T) {
m := newTestManager(t)
host := models.Host{
@@ -14842,12 +14841,14 @@ func TestCheckHostComprehensive(t *testing.T) {
Hostname: "testhost",
RAID: []models.HostRAIDArray{
{
- Device: "/dev/md2", // Note: md0/md1 are skipped for Synology compatibility
- Level: "raid1",
- State: "resync",
- TotalDevices: 2,
- ActiveDevices: 2,
- FailedDevices: 0,
+ Device: "/dev/md2",
+ Level: "raid1",
+ State: "active, recovering",
+ Operation: "recovery",
+ TotalDevices: 2,
+ ActiveDevices: 2,
+ FailedDevices: 0,
+ RebuildPercent: 12.6,
},
},
}
@@ -14860,10 +14861,74 @@ func TestCheckHostComprehensive(t *testing.T) {
m.mu.RUnlock()
if alert == nil {
- t.Fatal("expected RAID rebuilding alert for resync")
+ t.Fatal("expected RAID rebuilding alert for recovery")
}
if alert.Level != AlertLevelWarning {
- t.Errorf("expected warning level for resync, got %s", alert.Level)
+ t.Errorf("expected warning level for recovery, got %s", alert.Level)
+ }
+ })
+
+ t.Run("RAID check operation does not trigger rebuilding alert", func(t *testing.T) {
+ m := newTestManager(t)
+
+ host := models.Host{
+ ID: "host1",
+ Hostname: "testhost",
+ RAID: []models.HostRAIDArray{
+ {
+ Device: "/dev/md2",
+ Level: "raid5",
+ State: "active",
+ Operation: "check",
+ TotalDevices: 3,
+ ActiveDevices: 3,
+ FailedDevices: 0,
+ RebuildPercent: 12.6,
+ },
+ },
+ }
+
+ m.CheckHost(host)
+
+ m.mu.RLock()
+ alertID := buildCanonicalStateID("agent:host1/raid:md2", "agent:host1/raid:md2-health")
+ _, exists := testLookupActiveAlert(t, m, alertID)
+ m.mu.RUnlock()
+
+ if exists {
+ t.Fatal("expected no RAID rebuilding alert for scrub check operation")
+ }
+ })
+
+ t.Run("RAID resync operation does not trigger rebuilding alert", func(t *testing.T) {
+ m := newTestManager(t)
+
+ host := models.Host{
+ ID: "host1",
+ Hostname: "testhost",
+ RAID: []models.HostRAIDArray{
+ {
+ Device: "/dev/md2",
+ Level: "raid1",
+ State: "active, resyncing",
+ Operation: "resync",
+ TotalDevices: 2,
+ ActiveDevices: 2,
+ FailedDevices: 0,
+ RebuildPercent: 12.6,
+ },
+ },
+ }
+
+ m.CheckHost(host)
+
+ m.mu.RLock()
+ alertID := buildCanonicalStateID("agent:host1/raid:md2", "agent:host1/raid:md2-health")
+ _, exists := testLookupActiveAlert(t, m, alertID)
+ m.mu.RUnlock()
+
+ if exists {
+ t.Fatal("expected no RAID rebuilding alert for maintenance resync operation")
}
})
@@ -14923,6 +14988,7 @@ func TestCheckHostComprehensive(t *testing.T) {
Device: "/dev/md2",
Level: "raid1",
State: "recovering",
+ Operation: "recovery",
TotalDevices: 2,
ActiveDevices: 2,
FailedDevices: 0,
@@ -14947,6 +15013,9 @@ func TestCheckHostComprehensive(t *testing.T) {
if got := alert.Metadata["canonicalSpecID"]; got != "agent:host1/raid:md2-health" {
t.Fatalf("canonicalSpecID = %v, want agent:host1/raid:md2-health", got)
}
+ if got := alert.Metadata["raidOperation"]; got != "recovery" {
+ t.Fatalf("raidOperation = %v, want recovery", got)
+ }
})
t.Run("applies override thresholds", func(t *testing.T) {
diff --git a/internal/hostagent/mdadm.go b/internal/hostagent/mdadm.go
index 644028323c..53f63f5729 100644
--- a/internal/hostagent/mdadm.go
+++ b/internal/hostagent/mdadm.go
@@ -19,14 +19,17 @@ import (
// Pre-compiled regexes for performance (avoid recompilation on each call)
var (
- mdDeviceRe = regexp.MustCompile(`^(md\d+)\s*:`)
- mdArrayPathRe = regexp.MustCompile(`^/dev/md\d+$`)
- slotRe = regexp.MustCompile(`^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(.+?)\s+(/dev/.+)$`)
- speedRe = regexp.MustCompile(`speed=(\S+)`)
- mdadmLookPath = exec.LookPath
- mdadmStat = os.Stat
- openFileForRead = func(name string) (io.ReadCloser, error) { return os.Open(name) }
- readFile = func(name string) ([]byte, error) {
+ mdDeviceRe = regexp.MustCompile(`^(md\d+)\s*:`)
+ mdArrayPathRe = regexp.MustCompile(`^/dev/md\d+$`)
+ slotRe = regexp.MustCompile(`^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(.+?)\s+(/dev/.+)$`)
+ speedRe = regexp.MustCompile(`speed=(\S+)`)
+ // /proc/mdstat progress line action.
+ // Example: "[==>..................] check = 12.6% (...) finish=... speed=..."
+ mdstatOperationRe = regexp.MustCompile(`(?i)\b(recovery|resync|check|reshape)\b\s*=`)
+ mdadmLookPath = exec.LookPath
+ mdadmStat = os.Stat
+ openFileForRead = func(name string) (io.ReadCloser, error) { return os.Open(name) }
+ readFile = func(name string) ([]byte, error) {
file, err := openFileForRead(name)
if err != nil {
return nil, err
@@ -267,12 +270,15 @@ func parseMdadmDetail(device, output string) (agentshost.RAIDArray, error) {
}
}
- // Check for rebuild/resync info in /proc/mdstat for speed information
- if array.RebuildPercent > 0 {
- speed := getRebuildSpeed(device)
- if speed != "" {
- array.RebuildSpeed = speed
- }
+ // /proc/mdstat is the authoritative source for distinguishing a true
+ // rebuild from routine maintenance such as a scrub on kernels that do not
+ // surface scrub state in mdadm --detail.
+ operation, speed := getMdstatProgress(device)
+ if operation != "" {
+ array.Operation = operation
+ }
+ if speed != "" {
+ array.RebuildSpeed = speed
}
return array, nil
@@ -297,46 +303,55 @@ func parseIntField(device, key, value string) (int, error) {
return n, nil
}
-// getRebuildSpeed extracts rebuild speed from /proc/mdstat
-func getRebuildSpeed(device string) string {
+// getMdstatProgress extracts the in-progress md operation and speed from
+// /proc/mdstat for the named array. It returns empty strings when the array is
+// idle, absent, or the progress line is unavailable.
+func getMdstatProgress(device string) (operation, speed string) {
// Remove /dev/ prefix for /proc/mdstat lookup
deviceName := strings.TrimPrefix(device, "/dev/")
output, err := readProcMDStat()
if err != nil {
- return ""
+ return "", ""
}
- // Look for lines containing rebuild/resync speed
- // Example: [==>..................] recovery = 12.6% (37043392/293039104) finish=127.5min speed=33440K/sec
+ // Example progress line shapes:
+ // [==>..................] recovery = 12.6% (...) finish=... speed=33440K/sec
+ // [=>...................] resync = 5.0% (...) finish=... speed=...
+ // [==>..................] check = 12.6% (...) finish=... speed=...
lines := strings.Split(string(output), "\n")
inSection := false
for _, line := range lines {
- // Check if this is our device
if strings.HasPrefix(strings.TrimSpace(line), deviceName) {
inSection = true
continue
}
- // If we're in the right section, look for speed info
- if inSection {
- if strings.Contains(line, "speed=") {
- // Extract speed value using pre-compiled regex
- matches := speedRe.FindStringSubmatch(line)
- if len(matches) > 1 {
- return matches[1]
- }
- }
+ if !inSection {
+ continue
+ }
- // Exit section when we hit a new device or blank line
- if strings.TrimSpace(line) == "" || (strings.HasPrefix(strings.TrimSpace(line), "md") && strings.Contains(line, ":")) {
- break
+ if strings.TrimSpace(line) == "" || (strings.HasPrefix(strings.TrimSpace(line), "md") && strings.Contains(line, ":")) {
+ break
+ }
+
+ if operation == "" {
+ if matches := mdstatOperationRe.FindStringSubmatch(line); len(matches) > 1 {
+ operation = strings.ToLower(matches[1])
}
}
+ if speed == "" {
+ if matches := speedRe.FindStringSubmatch(line); len(matches) > 1 {
+ speed = matches[1]
+ }
+ }
+ if operation != "" && speed != "" {
+ break
+ }
}
- return ""
+ return operation, speed
}
// readProcMDStat reads /proc/mdstat directly (without shelling out)
diff --git a/internal/hostagent/mdadm_test.go b/internal/hostagent/mdadm_test.go
index 21a17c197c..de57734818 100644
--- a/internal/hostagent/mdadm_test.go
+++ b/internal/hostagent/mdadm_test.go
@@ -830,53 +830,118 @@ func TestCollectArraysPartialSuccessIgnoresDetailErrors(t *testing.T) {
}
}
-func TestGetRebuildSpeed(t *testing.T) {
- mdstat := `md0 : active raid1 sda1[0] sdb1[1]
+func TestGetMdstatProgress(t *testing.T) {
+ tests := []struct {
+ name string
+ device string
+ mdstat string
+ wantOp string
+ wantSpeed string
+ }{
+ {
+ name: "recovery rebuild",
+ device: "/dev/md0",
+ mdstat: `md0 : active raid1 sda1[0] sdb1[1]
[>....................] recovery = 12.6% (37043392/293039104) finish=127.5min speed=33440K/sec
-`
- withReadProcMDStat(t, func() ([]byte, error) {
- return []byte(mdstat), nil
- })
+`,
+ wantOp: "recovery",
+ wantSpeed: "33440K/sec",
+ },
+ {
+ name: "check data scrub",
+ device: "/dev/md2",
+ mdstat: `md2 : active raid5 sdb1[0] sdc1[1] sdd1[2]
+ 14649176064 blocks super 1.2 level 5, 512k chunk
+ [==>..................] check = 12.6% (37043392/293039104) finish=127.5min speed=12000K/sec
+`,
+ wantOp: "check",
+ wantSpeed: "12000K/sec",
+ },
+ {
+ name: "resync maintenance",
+ device: "/dev/md1",
+ mdstat: `md1 : active raid1 sda2[0] sdb2[1]
+ [=>...................] resync = 5.0% (1048576/20971520) finish=2.5min speed=140000K/sec
+`,
+ wantOp: "resync",
+ wantSpeed: "140000K/sec",
+ },
+ {
+ name: "reshape",
+ device: "/dev/md3",
+ mdstat: `md3 : active raid5 sdb1[0] sdc1[1] sdd1[2] sde1[3]
+ [====>................] reshape = 25.0% (...) finish=10min speed=50000K/sec
+`,
+ wantOp: "reshape",
+ wantSpeed: "50000K/sec",
+ },
+ {
+ name: "idle array",
+ device: "/dev/md0",
+ mdstat: `md0 : active raid1 sda1[0] sdb1[1]
+ 102400000 blocks super 1.2 [2/2] [UU]
+`,
+ },
+ {
+ name: "device not present",
+ device: "/dev/md9",
+ mdstat: `md0 : active raid1 sda1[0] sdb1[1]
+ [>....................] recovery = 12.6% (...) finish=127.5min speed=33440K/sec
+`,
+ },
+ }
- speed := getRebuildSpeed("/dev/md0")
- if speed != "33440K/sec" {
- t.Fatalf("unexpected speed: %s", speed)
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ withReadProcMDStat(t, func() ([]byte, error) {
+ return []byte(tt.mdstat), nil
+ })
+
+ gotOp, gotSpeed := getMdstatProgress(tt.device)
+ if gotOp != tt.wantOp {
+ t.Errorf("operation = %q, want %q", gotOp, tt.wantOp)
+ }
+ if gotSpeed != tt.wantSpeed {
+ t.Errorf("speed = %q, want %q", gotSpeed, tt.wantSpeed)
+ }
+ })
}
}
-func TestGetRebuildSpeedNoMatch(t *testing.T) {
+func TestGetMdstatProgressNoMatch(t *testing.T) {
withReadProcMDStat(t, func() ([]byte, error) {
return []byte("md0 : active raid1 sda1[0]"), nil
})
- speed := getRebuildSpeed("/dev/md0")
- if speed != "" {
- t.Fatalf("expected empty speed, got %s", speed)
+ op, speed := getMdstatProgress("/dev/md0")
+ if op != "" || speed != "" {
+ t.Fatalf("expected empty op/speed, got op=%q speed=%q", op, speed)
}
}
-func TestGetRebuildSpeedError(t *testing.T) {
+func TestGetMdstatProgressError(t *testing.T) {
withReadProcMDStat(t, func() ([]byte, error) {
return nil, errors.New("read failed")
})
- speed := getRebuildSpeed("/dev/md0")
- if speed != "" {
- t.Fatalf("expected empty speed, got %s", speed)
+ op, speed := getMdstatProgress("/dev/md0")
+ if op != "" || speed != "" {
+ t.Fatalf("expected empty op/speed, got op=%q speed=%q", op, speed)
}
}
-func TestGetRebuildSpeedWithCommandError(t *testing.T) {
+func TestGetMdstatProgressWithCommandError(t *testing.T) {
withReadProcMDStat(t, func() ([]byte, error) {
return nil, context.Canceled
})
- if speed := getRebuildSpeed("/dev/md0"); speed != "" {
- t.Fatalf("expected empty speed, got %s", speed)
+ op, speed := getMdstatProgress("/dev/md0")
+ if op != "" || speed != "" {
+ t.Fatalf("expected empty op/speed, got op=%q speed=%q", op, speed)
}
}
-func TestParseDetailSetsRebuildSpeed(t *testing.T) {
+func TestParseDetailSetsRebuildSpeedAndOperation(t *testing.T) {
output := `/dev/md0:
Raid Level : raid1
State : clean
@@ -899,18 +964,51 @@ func TestParseDetailSetsRebuildSpeed(t *testing.T) {
if array.RebuildSpeed != "1234K/sec" {
t.Fatalf("expected rebuild speed, got %s", array.RebuildSpeed)
}
+ if array.Operation != "recovery" {
+ t.Fatalf("expected operation=recovery, got %q", array.Operation)
+ }
}
-func TestGetRebuildSpeedSectionExit(t *testing.T) {
+func TestParseDetailScrubOperation(t *testing.T) {
+ output := `/dev/md2:
+ Raid Level : raid5
+ State : clean
+ Active Devices : 3
+ Working Devices : 3
+ Failed Devices : 0
+
+ Number Major Minor RaidDevice State
+ 0 8 1 0 active sync /dev/sdb1`
+
+ mdstat := `md2 : active raid5 sdb1[0] sdc1[1] sdd1[2]
+ [==>..................] check = 12.6% (37043392/293039104) finish=127.5min speed=12000K/sec
+`
+ withReadProcMDStat(t, func() ([]byte, error) {
+ return []byte(mdstat), nil
+ })
+
+ array, err := parseMdadmDetail("/dev/md2", output)
+ if err != nil {
+ t.Fatalf("parseMdadmDetail error: %v", err)
+ }
+ if array.Operation != "check" {
+ t.Fatalf("expected operation=check, got %q", array.Operation)
+ }
+}
+
+func TestGetMdstatProgressSectionExit(t *testing.T) {
mdstat := `md0 : active raid1 sda1[0]
[>....................] recovery = 12.6% (37043392/293039104) finish=127.5min
md1 : active raid1 sdb1[0]
`
- withRunCommandOutput(t, func(ctx context.Context, name string, args ...string) ([]byte, error) {
+ withReadProcMDStat(t, func() ([]byte, error) {
return []byte(mdstat), nil
})
- speed := getRebuildSpeed("/dev/md0")
+ op, speed := getMdstatProgress("/dev/md0")
+ if op != "recovery" {
+ t.Fatalf("expected op=recovery, got %q", op)
+ }
if speed != "" {
t.Fatalf("expected empty speed, got %s", speed)
}
diff --git a/internal/models/models.go b/internal/models/models.go
index 8d04b23be7..5bb88eff85 100644
--- a/internal/models/models.go
+++ b/internal/models/models.go
@@ -401,6 +401,9 @@ type HostRAIDArray struct {
Devices []HostRAIDDevice `json:"devices"`
RebuildPercent float64 `json:"rebuildPercent"`
RebuildSpeed string `json:"rebuildSpeed,omitempty"`
+ // Operation is the in-progress sync action from /proc/mdstat
+ // ("recovery", "resync", "check", or "reshape"); empty when idle.
+ Operation string `json:"operation,omitempty"`
}
func (a HostRAIDArray) NormalizeCollections() HostRAIDArray {
diff --git a/internal/monitoring/monitor.go b/internal/monitoring/monitor.go
index 1552689489..015fb9f94d 100644
--- a/internal/monitoring/monitor.go
+++ b/internal/monitoring/monitor.go
@@ -3346,6 +3346,7 @@ func hostRAIDFromReadStateView(raid []unifiedresources.HostRAIDMeta) []models.Ho
Devices: devices,
RebuildPercent: entry.RebuildPercent,
RebuildSpeed: entry.RebuildSpeed,
+ Operation: entry.Operation,
})
}
return out
diff --git a/internal/monitoring/monitor_agents.go b/internal/monitoring/monitor_agents.go
index a78fbeb1bf..3307afd042 100644
--- a/internal/monitoring/monitor_agents.go
+++ b/internal/monitoring/monitor_agents.go
@@ -1779,6 +1779,7 @@ func (m *Monitor) ApplyHostReport(report agentshost.Report, tokenRecord *config.
Devices: devices,
RebuildPercent: array.RebuildPercent,
RebuildSpeed: array.RebuildSpeed,
+ Operation: array.Operation,
})
}
diff --git a/internal/storagehealth/topology.go b/internal/storagehealth/topology.go
index 135006a9d7..58d0a4c561 100644
--- a/internal/storagehealth/topology.go
+++ b/internal/storagehealth/topology.go
@@ -22,10 +22,12 @@ func AssessHostRAIDArray(array models.HostRAIDArray) Assessment {
}
stateLower := strings.ToLower(strings.TrimSpace(array.State))
- isChecking := strings.Contains(stateLower, "check")
- isRebuilding := !isChecking && (strings.Contains(stateLower, "recover") ||
- strings.Contains(stateLower, "resync") ||
- (array.RebuildPercent > 0 && !strings.Contains(stateLower, "clean")))
+ operation := strings.ToLower(strings.TrimSpace(array.Operation))
+ isMaintenance := operation == "check" || operation == "resync"
+ isRebuilding := !isMaintenance && (operation == "recovery" ||
+ operation == "reshape" ||
+ (operation == "" && (strings.Contains(stateLower, "recover") ||
+ (array.RebuildPercent > 0 && !strings.Contains(stateLower, "clean") && !strings.Contains(stateLower, "check")))))
if strings.Contains(stateLower, "degraded") || array.FailedDevices > 0 || (array.TotalDevices > 0 && array.ActiveDevices > 0 && array.ActiveDevices < array.TotalDevices) {
summary := fmt.Sprintf("RAID array %s is degraded", array.Device)
diff --git a/internal/storagehealth/topology_test.go b/internal/storagehealth/topology_test.go
index f7b4dae487..cff55cd34e 100644
--- a/internal/storagehealth/topology_test.go
+++ b/internal/storagehealth/topology_test.go
@@ -27,6 +27,7 @@ func TestAssessHostRAIDArrayRebuilding(t *testing.T) {
assessment := AssessHostRAIDArray(models.HostRAIDArray{
Device: "/dev/md3",
State: "recovering",
+ Operation: "recovery",
RebuildPercent: 42,
})
@@ -35,6 +36,69 @@ func TestAssessHostRAIDArrayRebuilding(t *testing.T) {
}
}
+func TestAssessHostRAIDArrayRecoveryOperationAlerts(t *testing.T) {
+ assessment := AssessHostRAIDArray(models.HostRAIDArray{
+ Device: "/dev/md2",
+ State: "active, recovering",
+ Operation: "recovery",
+ RebuildPercent: 12.6,
+ TotalDevices: 2,
+ ActiveDevices: 2,
+ })
+
+ if assessment.Level != RiskWarning {
+ t.Fatalf("Level = %q, want %q", assessment.Level, RiskWarning)
+ }
+ if !hasReasonCode(assessment, "raid_rebuilding") {
+ t.Fatalf("expected raid_rebuilding reason, got %+v", assessment.Reasons)
+ }
+}
+
+func TestAssessHostRAIDArrayCheckOperationIsSilent(t *testing.T) {
+ assessment := AssessHostRAIDArray(models.HostRAIDArray{
+ Device: "/dev/md2",
+ State: "active",
+ Operation: "check",
+ RebuildPercent: 12.6,
+ TotalDevices: 3,
+ ActiveDevices: 3,
+ })
+
+ if assessment.Level != RiskHealthy {
+ t.Fatalf("Level = %q, want %q; reasons=%+v", assessment.Level, RiskHealthy, assessment.Reasons)
+ }
+ if hasReasonCode(assessment, "raid_rebuilding") {
+ t.Fatalf("did not expect raid_rebuilding for scrub operation, got %+v", assessment.Reasons)
+ }
+}
+
+func TestAssessHostRAIDArrayResyncOperationIsSilent(t *testing.T) {
+ assessment := AssessHostRAIDArray(models.HostRAIDArray{
+ Device: "/dev/md2",
+ State: "active, resyncing",
+ Operation: "resync",
+ RebuildPercent: 12.6,
+ TotalDevices: 2,
+ ActiveDevices: 2,
+ })
+
+ if assessment.Level != RiskHealthy {
+ t.Fatalf("Level = %q, want %q; reasons=%+v", assessment.Level, RiskHealthy, assessment.Reasons)
+ }
+ if hasReasonCode(assessment, "raid_rebuilding") {
+ t.Fatalf("did not expect raid_rebuilding for resync operation, got %+v", assessment.Reasons)
+ }
+}
+
+func hasReasonCode(assessment Assessment, code string) bool {
+ for _, reason := range assessment.Reasons {
+ if reason.Code == code {
+ return true
+ }
+ }
+ return false
+}
+
func TestFilterVendorManagedSystemRAIDArrays(t *testing.T) {
testCases := []struct {
name string
diff --git a/internal/unifiedresources/adapters.go b/internal/unifiedresources/adapters.go
index 4701a7e021..e4c90b5302 100644
--- a/internal/unifiedresources/adapters.go
+++ b/internal/unifiedresources/adapters.go
@@ -223,6 +223,7 @@ func resourceFromHost(host models.Host) (Resource, ResourceIdentity) {
Devices: devices,
RebuildPercent: r.RebuildPercent,
RebuildSpeed: r.RebuildSpeed,
+ Operation: r.Operation,
Risk: storageRiskFromAssessment(assessment),
}
if !isInternalHostRAIDDevice(r.Device) {
diff --git a/internal/unifiedresources/types.go b/internal/unifiedresources/types.go
index 0b138e0c36..3bd548da2c 100644
--- a/internal/unifiedresources/types.go
+++ b/internal/unifiedresources/types.go
@@ -478,6 +478,7 @@ type HostRAIDMeta struct {
Devices []HostRAIDDeviceMeta `json:"devices,omitempty"`
RebuildPercent float64 `json:"rebuildPercent,omitempty"`
RebuildSpeed string `json:"rebuildSpeed,omitempty"`
+ Operation string `json:"operation,omitempty"`
Risk *StorageRisk `json:"risk,omitempty"`
}
diff --git a/pkg/agents/host/report.go b/pkg/agents/host/report.go
index f857e23580..663cfdeddc 100644
--- a/pkg/agents/host/report.go
+++ b/pkg/agents/host/report.go
@@ -162,6 +162,9 @@ type RAIDArray struct {
Devices []RAIDDevice `json:"devices"` // Individual devices in array
RebuildPercent float64 `json:"rebuildPercent"` // Rebuild/resync progress (0-100)
RebuildSpeed string `json:"rebuildSpeed,omitempty"` // Rebuild speed (e.g., "50000K/sec")
+ // Operation reports the in-progress sync action from /proc/mdstat:
+ // "recovery", "resync", "check", or "reshape". Empty when idle.
+ Operation string `json:"operation,omitempty"`
}
// RAIDDevice represents a single device in a RAID array.