diff --git a/internal/exporter/reanimator_converter.go b/internal/exporter/reanimator_converter.go index 36031b2..537f947 100644 --- a/internal/exporter/reanimator_converter.go +++ b/internal/exporter/reanimator_converter.go @@ -49,7 +49,7 @@ func ConvertToReanimator(result *models.AnalysisResult) (*ReanimatorExport, erro Memory: dedupeMemory(convertMemoryFromDevices(devices, collectedAt)), Storage: dedupeStorage(convertStorageFromDevices(devices, collectedAt)), PCIeDevices: dedupePCIe(convertPCIeFromDevices(devices, collectedAt)), - PowerSupplies: dedupePSUs(convertPSUsFromDevices(devices, collectedAt)), + PowerSupplies: disambiguatePSUSlots(dedupePSUs(convertPSUsFromDevices(devices, collectedAt))), Sensors: convertSensors(result.Sensors), EventLogs: convertEventLogs(result.Events, collectedAt), Licenses: dedupeLicenses(convertLicenses(result.Hardware.Licenses, collectedAt)), @@ -2183,6 +2183,35 @@ func dedupePSUs(items []ReanimatorPSU) []ReanimatorPSU { return result } +// disambiguatePSUSlots renumbers PSU slots when two or more distinct PSUs +// (different serials, already survived dedupePSUs) report the same slot +// string from the source. Some collectors (e.g. BEE-SP) report every PSU +// at slot "0". A shared slot value prevents Reanimator from telling the +// PSUs apart by installed position, so they land in "other components" +// instead of being tracked as PSU installations. Reassigning stable 0-based +// positions by encounter order is the best available disambiguation without +// inventing a serial or other identity data we don't have. +func disambiguatePSUSlots(items []ReanimatorPSU) []ReanimatorPSU { + if len(items) < 2 { + return items + } + counts := make(map[string]int, len(items)) + for _, it := range items { + counts[strings.ToLower(strings.TrimSpace(it.Slot))]++ + } + next := make(map[string]int, len(items)) + for i := range items { + key := strings.ToLower(strings.TrimSpace(items[i].Slot)) + if counts[key] < 2 { + continue + } + idx := next[key] + next[key]++ + items[i].Slot = strconv.Itoa(idx) + } + return items +} + func dedupePCIe(items []ReanimatorPCIe) []ReanimatorPCIe { if len(items) < 2 { return items