Skip to content

Commit

Permalink
[Auditbeat][System] Fix error handling around go-sysinfo.Host (#17569) (
Browse files Browse the repository at this point in the history
#17603)

Before a system dataset is loaded, host information is loaded to
populate `entity_id` fields.

Error handling around it was incorrect and resulted in a panic when
fetching host info failed, which afaik it's limited to errors accessing
/proc/stat file.

(cherry picked from commit 97750c8)
  • Loading branch information
adriansr committed Apr 9, 2020
1 parent 6e585f4 commit 4fb9fad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,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 {
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

0 comments on commit 4fb9fad

Please sign in to comment.