Skip to content

[Auditbeat] Host: Fill top-level host fields #12259

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

Merged
merged 5 commits into from
May 28, 2019
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 @@ -170,6 +170,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add support to the system package dataset for the SUSE OS family. {pull}11634[11634]
- Process: Add file hash of process executable. {pull}11722[11722]
- Socket: Add network.transport and network.community_id. {pull}12231[12231]
- Host: Fill top-level host fields. {pull}12259[12259]

*Filebeat*

Expand Down
10 changes: 10 additions & 0 deletions auditbeat/docs/fields.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -6838,6 +6838,16 @@ IP addresses.



*`system.audit.host.os.codename`*::
+
--
type: keyword

OS codename, if any (e.g. stretch).


--

*`system.audit.host.os.platform`*::
+
--
Expand Down
2 changes: 1 addition & 1 deletion x-pack/auditbeat/module/system/fields.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions x-pack/auditbeat/module/system/host/_meta/fields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@
description: >
`os` contains information about the operating system.
fields:
- name: codename
type: keyword
description: >
OS codename, if any (e.g. stretch).
- name: platform
type: keyword
description: >
Expand Down
31 changes: 28 additions & 3 deletions x-pack/auditbeat/module/system/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ func (host *Host) toMapStr() common.MapStr {
mapstr.Put("containerized", host.info.Containerized)
}

if host.info.OS.Codename != "" {
mapstr.Put("os.codename", host.info.OS.Codename)
}

var ipStrings []string
for _, ip := range host.ips {
ipStrings = append(ipStrings, ip.String())
Expand Down Expand Up @@ -311,16 +315,37 @@ func getHost() (*Host, error) {
}

func hostEvent(host *Host, eventType string, action eventAction) mb.Event {
return mb.Event{
hostFields := host.toMapStr()

event := mb.Event{
RootFields: common.MapStr{
"event": common.MapStr{
"kind": eventType,
"action": action.String(),
},
"message": hostMessage(host, action),
},
MetricSetFields: host.toMapStr(),
}
MetricSetFields: hostFields,
Copy link
Member

Choose a reason for hiding this comment

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

If it weren't a breaking change I'd suggest not duplicating values between host.* and system.host.*.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed

}

// Copy select host.* fields in case add_host_metadata is not configured.
hostTopLevel := common.MapStr{}
hostFields.CopyFieldsTo(hostTopLevel, "architecture")
hostFields.CopyFieldsTo(hostTopLevel, "containerized")
hostFields.CopyFieldsTo(hostTopLevel, "hostname")
hostFields.CopyFieldsTo(hostTopLevel, "id")
hostFields.CopyFieldsTo(hostTopLevel, "ip")
hostFields.CopyFieldsTo(hostTopLevel, "mac")
hostFields.CopyFieldsTo(hostTopLevel, "os.codename")
hostFields.CopyFieldsTo(hostTopLevel, "os.family")
hostFields.CopyFieldsTo(hostTopLevel, "os.kernel")
hostFields.CopyFieldsTo(hostTopLevel, "os.name")
hostFields.CopyFieldsTo(hostTopLevel, "os.platform")
hostFields.CopyFieldsTo(hostTopLevel, "os.version")

event.RootFields.Put("host", hostTopLevel)

return event
}

func hostMessage(host *Host, action eventAction) string {
Expand Down
7 changes: 4 additions & 3 deletions x-pack/auditbeat/tests/system/test_metricsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ def test_metricset_host(self):
host metricset collects general information about a server.
"""

fields = ["system.audit.host.id", "system.audit.host.uptime", "system.audit.host.ip",
fields = ["host.name", "host.architecture", "host.hostname", "host.id", "host.ip", "host.mac",
"host.os.family", "host.os.kernel", "host.os.name", "host.os.platform", "host.os.version",
"system.audit.host.id", "system.audit.host.uptime", "system.audit.host.ip",
"system.audit.host.os.name"]

# Metricset is beta and that generates a warning, TODO: remove later
self.check_metricset("system", "host", COMMON_FIELDS + fields, warnings_allowed=True)
self.check_metricset("system", "host", COMMON_FIELDS + fields)

@unittest.skipUnless(sys.platform == "linux2", "Only implemented for Linux")
@unittest.skipIf(sys.byteorder != "little", "Test only implemented for little-endian systems")
Expand Down