Files
logpile/internal/parser/vendors/inspur/fru.go
T
mchusandClaude Sonnet 5 74e6bf0578 fix(parser): support Inspur HGX dump_<serial>_<timestamp>/ onekeylog layout
Fixes #20. This onekeylog variant has no devicefrusdr.log at all: FRU/sensors
come from raw ipmitool text output, PCIe/GPU presence has a dedicated
structural snapshot, SEL lives at a different path, and BMC component
failures are logged separately from SEL/IDL.

- Fall back to component/fru.txt (same FRU block format as devicefrusdr.log)
  and component/sensor.txt / sdr.txt (ipmitool sensor list / sdr elist)
  when devicefrusdr.log is absent.
- Parse log/bmc/diagnose/OtrdDiagnoseComponent.json's PCIe Device Info array
  for GPU/PCIe presence and link state, independent of SEL/IDL alarm
  history; flag devices running below their negotiated max link
  speed/width as degraded with a Warning event.
- Fall back to log/sel.csv (same format as selelist.csv) when selelist.csv
  is absent.
- Parse log/bmc/commer-comp/{commerslot,commerhmc,commerswvr,commerswcpld}
  logs (including rotated *.tar.gz.N parts) into failure events, filtering
  known-noisy lines.
- Collapse SEL events duplicated across sources by
  (timestamp, event_type, description).
- Surface a CollectionError when FRU/sensors are still empty after all
  fallbacks, instead of silently returning an empty inventory.
- Fix ParseFRU: a later placeholder "Product Serial : 0" / "Product Part
  Number : NULL" line in the same FRU block (e.g. SCM_FRU) was overwriting
  an already-parsed real Board Serial/Part Number.

Verified against dump_23DB01633_20260727-1359.tar.gz (HGX B200, KR9288-X3):
fru 0→21, sensors 0→303, 8 GPUs present at Gen5 x16 in slots 100-107.

Deferred (not covered by this change): BIOS-change-settings context and
BIOS POST codes from the same layout — see bible-local/10-decisions.md
ADL-048.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-29 10:05:58 +03:00

168 lines
4.8 KiB
Go

package inspur
import (
"bufio"
"regexp"
"strings"
"git.mchus.pro/mchus/logpile/internal/models"
)
var (
fruDeviceRegex = regexp.MustCompile(`^FRU Device Description\s*:\s*(.+)$`)
fruFieldRegex = regexp.MustCompile(`^\s+(.+?)\s*:\s*(.*)$`)
platformIdRegex = regexp.MustCompile(`(?i)PlatformId\s*=\s*(\S+)`)
)
// ParseFRU parses BMC FRU (Field Replaceable Unit) output
func ParseFRU(content []byte) []models.FRUInfo {
var fruList []models.FRUInfo
var current *models.FRUInfo
scanner := bufio.NewScanner(strings.NewReader(string(content)))
for scanner.Scan() {
line := scanner.Text()
// Check for new FRU device
if matches := fruDeviceRegex.FindStringSubmatch(line); matches != nil {
if current != nil && current.Description != "" {
fruList = append(fruList, *current)
}
current = &models.FRUInfo{
Description: strings.TrimSpace(matches[1]),
}
continue
}
// Skip if no current FRU device
if current == nil {
continue
}
// Skip "Device not present" entries
if strings.Contains(line, "Device not present") {
current = nil
continue
}
// Parse FRU fields
if matches := fruFieldRegex.FindStringSubmatch(line); matches != nil {
fieldName := strings.TrimSpace(matches[1])
fieldValue := strings.TrimSpace(matches[2])
switch fieldName {
case "Chassis Type":
current.ChassisType = fieldValue
case "Chassis Part Number":
if fieldValue != "0" {
current.PartNumber = fieldValue
}
case "Chassis Serial":
if fieldValue != "0" {
current.SerialNumber = fieldValue
}
case "Board Mfg Date":
current.MfgDate = fieldValue
case "Board Mfg", "Product Manufacturer":
if fieldValue != "NULL" {
current.Manufacturer = fieldValue
}
case "Board Product", "Product Name":
if fieldValue != "NULL" {
current.ProductName = fieldValue
}
case "Board Serial", "Product Serial":
// Modules with no product-level FRU (e.g. SCM_FRU) report
// "Product Serial : 0" after a real "Board Serial" value;
// don't let the placeholder overwrite the real serial.
if fieldValue != "0" && fieldValue != "NULL" {
current.SerialNumber = fieldValue
}
case "Board Part Number", "Product Part Number":
// See "Board Serial" above: placeholder "NULL"/"0" product-level
// fields must not overwrite a real board-level part number.
if fieldValue != "0" && fieldValue != "NULL" {
current.PartNumber = fieldValue
}
case "Product Version":
if fieldValue != "0" {
current.Version = fieldValue
}
case "Product Asset Tag":
if fieldValue != "NULL" {
current.AssetTag = fieldValue
}
}
}
}
// Don't forget the last one
if current != nil && current.Description != "" {
fruList = append(fruList, *current)
}
return fruList
}
// extractBoardInfo extracts main board/chassis information from FRU data
func extractBoardInfo(fruList []models.FRUInfo, hw *models.HardwareConfig) {
if hw == nil || len(fruList) == 0 {
return
}
// Look for the main board/chassis FRU entry.
// Keep the first non-empty serial as the server serial and avoid overwriting it
// with module-specific serials (e.g., SCM_FRU).
for _, fru := range fruList {
// Skip empty entries
if fru.ProductName == "" && fru.SerialNumber == "" {
continue
}
// Prioritize entries that look like main board info
desc := strings.ToLower(fru.Description)
isMainBoard := strings.Contains(desc, "builtin") ||
strings.Contains(desc, "fru device") ||
strings.Contains(desc, "chassis") ||
strings.Contains(desc, "board")
if fru.SerialNumber != "" && hw.BoardInfo.SerialNumber == "" {
hw.BoardInfo.SerialNumber = fru.SerialNumber
}
if fru.ProductName != "" && (hw.BoardInfo.ProductName == "" || isMainBoard) {
hw.BoardInfo.ProductName = fru.ProductName
}
// Manufacturer from non-main FRU entries (e.g. PSU vendor) should not become server vendor.
if fru.Manufacturer != "" && isMainBoard && hw.BoardInfo.Manufacturer == "" {
hw.BoardInfo.Manufacturer = fru.Manufacturer
}
if fru.PartNumber != "" && (hw.BoardInfo.PartNumber == "" || isMainBoard) {
hw.BoardInfo.PartNumber = fru.PartNumber
}
// Main board entry with complete data is good enough to stop.
if isMainBoard && hw.BoardInfo.ProductName != "" && hw.BoardInfo.SerialNumber != "" {
break
}
}
}
// extractPlatformId extracts server model from ThermalConfig (PlatformId)
func extractPlatformId(content []byte, hw *models.HardwareConfig) {
if hw == nil {
return
}
if match := platformIdRegex.FindSubmatch(content); match != nil {
platformId := strings.TrimSpace(string(match[1]))
if platformId != "" {
// Set as ProductName (server model) - this takes priority over FRU data
hw.BoardInfo.ProductName = platformId
// Also set manufacturer as Inspur if not already set
if hw.BoardInfo.Manufacturer == "" {
hw.BoardInfo.Manufacturer = "Inspur"
}
}
}
}