Skip to content
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

[Auditbeat][System] Fix error handling around go-sysinfo.Host #17569

Merged
merged 1 commit into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d

- system/socket: Fixed compatibility issue with kernel 5.x. {pull}15771[15771]
- system/package: Fix parsing of Installed-Size field of DEB packages. {issue}16661[16661] {pull}17188[17188]
- system module: Fix panic during initialisation when /proc/stat can't be read. {pull}17569[17569]

*Filebeat*

Expand Down
9 changes: 5 additions & 4 deletions x-pack/auditbeat/module/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,20 @@ func NewModule(base mb.BaseModule) (mb.Module, error) {
log := logp.NewLogger(moduleName)

var hostID string
hostInfo, err := sysinfo.Host()
if hostInfo != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was going on in here is when sysinfo.Host() errors, it returns a non-nil interface that wraps a nil pointer, causing the nil check to pass but a panic inside the hostInfo.Info() call below.

if hostInfo, err := sysinfo.Host(); err != nil {
log.Errorf("Could not get host info. err=%+v", err)
} else {
hostID = hostInfo.Info().UniqueID
}

if hostID == "" {
log.Warnf("Could not get host ID, will not fill entity_id fields. Error: %+v", err)
log.Warnf("Could not get host ID, will not fill entity_id fields.")
}

return &SystemModule{
BaseModule: base,
config: config,
hostID: hostInfo.Info().UniqueID,
hostID: hostID,
}, nil
}

Expand Down