From 3fa6a4df5e553d6a95746f36003aced74cb3d628 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 (cherry picked from commit 2a9c2178d51721be310bf39ae71112d85a87272c) --- 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 4aa2977a8c47..7d21599193a9 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -109,6 +109,7 @@ https://github.com/elastic/beats/compare/v6.5.0...6.x[Check the HEAD diff] - Test etcd module with etcd 3.3. {pull}9068[9068] - Add setting to disable docker cpu metrics per core. {pull}9194[9194] - The `elasticsearch/node` metricset now reports the Elasticsearch cluster UUID. {pull}8771[8771] +- 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 337e2dc47b40..c8829ad7f894 100644 --- a/libbeat/docs/processors-using.asciidoc +++ b/libbeat/docs/processors-using.asciidoc @@ -917,7 +917,8 @@ The fields added to the event are looking as following: "family":"darwin", "build":"16G1212", "platform":"darwin", - "version":"10.12.6" + "version":"10.12.6", + "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 9eba33922b69..a65dfe4e6fac 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, }, }, } @@ -72,6 +73,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) if info.OS.Codename != "" { monitoring.ReportString(V, "codename", 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 a80ae4089ac6..1c578065c0d8 100644 --- a/libbeat/processors/add_host_metadata/add_host_metadata_test.go +++ b/libbeat/processors/add_host_metadata/add_host_metadata_test.go @@ -51,6 +51,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) @@ -84,6 +88,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)