From 2a9c2178d51721be310bf39ae71112d85a87272c Mon Sep 17 00:00:00 2001 From: kaiyan-sheng Date: Fri, 7 Dec 2018 13:54:37 -0700 Subject: [PATCH] Add OS Name into add-host-metadata (#9405) * Add OS Name into add-host-metadat * Run gofmt * Add changelog and update documentation * Update changelog --- CHANGELOG.asciidoc | 1 + libbeat/docs/processors-using.asciidoc | 3 ++- libbeat/metric/system/host/host.go | 2 ++ .../add_host_metadata/add_host_metadata_test.go | 8 ++++++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 5ab427f7247b..12959bb51470 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -95,6 +95,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha1...master[Check the HEAD d - The `elasticsearch/node` metricset now reports the Elasticsearch cluster UUID. {pull}8771[8771] - Add service.type field to Metricbeat. {pull}8965[8965] - Support GET requests in Jolokia module. {issue}8566[8566] {pull}9226[9226] +- Add `host.os.name` field to add_host_metadata processor. {issue}8948[8948] {pull}9405[9405] *Packetbeat* diff --git a/libbeat/docs/processors-using.asciidoc b/libbeat/docs/processors-using.asciidoc index 449b9d3b22a6..f4db598e2961 100644 --- a/libbeat/docs/processors-using.asciidoc +++ b/libbeat/docs/processors-using.asciidoc @@ -918,7 +918,8 @@ The fields added to the event are looking as following: "build":"16G1212", "platform":"darwin", "version":"10.12.6", - "kernel":"16.7.0" + "kernel":"16.7.0", + "name":"Mac OS X" }, "ip": ["192.168.0.1", "10.0.0.1"], "mac": ["00:25:96:12:34:56", "72:00:06:ff:79:f1"] diff --git a/libbeat/metric/system/host/host.go b/libbeat/metric/system/host/host.go index fb2a5e246ac0..8589ef5a5a09 100644 --- a/libbeat/metric/system/host/host.go +++ b/libbeat/metric/system/host/host.go @@ -34,6 +34,7 @@ func MapHostInfo(info types.HostInfo) common.MapStr { "platform": info.OS.Platform, "version": info.OS.Version, "family": info.OS.Family, + "name": info.OS.Name, "kernel": info.KernelVersion, }, }, @@ -73,6 +74,7 @@ func ReportInfo(_ monitoring.Mode, V monitoring.Visitor) { monitoring.ReportString(V, "platform", info.OS.Platform) monitoring.ReportString(V, "version", info.OS.Version) monitoring.ReportString(V, "family", info.OS.Family) + monitoring.ReportString(V, "name", info.OS.Name) monitoring.ReportString(V, "kernel", info.KernelVersion) if info.OS.Codename != "" { diff --git a/libbeat/processors/add_host_metadata/add_host_metadata_test.go b/libbeat/processors/add_host_metadata/add_host_metadata_test.go index 3f6c9a266444..d67fb26bc233 100644 --- a/libbeat/processors/add_host_metadata/add_host_metadata_test.go +++ b/libbeat/processors/add_host_metadata/add_host_metadata_test.go @@ -57,6 +57,10 @@ func TestConfigDefault(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, v) + v, err = newEvent.GetValue("host.os.name") + assert.NoError(t, err) + assert.NotNil(t, v) + v, err = newEvent.GetValue("host.ip") assert.Error(t, err) assert.Nil(t, v) @@ -96,6 +100,10 @@ func TestConfigNetInfoEnabled(t *testing.T) { assert.NoError(t, err) assert.NotNil(t, v) + v, err = newEvent.GetValue("host.os.name") + assert.NoError(t, err) + assert.NotNil(t, v) + v, err = newEvent.GetValue("host.ip") assert.NoError(t, err) assert.NotNil(t, v)