Files
logpile/internal/parser/vendors/inspur/memory_status.go
T
Mikhail ChusavitinandClaude Opus 5.5 693906ceba feat(inspur): keep DIMM state on the DIMM, parse maintenance.log installs
component.log memory status produced synthetic "Memory module … not
detected (capacity 0GB)" events that duplicated IDL/SEL "Memory Device
Disabled … POR Mapout" Asserts already in the journal, with a wrong text
(the modules are present).

- Drop synthetic memory events. The snapshot status stays authoritative
  on the DIMM; the journal Assert/Deassert supplies status_history, the
  fault description and status_changed_at (latest active Assert).
- Drop a component.log fan state event when the journal already holds an
  active Assert for that fan.
- Parse "Component Replace <dev> SN changed from X to Y" from
  maintenance.log and rotated maintenance.log.N.gz into Info events,
  mapping DIMM<cpu><ch><dimm> to the inventory slot (DIMM021 -> CPU0_C2D1).

ADL-071.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 13:01:30 +03:00

95 lines
2.5 KiB
Go

package inspur
import (
"fmt"
"sort"
"strings"
"git.mchus.pro/mchus/logpile/internal/models"
)
// applyMemoryStatusFromEvents explains DIMM state reported by the
// component.log snapshot using the BMC journal (IDL/SEL Assert/Deassert).
// The snapshot stays authoritative for the current status; the journal
// supplies transition history, the fault description and when the
// currently asserted fault started. Snapshot state is never duplicated
// into the event log.
func applyMemoryStatusFromEvents(hw *models.HardwareConfig, events []models.Event) {
if hw == nil || len(hw.Memory) == 0 {
return
}
bySlot := make(map[string][]models.Event)
for _, event := range events {
if !strings.EqualFold(strings.TrimSpace(event.SensorType), "memory") || event.Timestamp.IsZero() {
continue
}
etype := strings.ToLower(strings.TrimSpace(event.EventType))
if etype != "assert" && etype != "deassert" {
continue
}
slot := strings.ToUpper(strings.TrimSpace(event.SensorName))
if slot == "" {
continue
}
bySlot[slot] = append(bySlot[slot], event)
}
for i := range hw.Memory {
dimm := &hw.Memory[i]
journal := bySlot[strings.ToUpper(strings.TrimSpace(dimm.Slot))]
sort.SliceStable(journal, func(a, b int) bool {
return journal[a].Timestamp.Before(journal[b].Timestamp)
})
var active *models.Event
lastStatus := ""
for j := range journal {
event := journal[j]
status := "OK"
if eventIsDeassert(event) {
active = nil
} else {
status = "Warning"
if event.Severity == models.SeverityCritical {
status = "Critical"
}
active = &journal[j]
}
if status == lastStatus {
continue
}
lastStatus = status
dimm.StatusHistory = append(dimm.StatusHistory, models.StatusHistoryEntry{
Status: status,
ChangedAt: event.Timestamp,
Details: strings.TrimSpace(event.Description),
})
}
if !memoryStatusIsFault(dimm.Status) {
continue
}
if active != nil {
ts := active.Timestamp
dimm.StatusChangedAt = &ts
if strings.TrimSpace(dimm.ErrorDescription) == "" {
dimm.ErrorDescription = strings.Join(strings.Fields(active.Description), " ")
}
continue
}
if strings.TrimSpace(dimm.ErrorDescription) == "" {
dimm.ErrorDescription = fmt.Sprintf("BMC reported %s at log collection; no matching journal entry", dimm.Status)
}
}
}
func memoryStatusIsFault(status string) bool {
switch strings.ToLower(strings.TrimSpace(status)) {
case "warning", "error", "critical":
return true
default:
return false
}
}