Files
logpile/internal/exporter/reanimator_event_logs_test.go
T
Mikhail ChusavitinandClaude Opus 5.5 2ce60280c3 feat(export): contract-conformant event_logs event_time and is_active
Reanimator contract v2.13 makes event_logs[].event_time optional
(Reanimator falls back to collection/ingest time) and defines is_active
("still active / not cleared").

- Omit event_time when the event has no source time instead of passing
  collected_at off as the event time.
- is_active=true only from an authoritative active-alarm snapshot: Inspur
  dev_status.log (IDL event ID / SEL sensor at the same instant) and
  component.log fan state (new models.Event.Active). false for Deasserts,
  superseded Asserts in a real Assert/Deassert lifecycle and Inspur
  Warning/Critical Asserts missing from dev_status.log; unset otherwise.
  A missing Deassert is not treated as active: AC loss and BMC resets drop
  them (24C319575: PSU1 predictive failure).
- component.log fan events use source BMC instead of host.
- Request installed_at in the Reanimator contract to date component
  installs from maintenance.log; follow-up in BACKLOG [installed_at].

ADL-072.

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

51 lines
2.4 KiB
Go

package exporter
import (
"testing"
"time"
"git.mchus.pro/mchus/logpile/internal/models"
)
func TestConvertEventLogs_UndatedEventHasNoEventTime(t *testing.T) {
logs := convertEventLogs([]models.Event{{Source: "BMC", Description: "FAN3 reports Critical"}})
if len(logs) != 1 {
t.Fatalf("expected 1 log, got %d", len(logs))
}
if logs[0].EventTime != "" {
t.Fatalf("event without source time must not get collection time, got %q", logs[0].EventTime)
}
}
func TestConvertEventLogs_IsActive(t *testing.T) {
t0 := time.Date(2026, 8, 12, 10, 0, 0, 0, time.UTC)
yes := true
events := []models.Event{
// 0..2: condition with lifecycle, latest Assert still open.
{Timestamp: t0, Source: "BMC", SensorType: "memory", SensorName: "CPU0_C2D1", ID: "0C090401", EventType: "Assert", Description: "disabled"},
{Timestamp: t0.Add(time.Minute), Source: "BMC", SensorType: "memory", SensorName: "CPU0_C2D1", ID: "0C090401", EventType: "Deassert", Description: "disabled"},
{Timestamp: t0.Add(2 * time.Minute), Source: "BMC", SensorType: "memory", SensorName: "CPU0_C2D1", ID: "0C090401", EventType: "Assert", Description: "disabled"},
// 3: one-shot Assert without lifecycle.
{Timestamp: t0, Source: "BMC", SensorType: "sys restart", SensorName: "SYS RESTART", ID: "1D020000", EventType: "Assert", Description: "restart"},
// 4: explicit snapshot state.
{Source: "BMC", SensorType: "fan", SensorName: "FAN3", EventType: "Fan Status", Description: "FAN3 reports Critical", Active: &yes},
// 5: SEL-style record: condition in EventType, phase in RawData.
{Timestamp: t0, Source: "SEL", SensorType: "power supply", SensorName: "PSU0_Status", ID: "10", EventType: "Predictive failure", RawData: "Asserted", Description: "Predictive failure"},
{Timestamp: t0.Add(time.Minute), Source: "SEL", SensorType: "power supply", SensorName: "PSU0_Status", ID: "15", EventType: "Predictive failure", RawData: "Deasserted", Description: "Predictive failure"},
}
logs := convertEventLogs(events)
want := []*bool{ptrBool(false), ptrBool(false), nil, nil, ptrBool(true), ptrBool(false), ptrBool(false)}
for i, w := range want {
got := logs[i].IsActive
switch {
case w == nil && got != nil:
t.Fatalf("log %d: expected is_active unset, got %v", i, *got)
case w != nil && (got == nil || *got != *w):
t.Fatalf("log %d: expected is_active=%v, got %v", i, *w, got)
}
}
}
func ptrBool(v bool) *bool { return &v }