Files
logpile/internal/parser/vendors/inspur/idl.go
T
Mikhail ChusavitinandClaude Opus 5.5 f2ad0aca96 fix: never use parse time as event or collection time
Dump data is always historical. Parsers stamped undated events with
time.Now() (Inspur component.log memory/fan status, IDL/H3C SEL with
unparsable time, NVIDIA summary/bug-report, generic, XigmaNAS, Unraid,
Redfish replay warnings), so an August dump opened in September showed
DIMM warnings dated the day of analysis.

- Events without a source time keep a zero timestamp.
- Yearless syslog timestamps take the year from the collection time via
  parser.ParseYearlessInDefaultArchiveLocation; zero when unknown.
- Archive/uploaded-snapshot collected_at is no longer defaulted to now;
  only live API collection uses the current time.

ADL-070.

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

129 lines
3.5 KiB
Go

package inspur
import (
"regexp"
"strings"
"time"
"git.mchus.pro/mchus/logpile/internal/models"
)
// ParseIDLLog parses IDL-style entries for BMC alarms.
// Works for both plain idl.log lines and JSON structured logs (idl_json/run_json)
// where MESSAGE/LOG2_FMTMSG contains:
// |timestamp|component|type|severity|eventID|description|
func ParseIDLLog(content []byte) []models.Event {
var events []models.Event
// Pattern to match CommerDiagnose log entries
// Example: |2025-12-02T17:54:27+08:00|MEMORY|Assert|Warning|0C180401|CPU1_C4D0 Memory Device Disabled...|
re := regexp.MustCompile(`\|(\d{4}-\d{2}-\d{2}T[\d:]+[+-]\d{2}:\d{2})\|([^|]+)\|([^|]+)\|([^|]+)\|([^|]+)\|([^|]+)\|`)
lines := strings.Split(string(content), "\n")
seenEvents := make(map[string]bool) // Deduplicate events
for _, line := range lines {
matches := re.FindStringSubmatch(line)
if matches == nil {
continue
}
timestamp := matches[1]
component := matches[2]
eventType := matches[3]
severityStr := matches[4]
eventID := matches[5]
description := matches[6]
// Parse timestamp
ts, err := time.Parse("2006-01-02T15:04:05-07:00", timestamp)
if err != nil {
ts = time.Time{}
}
// Map severity
severity := mapIDLSeverity(severityStr)
if strings.Contains(strings.ToLower(eventType), "deassert") {
severity = models.SeverityInfo
}
// Clean up description
description = cleanDescription(description)
// Create unique key for deduplication. Must include the timestamp:
// recurring alarms (e.g. flapping PCIe presence checks) reuse the same
// eventID/eventType/description on every occurrence, so deduping without
// the timestamp collapses all later occurrences into the first one and
// silently drops the most recent (and most relevant) event.
eventKey := timestamp + "|" + eventID + "|" + eventType + "|" + description
if seenEvents[eventKey] {
continue
}
seenEvents[eventKey] = true
// Extract sensor name from description if available
sensorName := extractSensorName(description, component)
events = append(events, models.Event{
ID: eventID,
Timestamp: ts,
Source: "BMC",
SensorType: strings.ToLower(component),
SensorName: sensorName,
EventType: eventType,
Severity: severity,
Description: description,
})
}
return events
}
func mapIDLSeverity(s string) models.Severity {
switch strings.ToLower(s) {
case "critical", "error":
return models.SeverityCritical
case "warning":
return models.SeverityWarning
default:
return models.SeverityInfo
}
}
func cleanDescription(desc string) string {
// Remove trailing " - Assert" or similar
desc = strings.TrimSuffix(desc, " - Assert")
desc = strings.TrimSuffix(desc, " - Deassert")
desc = strings.TrimSpace(desc)
return desc
}
func extractSensorName(desc, component string) string {
// Try to extract sensor/device name from description
// For memory: CPU1_C4D0, CPU1_C4D1, etc.
if component == "MEMORY" {
re := regexp.MustCompile(`(CPU\d+_C\d+D\d+)`)
if matches := re.FindStringSubmatch(desc); matches != nil {
return matches[1]
}
}
// For PSU: PSU0, PSU1, etc.
if component == "PSU" || component == "POWER" {
re := regexp.MustCompile(`(PSU\d+)`)
if matches := re.FindStringSubmatch(desc); matches != nil {
return matches[1]
}
}
// For temperature sensors
if component == "TEMPERATURE" || component == "THERMAL" {
re := regexp.MustCompile(`(\w+_Temp|\w+_DTS)`)
if matches := re.FindStringSubmatch(desc); matches != nil {
return matches[1]
}
}
return component
}