-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get systemeventlog #376
Get systemeventlog #376
Changes from all commits
34de741
3469c21
d73562b
ebab84a
de61fa1
f7408e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM mcr.microsoft.com/devcontainers/go:1-1.21-bullseye | ||
RUN apt update | ||
RUN apt install ipmitool -y | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -383,3 +383,47 @@ func (i *Ipmi) ClearSystemEventLog(ctx context.Context) (err error) { | |
_, err = i.run(ctx, []string{"sel", "clear"}) | ||
return err | ||
} | ||
|
||
// GetSystemEventLog returns the system event log entries in ID, Timestamp, Description, Message format | ||
func (i *Ipmi) GetSystemEventLog(ctx context.Context) (entries [][]string, err error) { | ||
output, err := i.GetSystemEventLogRaw(ctx) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "error getting system event log") | ||
} | ||
|
||
entries = parseSystemEventLog(output) | ||
|
||
return entries, nil | ||
} | ||
|
||
// parseSystemEventLogRaw parses the raw output of the system event log. Helper | ||
// function for GetSystemEventLog to make testing the parser easier. | ||
func parseSystemEventLog(raw string) (entries [][]string) { | ||
scanner := bufio.NewScanner(strings.NewReader(raw)) | ||
for scanner.Scan() { | ||
line := strings.Split(scanner.Text(), "|") | ||
if len(line) < 6 { | ||
continue | ||
} | ||
if line[0] == "ID" { | ||
continue | ||
} | ||
for i := range line { | ||
line[i] = strings.TrimSpace(line[i]) | ||
} | ||
// ID, Timestamp (date time), Description, Message (message : assertion) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you include some fixture data for this, along with a test for the parsing (move this scanner block into another method if that makes it easier to test) |
||
entries = append(entries, []string{line[0], fmt.Sprintf("%s %s", line[1], line[2]), line[3], fmt.Sprintf("%s : %s", line[4], line[5])}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this references elems in the slice |
||
} | ||
|
||
return entries | ||
} | ||
|
||
// GetSystemEventLogRaw returns the raw SEL output | ||
func (i *Ipmi) GetSystemEventLogRaw(ctx context.Context) (eventlog string, err error) { | ||
output, err := i.run(ctx, []string{"sel", "list"}) | ||
if err != nil { | ||
return "", errors.Wrap(err, "error getting system event log") | ||
} | ||
|
||
return output, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Include tracing here, for an example, see -
bmclib/client.go
Line 377 in 764ac9e