fix: complete hardware collection diagnostics

This commit is contained in:
2026-08-25 17:04:33 +03:00
parent 33ace33de5
commit ccc781856e
19 changed files with 311 additions and 81 deletions
+40 -5
View File
@@ -652,21 +652,56 @@ func appendUniqueStorage(base, extra []schema.HardwareStorage) []schema.Hardware
if len(extra) == 0 {
return base
}
seen := map[string]bool{}
for _, d := range base {
seen[storageIdentityKey(d)] = true
seen := map[string]int{}
for i, d := range base {
if key := storageIdentityKey(d); key != "" {
seen[key] = i
}
}
for _, d := range extra {
key := storageIdentityKey(d)
if key == "" || seen[key] {
if key == "" {
continue
}
if idx, ok := seen[key]; ok {
mergeStorageRecord(&base[idx], d)
continue
}
base = append(base, d)
seen[key] = true
seen[key] = len(base) - 1
}
return base
}
func mergeStorageRecord(dst *schema.HardwareStorage, src schema.HardwareStorage) {
if dst.Model == nil {
dst.Model = src.Model
}
if dst.SizeGB == nil {
dst.SizeGB = src.SizeGB
}
if dst.Interface == nil {
dst.Interface = src.Interface
}
if dst.Firmware == nil {
dst.Firmware = src.Firmware
}
if dst.Slot == nil {
dst.Slot = src.Slot
}
if dst.Manufacturer == nil {
dst.Manufacturer = src.Manufacturer
}
if dst.Present == nil {
dst.Present = src.Present
}
// A RAID controller often reports JBOD as Unknown; never replace a direct
// device health reading with that weaker verdict.
if dst.Status == nil {
dst.Status = src.Status
}
}
func storageIdentityKey(d schema.HardwareStorage) string {
if d.SerialNumber != nil && strings.TrimSpace(*d.SerialNumber) != "" {
return "sn:" + strings.ToLower(strings.TrimSpace(*d.SerialNumber))