sync file-type support across upload/convert and fix collected_at timezone handling
This commit is contained in:
42
internal/parser/vendors/inspur/parser.go
vendored
42
internal/parser/vendors/inspur/parser.go
vendored
@@ -8,6 +8,7 @@ package inspur
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.mchus.pro/mchus/logpile/internal/models"
|
||||
"git.mchus.pro/mchus/logpile/internal/parser"
|
||||
@@ -86,6 +87,8 @@ func containsInspurMarkers(content []byte) bool {
|
||||
|
||||
// Parse parses Inspur/Kaytus archive
|
||||
func (p *Parser) Parse(files []parser.ExtractedFile) (*models.AnalysisResult, error) {
|
||||
selLocation := inferInspurArchiveLocation(files)
|
||||
|
||||
result := &models.AnalysisResult{
|
||||
Events: make([]models.Event, 0),
|
||||
FRU: make([]models.FRUInfo, 0),
|
||||
@@ -145,7 +148,7 @@ func (p *Parser) Parse(files []parser.ExtractedFile) (*models.AnalysisResult, er
|
||||
|
||||
// Parse SEL list (selelist.csv)
|
||||
if f := parser.FindFileByName(files, "selelist.csv"); f != nil {
|
||||
selEvents := ParseSELList(f.Content)
|
||||
selEvents := ParseSELListWithLocation(f.Content, selLocation)
|
||||
result.Events = append(result.Events, selEvents...)
|
||||
}
|
||||
|
||||
@@ -184,6 +187,43 @@ func (p *Parser) Parse(files []parser.ExtractedFile) (*models.AnalysisResult, er
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func inferInspurArchiveLocation(files []parser.ExtractedFile) *time.Location {
|
||||
fallback := parser.DefaultArchiveLocation()
|
||||
f := parser.FindFileByName(files, "timezone.conf")
|
||||
if f == nil {
|
||||
return fallback
|
||||
}
|
||||
locName := parseTimezoneConfigLocation(f.Content)
|
||||
if strings.TrimSpace(locName) == "" {
|
||||
return fallback
|
||||
}
|
||||
loc, err := time.LoadLocation(locName)
|
||||
if err != nil {
|
||||
return fallback
|
||||
}
|
||||
return loc
|
||||
}
|
||||
|
||||
func parseTimezoneConfigLocation(content []byte) string {
|
||||
lines := strings.Split(string(content), "\n")
|
||||
for _, line := range lines {
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" || strings.HasPrefix(line, "[") || strings.HasPrefix(line, "#") || strings.HasPrefix(line, ";") {
|
||||
continue
|
||||
}
|
||||
parts := strings.SplitN(line, "=", 2)
|
||||
if len(parts) != 2 {
|
||||
continue
|
||||
}
|
||||
key := strings.ToLower(strings.TrimSpace(parts[0]))
|
||||
val := strings.TrimSpace(parts[1])
|
||||
if key == "timezone" && val != "" {
|
||||
return val
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (p *Parser) parseDeviceFruSDR(content []byte, result *models.AnalysisResult) {
|
||||
lines := string(content)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user