Older AMI-BMC Inspur onekeylog archives (NF5466M5 / NF5280M5 generation)
opened to an empty result: they carry none of the files the inspur parser
keys on (no asset.json, devicefrusdr.log, selelist.csv or component.log).
New package internal/parser/vendors/inspur_legacy (vendor id inspur_legacy),
separate from inspur:
- binary IPMI FRU decode (FRU.bin) -> board identity
- Inspur_AssetInfoInventory.log -> CPU / memory / PCIe / PSU inventory
- events from Inspur_<model>_<serial>_IDL, sel.log, blackbox.log,
MegaRAID raid0.log, and the flat AMI <severity>.log files
- no live sensors in this archive class -> recorded as a collection error
- BMC clock timestamps before 2010 dropped as un-set (1970 / ~2005 RTC)
Registry: add optional PrioritizedParser { DetectPriority() int } so a
confidence tie is broken by specificity. inspur_legacy returns 10 and also
declines (Detect 0) when modern Kaytus markers are present, so the two
Inspur parsers never fight over a newer dump.
Docs: ADL-065, 06-parsers.md, releases/v1.32.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017VL8wLGD6Lnp6hZCpqT6cZ
63 lines
1.7 KiB
Go
63 lines
1.7 KiB
Go
package parser
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.mchus.pro/mchus/logpile/internal/models"
|
|
)
|
|
|
|
type stubParser struct {
|
|
name string
|
|
vendor string
|
|
confidence int
|
|
priority int
|
|
hasPrio bool
|
|
}
|
|
|
|
func (s stubParser) Name() string { return s.name }
|
|
func (s stubParser) Vendor() string { return s.vendor }
|
|
func (s stubParser) Version() string { return "1.0" }
|
|
func (s stubParser) Detect([]ExtractedFile) int {
|
|
return s.confidence
|
|
}
|
|
func (s stubParser) Parse([]ExtractedFile) (*models.AnalysisResult, error) {
|
|
return &models.AnalysisResult{}, nil
|
|
}
|
|
|
|
type stubPrioParser struct{ stubParser }
|
|
|
|
func (s stubPrioParser) DetectPriority() int { return s.priority }
|
|
|
|
func TestDetectFormat_PriorityBreaksConfidenceTie(t *testing.T) {
|
|
broad := stubParser{name: "broad", vendor: "test_broad", confidence: 100}
|
|
specific := stubPrioParser{stubParser{name: "specific", vendor: "test_specific", confidence: 100}}
|
|
specific.priority = 10
|
|
|
|
saved := registry
|
|
registry = map[string]VendorParser{"a": broad, "b": specific}
|
|
defer func() { registry = saved }()
|
|
|
|
got, err := DetectFormat(nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.Name() != "specific" {
|
|
t.Fatalf("chosen %q, want the higher-priority parser on a confidence tie", got.Name())
|
|
}
|
|
}
|
|
|
|
func TestDetectFormat_HigherConfidenceStillWinsOverPriority(t *testing.T) {
|
|
broad := stubParser{name: "broad", vendor: "test_broad", confidence: 100}
|
|
specific := stubPrioParser{stubParser{name: "specific", vendor: "test_specific", confidence: 40}}
|
|
specific.priority = 10
|
|
|
|
saved := registry
|
|
registry = map[string]VendorParser{"a": broad, "b": specific}
|
|
defer func() { registry = saved }()
|
|
|
|
got, _ := DetectFormat(nil)
|
|
if got.Name() != "broad" {
|
|
t.Fatalf("chosen %q, want higher-confidence parser", got.Name())
|
|
}
|
|
}
|