Skip to content

Commit

Permalink
fix(sel-events): ignore parse time error
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Aleksandrov <aleks.aleksandrov@corp.mail.ru>
  • Loading branch information
Aleksandr Aleksandrov committed Jul 1, 2024
1 parent 6e4076e commit 43887d4
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions collector_sel_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

const (
SELEventsCollectorName CollectorName = "sel-events"
SELDateTimeFormat string = "Jan-02-2006 15:04:05"
)

var (
Expand Down Expand Up @@ -92,12 +93,20 @@ func (c SELEventsCollector) Collect(result freeipmi.Result, ch chan<- prometheus
for _, metricConfig := range selEventConfigs {
match := metricConfig.Regex.FindStringSubmatch(data.Event)
if match != nil {
t, err := time.Parse("Jan-02-2006 15:04:05", data.Date+" "+data.Time)
var newTimestamp float64 = 0
datetime := data.Date + " " + data.Time
t, err := time.Parse(SELDateTimeFormat, datetime)
// ignore errors with invalid date or time
// NOTE: in some cases ipmi-sel can return "PostInit" in Date and Time fields
// Example:
// $ ipmi-sel --comma-separated-output --output-event-state --interpret-oem-data --output-oem-event-strings
// ID,Date,Time,Name,Type,State,Event
// 3,PostInit,PostInit,Sensor #211,Memory,Warning,Correctable memory error ; Event Data3 = 34h
if err != nil {
level.Error(logger).Log("msg", "Failed to collect SEL event metrics", "target", targetName(target.host), "error", err)
return 0, err
level.Debug(logger).Log("msg", "Failed to parse time", "target", targetName(target.host), "error", err)
} else {
newTimestamp = float64(t.Unix())
}
newTimestamp := float64(t.Unix())
// save latest timestamp by name metrics
if newTimestamp > selEventByNameTimestamp[metricConfig.Name] {
selEventByNameTimestamp[metricConfig.Name] = newTimestamp
Expand Down

0 comments on commit 43887d4

Please sign in to comment.