package inspurlegacy import ( "sort" "strings" "time" "git.mchus.pro/mchus/logpile/internal/models" ) // bogusYear reports whether a timestamp comes from an AMI BMC clock that had // not yet been set: the 1970/1971 epoch, or the ~2005 firmware-default RTC seen // in alert.log. This hardware shipped no earlier than 2018, so any event before // 2010 has no trustworthy wall-clock time. func bogusYear(t time.Time) bool { return t.Year() < 2010 } // severityFromWord maps a free-text severity/class word to models.Severity. func severityFromWord(s string) models.Severity { switch strings.ToLower(strings.TrimSpace(s)) { case "critical", "error", "fatal", "serious", "nonrecoverable", "non-recoverable": return models.SeverityCritical case "warning", "warn", "predictive": return models.SeverityWarning default: return models.SeverityInfo } } // dedupeEvents removes exact duplicates (same timestamp, source, description) // in place, preserving order. The same fault is often reported by both the IDL // log and sel.log. func dedupeEvents(events []models.Event) []models.Event { seen := make(map[string]struct{}, len(events)) out := events[:0] for _, e := range events { key := e.Timestamp.Format(time.RFC3339) + "|" + e.Source + "|" + e.SensorName + "|" + e.Description if _, ok := seen[key]; ok { continue } seen[key] = struct{}{} out = append(out, e) } return out } // sortEvents orders events chronologically, then by source for stability. func sortEvents(events []models.Event) { sort.SliceStable(events, func(i, j int) bool { if !events[i].Timestamp.Equal(events[j].Timestamp) { return events[i].Timestamp.Before(events[j].Timestamp) } return events[i].Source < events[j].Source }) }