From 3a69f5c438afcecc39c6c47c82fb592b4a24e89b Mon Sep 17 00:00:00 2001 From: Adrian Serrano Date: Tue, 7 Apr 2020 13:16:01 +0200 Subject: [PATCH] [Auditbeat][System] Fix error handling around go-sysinfo.Host 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. --- CHANGELOG.next.asciidoc | 1 + x-pack/auditbeat/module/system/system.go | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 49a2efa181e..b58850dbea3 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -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* diff --git a/x-pack/auditbeat/module/system/system.go b/x-pack/auditbeat/module/system/system.go index 72a1abca221..dea55bffdfc 100644 --- a/x-pack/auditbeat/module/system/system.go +++ b/x-pack/auditbeat/module/system/system.go @@ -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 }