Add XigmaNAS log parser and tests

This commit is contained in:
2026-02-04 22:14:14 +03:00
parent f9230e12f3
commit b64a8d8709
3 changed files with 532 additions and 0 deletions

View File

@@ -0,0 +1,94 @@
package xigmanas
import (
"os"
"path/filepath"
"strings"
"testing"
"git.mchus.pro/mchus/logpile/internal/parser"
)
func TestParserDetect(t *testing.T) {
p := &Parser{}
files := []parser.ExtractedFile{
{
Path: "xigmanas",
Content: []byte(`Version:
--------
14.3.0.5
loader_brand="XigmaNAS"`),
},
}
if got := p.Detect(files); got < 70 {
t.Fatalf("expected high confidence, got %d", got)
}
files2 := []parser.ExtractedFile{
{
Path: "random_file.txt",
Content: []byte("Some random content"),
},
}
if got := p.Detect(files2); got != 0 {
t.Fatalf("expected zero confidence, got %d", got)
}
}
func TestParserParseExample(t *testing.T) {
p := &Parser{}
examplePath := filepath.Join("..", "..", "..", "..", "example", "xigmanas.txt")
raw, err := os.ReadFile(examplePath)
if err != nil {
t.Fatalf("read example file: %v", err)
}
files := []parser.ExtractedFile{
{Path: "xigmanas", Content: raw},
}
result, err := p.Parse(files)
if err != nil {
t.Fatalf("parse failed: %v", err)
}
if result == nil || result.Hardware == nil {
t.Fatal("expected non-nil result with hardware")
}
if len(result.Hardware.Firmware) == 0 {
t.Fatal("expected firmware data")
}
foundXigmaVersion := false
for _, fw := range result.Hardware.Firmware {
if fw.DeviceName == "XigmaNAS" && fw.Version == "14.3.0.5" {
foundXigmaVersion = true
}
}
if !foundXigmaVersion {
t.Fatalf("expected XigmaNAS firmware version 14.3.0.5, got %+v", result.Hardware.Firmware)
}
if result.Hardware.BoardInfo.Manufacturer != "HP" {
t.Fatalf("expected board manufacturer HP, got %q", result.Hardware.BoardInfo.Manufacturer)
}
if len(result.Hardware.CPUs) == 0 {
t.Fatal("expected at least one CPU")
}
if !strings.Contains(strings.ToLower(result.Hardware.CPUs[0].Model), "athlon") {
t.Fatalf("expected CPU model to contain athlon, got %q", result.Hardware.CPUs[0].Model)
}
if len(result.Hardware.Storage) < 4 {
t.Fatalf("expected at least 4 storage devices, got %d", len(result.Hardware.Storage))
}
if len(result.Sensors) == 0 {
t.Fatal("expected SMART temperature sensors")
}
if len(result.Events) == 0 {
t.Fatal("expected events from uptime/zfs sections")
}
}