package inspurlegacy import ( "strings" "time" "git.mchus.pro/mchus/logpile/internal/models" ) // idlTimeLayout is the naive local timestamp used by the legacy IDL log; it // carries no timezone offset. const idlTimeLayout = "2006-01-02T15:04:05" // ParseIDLEvents parses the "Inspur___IDL" event log. Each line // is "timestamp|component|severity|assertion|code|description". func ParseIDLEvents(content []byte) []models.Event { var events []models.Event for _, line := range strings.Split(string(content), "\n") { line = strings.TrimRight(line, "\r ") if line == "" { continue } parts := strings.Split(line, "|") if len(parts) < 6 { continue } ts, err := time.Parse(idlTimeLayout, strings.TrimSpace(parts[0])) if err != nil { continue } component := strings.TrimSpace(parts[1]) severityWord := strings.TrimSpace(parts[2]) assertion := strings.TrimSpace(parts[3]) code := strings.TrimSpace(parts[4]) desc := strings.TrimSpace(strings.Join(parts[5:], "|")) desc = strings.TrimRight(desc, ".") if bogusYear(ts) { // Pre-NTP boot spam with no real wall-clock time. continue } severity := severityFromWord(severityWord) if strings.Contains(strings.ToLower(assertion), "deassert") { severity = models.SeverityInfo } events = append(events, models.Event{ ID: "idl_" + code + "_" + ts.Format("20060102T150405"), Timestamp: ts, Source: "BMC/IDL", SensorType: strings.ToLower(component), SensorName: component, EventType: assertion, Severity: severity, Description: desc, RawData: line, }) } return events }