diff --git a/bmc-log-collector/log-collector.go b/bmc-log-collector/log-collector.go index 37fe41ede..0021fcb57 100644 --- a/bmc-log-collector/log-collector.go +++ b/bmc-log-collector/log-collector.go @@ -54,8 +54,6 @@ type selCollector struct { } func (c *selCollector) collectSystemEventLog(ctx context.Context, m Machine, logWriter bmcLogWriter) { - const layout = "2006-01-02T15:04:05Z07:00" - var currentLastId int filePath := path.Join(c.ptrDir, m.Serial) err := checkAndCreatePointerFile(filePath) @@ -89,7 +87,7 @@ func (c *selCollector) collectSystemEventLog(ctx context.Context, m Machine, log err = updateLastPointer(lastPtr, filePath) if err != nil { - slog.Error("failed to write a pointer file.", "err", err, "serial", m.Serial, "currentLastReadId", currentLastId, "ptrDir", c.ptrDir) + slog.Error("failed to write a pointer file.", "err", err, "serial", m.Serial, "ptrDir", c.ptrDir) } return } @@ -103,23 +101,17 @@ func (c *selCollector) collectSystemEventLog(ctx context.Context, m Machine, log return } - createTime, err := time.Parse(layout, response.Sel[len(response.Sel)-1].Create) + createTime, err := time.Parse(time.RFC3339, response.Sel[len(response.Sel)-1].Create) if err != nil { - slog.Error("failed to parse for time", "err", err, "serial", m.Serial, "currentLastReadId", currentLastId, "ptrDir", c.ptrDir) + slog.Error("failed to parse for time", "err", err, "serial", m.Serial) return } - FirstCreateTime := createTime.Unix() + firstCreateTime := createTime.Unix() for i := len(response.Sel) - 1; i >= 0; i-- { - t, err := time.Parse(layout, response.Sel[i].Create) + currentId, err := strconv.Atoi(response.Sel[i].Id) if err != nil { - slog.Error("failed to time parse", "err", err, "serial", m.Serial, "LastReadId", currentLastId, "ptrDir", c.ptrDir) - continue - } - currentCreateUnixtime := t.Unix() - currentLastId, err = strconv.Atoi(response.Sel[i].Id) - if err != nil { - slog.Error("failed to strconv", "err", err, "serial", m.Serial, "LastReadId", currentLastId, "ptrDir", c.ptrDir) + slog.Error("failed to strconv", "err", err, "serial", m.Serial, "LastReadId", currentId, "ptrDir", c.ptrDir) continue } // Add the information to identify of the node @@ -127,46 +119,43 @@ func (c *selCollector) collectSystemEventLog(ctx context.Context, m Machine, log response.Sel[i].BmcIP = m.BmcIP response.Sel[i].NodeIP = m.NodeIP - if lastPtr.LastReadId < currentLastId { + if lastPtr.LastReadId < currentId { bmcByteJsonLog, err := json.Marshal(response.Sel[i]) if err != nil { - slog.Error("failed to marshal the system event log", "err", err, "serial", m.Serial, "lastPtr.LastReadId", lastPtr.LastReadId, "currentLastReadId", currentLastId, "ptrDir", c.ptrDir) + slog.Error("failed to marshal the system event log", "err", err, "serial", m.Serial, "lastPtr.LastReadId", lastPtr.LastReadId, "currentLastReadId", currentId, "ptrDir", c.ptrDir) } err = logWriter.write(string(bmcByteJsonLog), m.Serial) if err != nil { - slog.Error("failed to output log", "err", err, "serial", m.Serial, "bmcByteJsonLog", string(bmcByteJsonLog), "currentLastReadId", currentLastId, "ptrDir", c.ptrDir) + slog.Error("failed to output log", "err", err, "serial", m.Serial, "bmcByteJsonLog", string(bmcByteJsonLog), "currentLastReadId", currentId, "ptrDir", c.ptrDir) } - lastPtr.LastReadId = currentLastId - lastPtr.LastReadTime = currentCreateUnixtime + lastPtr.LastReadId = currentId + lastPtr.LastReadTime = firstCreateTime lastPtr.LastError = nil - if currentLastId == 1 { - lastPtr.FirstCreateTime = currentCreateUnixtime - } } else { // If the log is reset in iDRAC, the ID starts from 1. // In that case, determine if generated time been changed to identify log reseted. - if lastPtr.FirstCreateTime != FirstCreateTime { + if lastPtr.FirstCreateTime != firstCreateTime { bmcByteJsonLog, err := json.Marshal(response.Sel[i]) if err != nil { - slog.Error("failed to convert JSON", "err", err, "serial", m.Serial, "i", i, "Event", response.Sel[i], "currentLastReadId", currentLastId) + slog.Error("failed to convert JSON", "err", err, "serial", m.Serial, "i", i, "Event", response.Sel[i], "currentLastReadId", currentId) } err = logWriter.write(string(bmcByteJsonLog), m.Serial) if err != nil { - slog.Error("failed to output log", "err", err, "serial", m.Serial, "bmcByteJsonLog", string(bmcByteJsonLog), "currentLastReadId", currentLastId) + slog.Error("failed to output log", "err", err, "serial", m.Serial, "bmcByteJsonLog", string(bmcByteJsonLog), "currentLastReadId", currentId) } - lastPtr.LastReadId = currentLastId - lastPtr.LastReadTime = currentCreateUnixtime + lastPtr.LastReadId = currentId + lastPtr.LastReadTime = firstCreateTime lastPtr.LastError = nil } } } - lastPtr.FirstCreateTime = FirstCreateTime + lastPtr.FirstCreateTime = firstCreateTime err = updateLastPointer(lastPtr, filePath) if err != nil { - slog.Error("failed to write a pointer file.", "err", err, "serial", m.Serial, "FirstCreateTime", FirstCreateTime, "filePath", filePath) + slog.Error("failed to write a pointer file.", "err", err, "serial", m.Serial, "firstCreateTime", firstCreateTime, "filePath", filePath) return } }