From 09b235431508301ad4f370950cee1a8d93340da5 Mon Sep 17 00:00:00 2001 From: "Harper, Jason M" Date: Thu, 26 Jun 2025 08:49:42 -0700 Subject: [PATCH 1/2] fix NIC data parsing for report Signed-off-by: Harper, Jason M --- internal/report/table_helpers.go | 71 +++++++++++++++++++++++++------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/internal/report/table_helpers.go b/internal/report/table_helpers.go index b93d235f..f33d32b4 100644 --- a/internal/report/table_helpers.go +++ b/internal/report/table_helpers.go @@ -1363,24 +1363,67 @@ func parseNicInfo(scriptOutput string) []nicInfo { var nic nicInfo for line := range strings.SplitSeq(nicOutput, "\n") { line = strings.TrimSpace(line) - nic.Name, _ = strings.CutPrefix(line, "Interface: ") - nic.Vendor, _ = strings.CutPrefix(line, "Vendor: ") - nic.VendorID, _ = strings.CutPrefix(line, "Vendor ID: ") + if after, ok := strings.CutPrefix(line, "Interface: "); ok { + nic.Name = after + continue + } + if after, ok := strings.CutPrefix(line, "Vendor: "); ok { + nic.Vendor = after + continue + } + if after, ok := strings.CutPrefix(line, "Vendor ID: "); ok { + nic.VendorID = after + continue + } if strings.HasPrefix(line, "Model: ") { // sometimes the model name has additional information in parentheses, we want to keep only the model name nic.Model = strings.TrimSpace(strings.TrimPrefix(strings.Split(line, "(")[0], "Model: ")) + continue + } + if after, ok := strings.CutPrefix(line, "Model ID: "); ok { + nic.ModelID = after + continue + } + if after, ok := strings.CutPrefix(line, "Speed: "); ok { + nic.Speed = after + continue + } + if after, ok := strings.CutPrefix(line, "Link detected: "); ok { + nic.Link = after + continue + } + if after, ok := strings.CutPrefix(line, "bus-info: "); ok { + nic.Bus = after + continue + } + if after, ok := strings.CutPrefix(line, "driver: "); ok { + nic.Driver = after + continue + } + if after, ok := strings.CutPrefix(line, "version: "); ok { + nic.DriverVersion = after + continue + } + if after, ok := strings.CutPrefix(line, "firmware-version: "); ok { + nic.FirmwareVersion = after + continue + } + if after, ok := strings.CutPrefix(line, "MAC Address: "); ok { + nic.MACAddress = after + continue + } + if after, ok := strings.CutPrefix(line, "NUMA Node: "); ok { + nic.NUMANode = after + continue + } + if after, ok := strings.CutPrefix(line, "CPU Affinity: "); ok { + nic.CPUAffinity = after + continue + } + if after, ok := strings.CutPrefix(line, "IRQ Balance: "); ok { + nic.IRQBalance = after + continue } - nic.ModelID, _ = strings.CutPrefix(line, "Model ID: ") - nic.Speed, _ = strings.CutPrefix(line, "Speed: ") - nic.Link, _ = strings.CutPrefix(line, "Link detected: ") - nic.Bus, _ = strings.CutPrefix(line, "bus-info: ") - nic.Driver, _ = strings.CutPrefix(line, "driver: ") - nic.DriverVersion, _ = strings.CutPrefix(line, "version: ") - nic.FirmwareVersion, _ = strings.CutPrefix(line, "firmware-version: ") - nic.MACAddress, _ = strings.CutPrefix(line, "MAC Address: ") - nic.NUMANode, _ = strings.CutPrefix(line, "NUMA Node: ") - nic.CPUAffinity, _ = strings.CutPrefix(line, "CPU Affinity: ") - nic.IRQBalance, _ = strings.CutPrefix(line, "IRQ Balance: ") } nics = append(nics, nic) } From 9437fbb1e72d4f033ff6a0940e1beb7836dafa04 Mon Sep 17 00:00:00 2001 From: "Harper, Jason M" Date: Thu, 26 Jun 2025 09:18:35 -0700 Subject: [PATCH 2/2] refactor Signed-off-by: Harper, Jason M --- internal/report/table_helpers.go | 85 ++++++++++---------------------- 1 file changed, 25 insertions(+), 60 deletions(-) diff --git a/internal/report/table_helpers.go b/internal/report/table_helpers.go index f33d32b4..fe3ebade 100644 --- a/internal/report/table_helpers.go +++ b/internal/report/table_helpers.go @@ -1361,70 +1361,35 @@ func parseNicInfo(scriptOutput string) []nicInfo { continue } var nic nicInfo + // Map of prefixes to field pointers + fieldMap := map[string]*string{ + "Interface: ": &nic.Name, + "Vendor: ": &nic.Vendor, + "Vendor ID: ": &nic.VendorID, + "Model: ": &nic.Model, + "Model ID: ": &nic.ModelID, + "Speed: ": &nic.Speed, + "Link detected: ": &nic.Link, + "bus-info: ": &nic.Bus, + "driver: ": &nic.Driver, + "version: ": &nic.DriverVersion, + "firmware-version: ": &nic.FirmwareVersion, + "MAC Address: ": &nic.MACAddress, + "NUMA Node: ": &nic.NUMANode, + "CPU Affinity: ": &nic.CPUAffinity, + "IRQ Balance: ": &nic.IRQBalance, + } for line := range strings.SplitSeq(nicOutput, "\n") { line = strings.TrimSpace(line) - if after, ok := strings.CutPrefix(line, "Interface: "); ok { - nic.Name = after - continue - } - if after, ok := strings.CutPrefix(line, "Vendor: "); ok { - nic.Vendor = after - continue - } - if after, ok := strings.CutPrefix(line, "Vendor ID: "); ok { - nic.VendorID = after - continue - } - if strings.HasPrefix(line, "Model: ") { - // sometimes the model name has additional information in parentheses, we want to keep only the model name - nic.Model = strings.TrimSpace(strings.TrimPrefix(strings.Split(line, "(")[0], "Model: ")) - continue - } - if after, ok := strings.CutPrefix(line, "Model ID: "); ok { - nic.ModelID = after - continue - } - if after, ok := strings.CutPrefix(line, "Speed: "); ok { - nic.Speed = after - continue - } - if after, ok := strings.CutPrefix(line, "Link detected: "); ok { - nic.Link = after - continue - } - if after, ok := strings.CutPrefix(line, "bus-info: "); ok { - nic.Bus = after - continue - } - if after, ok := strings.CutPrefix(line, "driver: "); ok { - nic.Driver = after - continue - } - if after, ok := strings.CutPrefix(line, "version: "); ok { - nic.DriverVersion = after - continue - } - if after, ok := strings.CutPrefix(line, "firmware-version: "); ok { - nic.FirmwareVersion = after - continue - } - if after, ok := strings.CutPrefix(line, "MAC Address: "); ok { - nic.MACAddress = after - continue - } - if after, ok := strings.CutPrefix(line, "NUMA Node: "); ok { - nic.NUMANode = after - continue - } - if after, ok := strings.CutPrefix(line, "CPU Affinity: "); ok { - nic.CPUAffinity = after - continue - } - if after, ok := strings.CutPrefix(line, "IRQ Balance: "); ok { - nic.IRQBalance = after - continue + for prefix, fieldPtr := range fieldMap { + if after, ok := strings.CutPrefix(line, prefix); ok { + *fieldPtr = after + break + } } } + // special case for model as it sometimes has additional information in parentheses + nic.Model = strings.TrimSpace(strings.Split(nic.Model, "(")[0]) nics = append(nics, nic) } return nics