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>
84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
package inspur
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/gzip"
|
|
"fmt"
|
|
"io"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"git.mchus.pro/mchus/logpile/internal/models"
|
|
)
|
|
|
|
const componentReplaceEventType = "Component Replace"
|
|
|
|
var (
|
|
reComponentReplace = regexp.MustCompile(`(?i)^Component Replace\s+(\S+)\s+(?:SN\s+)?changed from\s+(\S+)\s+to\s+(\S+?)!?(?:\s+-\s+(?:Assert|Deassert))?\s*$`)
|
|
reInspurDIMMCode = regexp.MustCompile(`(?i)^DIMM(\d)(\d)(\d)$`)
|
|
)
|
|
|
|
// ParseMaintenanceLog extracts BMC component replacement records
|
|
// ("Component Replace DIMM021 SN changed from NULL to …") from
|
|
// maintenance.log. The BMC writes them only there, not to IDL/SEL, and they
|
|
// are the only trace of when a DIMM, CPU or PSU was installed or swapped.
|
|
// Other maintenance.log lines are daemon chatter and are ignored.
|
|
func ParseMaintenanceLog(content []byte) []models.Event {
|
|
var events []models.Event
|
|
for _, event := range ParseIDLLog(content) {
|
|
match := reComponentReplace.FindStringSubmatch(strings.TrimSpace(event.Description))
|
|
if match == nil {
|
|
continue
|
|
}
|
|
device, from, to := match[1], match[2], match[3]
|
|
sensorName := device
|
|
if slot, ok := inspurDIMMCodeToSlot(device); ok {
|
|
sensorName = slot
|
|
}
|
|
|
|
action := "replaced"
|
|
switch {
|
|
case strings.EqualFold(from, "NULL"):
|
|
action = "installed"
|
|
case strings.EqualFold(to, "NULL"):
|
|
action = "removed"
|
|
}
|
|
description := fmt.Sprintf("%s %s: SN %s → %s", sensorName, action, from, to)
|
|
if sensorName != device {
|
|
description = fmt.Sprintf("%s (%s) %s: SN %s → %s", sensorName, device, action, from, to)
|
|
}
|
|
|
|
event.EventType = componentReplaceEventType
|
|
event.SensorName = sensorName
|
|
event.Severity = models.SeverityInfo
|
|
event.Description = description
|
|
event.RawData = strings.TrimSpace(match[0])
|
|
events = append(events, event)
|
|
}
|
|
return events
|
|
}
|
|
|
|
// inspurDIMMCodeToSlot maps the BMC asset code DIMM<cpu><channel><dimm>
|
|
// (e.g. DIMM021) to the inventory slot name CPU0_C2D1.
|
|
func inspurDIMMCodeToSlot(code string) (string, bool) {
|
|
match := reInspurDIMMCode.FindStringSubmatch(strings.TrimSpace(code))
|
|
if match == nil {
|
|
return "", false
|
|
}
|
|
return fmt.Sprintf("CPU%s_C%sD%s", match[1], match[2], match[3]), true
|
|
}
|
|
|
|
// decodeGzipLog returns the plain text of a rotated "*.log.N.gz" member.
|
|
func decodeGzipLog(content []byte) []byte {
|
|
gz, err := gzip.NewReader(bytes.NewReader(content))
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
defer gz.Close()
|
|
out, err := io.ReadAll(io.LimitReader(gz, 64<<20))
|
|
if err != nil {
|
|
return nil
|
|
}
|
|
return out
|
|
}
|