package inspur import ( "strings" "git.mchus.pro/mchus/logpile/internal/models" ) // applyActiveFromDeviceStatus marks journal alarms with the BMC's own // active-alarm snapshot (dev_status.log, taken at log collection). A // Warning/Critical Assert listed there is active; one missing from it is // not, even without a logged Deassert (AC loss or a BMC reset drops those). // Info-level asserts are one-shot notifications and stay unmarked. func applyActiveFromDeviceStatus(events, current []models.Event) { type activeAlarm struct { id string sensor string } bySecond := make(map[int64][]activeAlarm) for _, alarm := range current { if alarm.Timestamp.IsZero() || eventIsDeassert(alarm) { continue } sec := alarm.Timestamp.Unix() bySecond[sec] = append(bySecond[sec], activeAlarm{ id: strings.ToUpper(strings.TrimSpace(alarm.ID)), sensor: strings.ToUpper(strings.TrimSpace(alarm.SensorName)), }) } for i := range events { event := &events[i] if event.Active != nil || event.Timestamp.IsZero() || !isAlarmSeverity(event.Severity) { continue } source := strings.ToUpper(strings.TrimSpace(event.Source)) if source != "BMC" && source != "SEL" { continue } if eventIsDeassert(*event) { continue } active := false id := strings.ToUpper(strings.TrimSpace(event.ID)) sensor := strings.ToUpper(strings.TrimSpace(event.SensorName)) for _, alarm := range bySecond[event.Timestamp.Unix()] { // IDL records match by event ID; SEL records carry a record // number instead and match by sensor name at the same instant. if (source == "BMC" && id == alarm.id) || (source == "SEL" && sensor != "" && alarm.sensor != "" && (strings.Contains(sensor, alarm.sensor) || strings.Contains(alarm.sensor, sensor))) { active = true break } } event.Active = &active } } func isAlarmSeverity(severity models.Severity) bool { return severity == models.SeverityWarning || severity == models.SeverityCritical }