Fix NVIDIA GPU/NVSwitch parsing and Reanimator export statuses
This commit is contained in:
@@ -3,6 +3,7 @@ package nvidia
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"git.mchus.pro/mchus/logpile/internal/models"
|
||||
@@ -53,6 +54,8 @@ type Property struct {
|
||||
Value interface{} `json:"value"` // Can be string or number
|
||||
}
|
||||
|
||||
var nvswitchComponentIDRegex = regexp.MustCompile(`^(NVSWITCH\d+|NVSWITCHNVSWITCH\d+)$`)
|
||||
|
||||
// GetValueAsString returns the value as a string
|
||||
func (p *Property) GetValueAsString() string {
|
||||
switch v := p.Value.(type) {
|
||||
@@ -107,7 +110,7 @@ func parseInventoryComponents(components []Component, result *models.AnalysisRes
|
||||
}
|
||||
|
||||
// Parse NVSwitch components
|
||||
if strings.HasPrefix(comp.ComponentID, "NVSWITCHNVSWITCH") {
|
||||
if isNVSwitchComponentID(comp.ComponentID) {
|
||||
nvswitch := parseNVSwitchComponent(comp)
|
||||
if nvswitch != nil {
|
||||
// Add as PCIe device for now
|
||||
@@ -217,7 +220,7 @@ func parseGPUComponent(comp Component) *models.GPU {
|
||||
// parseNVSwitchComponent parses NVSwitch component information
|
||||
func parseNVSwitchComponent(comp Component) *models.PCIeDevice {
|
||||
device := &models.PCIeDevice{
|
||||
Slot: comp.ComponentID, // e.g., "NVSWITCHNVSWITCH0"
|
||||
Slot: normalizeNVSwitchSlot(comp.ComponentID),
|
||||
}
|
||||
|
||||
var vendorIDStr, deviceIDStr, vbios, pciID string
|
||||
@@ -279,3 +282,15 @@ func parseNVSwitchComponent(comp Component) *models.PCIeDevice {
|
||||
|
||||
return device
|
||||
}
|
||||
|
||||
func normalizeNVSwitchSlot(componentID string) string {
|
||||
slot := strings.TrimSpace(componentID)
|
||||
if strings.HasPrefix(slot, "NVSWITCHNVSWITCH") {
|
||||
return strings.Replace(slot, "NVSWITCHNVSWITCH", "NVSWITCH", 1)
|
||||
}
|
||||
return slot
|
||||
}
|
||||
|
||||
func isNVSwitchComponentID(componentID string) bool {
|
||||
return nvswitchComponentIDRegex.MatchString(strings.TrimSpace(componentID))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user