-
Notifications
You must be signed in to change notification settings - Fork 5k
[Auditbeat] Socket metricset #8834
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
cwurm
merged 38 commits into
elastic:feature-auditbeat-host
from
cwurm:sockets_metricset
Nov 30, 2018
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
5b0d079
Change to xxhash.
04f0189
Add sockets metricset and users info.
be4f900
Error handling
a9f0a27
Add enrichment with RPC services to sockets.
9e3fc9a
Addd diffs to sockets.
9355415
Unify status field values.
e68cc07
Fix import order.
78a3ab6
Roll back changes to connection in socket.go
22e9b72
Remove dublicate import.
3a37b66
Correct sockets config.
956a840
Small fixes.
2e81e6d
data.json for sockets metricset.
1db2569
Fix import order.
096e2e2
Working RPC enrichment.
10466bf
Remove RPC enrichment.
09df2aa
Unit test for sockets.
f94e1bd
System test for sockets.
5013d74
Update fields.yml.
2c1d9e3
Small fixes.
366ca7e
Move user information to separate PR.
f3e978a
Add comments to NetlinkSession.
7a52059
Rename metricset to socket.
8030aa4
Move reused Metricbeat functionality to helper package.
f7005ff
Revert unrelated changes.
611f49a
Metricset factory for non-Linux systems.
abc8a9a
Switch to single documents.
f31813b
Add top-level ECS process information.
6910430
Change to PushMetricSetV2.
e8c1203
Working netlink subscription.
b117a37
Switch back to Fetch metricset.
3a5817c
ECS fields.
1ed02be
Update fields.yml.
627881b
ECS field values for network.direction.
b32fc7a
Be lenient with errors during ptable refresh.
a6884ad
Remove TCP state.
2d0e0db
Change to top-level ECS fields only.
8a98827
Remove bucket, report state every 1 hour.
27b91b9
Back out network.type from fields.ecs.yml and skip in test.
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you under | ||
| // the Apache License, Version 2.0 (the "License"); you may | ||
| // not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| // +build linux | ||
|
|
||
| package socket | ||
|
|
||
| import ( | ||
| "os" | ||
| "sync/atomic" | ||
|
|
||
| "github.com/pkg/errors" | ||
|
|
||
| "github.com/elastic/gosigar/sys/linux" | ||
| ) | ||
|
|
||
| // NetlinkSession communicates with the kernel's netlink subsystem. | ||
| type NetlinkSession struct { | ||
| readBuffer []byte | ||
| seq uint32 | ||
| } | ||
|
|
||
| // NewNetlinkSession creates a new netlink session. | ||
| func NewNetlinkSession() *NetlinkSession { | ||
| return &NetlinkSession{ | ||
| readBuffer: make([]byte, os.Getpagesize()), | ||
| } | ||
| } | ||
|
|
||
| // GetSocketList retrieves the current list of sockets from the kernel. | ||
| func (session *NetlinkSession) GetSocketList() ([]*linux.InetDiagMsg, error) { | ||
| // Send request over netlink and parse responses. | ||
| req := linux.NewInetDiagReq() | ||
| req.Header.Seq = atomic.AddUint32(&session.seq, 1) | ||
| sockets, err := linux.NetlinkInetDiagWithBuf(req, session.readBuffer, nil) | ||
| if err != nil { | ||
| return nil, errors.Wrap(err, "failed requesting socket dump") | ||
| } | ||
| return sockets, nil | ||
| } |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,20 @@ | ||
| {{ if .Reference -}} | ||
| {{ end -}} | ||
| {{ if ne .GOOS "windows" -}} | ||
| - module: system | ||
|
|
||
| metricsets: | ||
| - host | ||
| - packages | ||
| - processes | ||
| {{ if eq .GOOS "linux" -}} | ||
| - socket | ||
| - user | ||
| {{- end }} | ||
|
|
||
| state.period: 12h | ||
|
|
||
| report_changes: true | ||
|
|
||
| {{ if eq .GOOS "darwin" -}} | ||
| {{ else if eq .GOOS "windows" -}} | ||
| {{ else -}} | ||
| {{- end }} | ||
| {{- end }} | ||
| {{ if .Reference }} | ||
| {{- end }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| { | ||
| "@timestamp": "2017-10-12T08:05:34.853Z", | ||
| "agent": { | ||
| "hostname": "host.example.com", | ||
| "name": "host.example.com" | ||
| }, | ||
| "user": { | ||
| "name": "vagrant", | ||
| "id": 1000 | ||
| }, | ||
| "process": { | ||
| "pid": 4021, | ||
| "name": "lynx" | ||
| }, | ||
| "source": { | ||
| "ip": "10.0.2.15", | ||
| "port": 33956 | ||
| }, | ||
| "destination": { | ||
| "port": 443, | ||
| "ip": "52.10.168.186" | ||
| }, | ||
| "event": { | ||
| "type": "event", | ||
| "action": "socket_opened", | ||
| "module": "system", | ||
| "dataset": "socket" | ||
| }, | ||
| "network": { | ||
| "type": "ipv4", | ||
| "direction": "outbound" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| The System `socket` metricset provides ... TODO. | ||
|
|
||
| The module is implemented for Linux only. | ||
|
|
||
| [float] | ||
| === Configuration options | ||
|
|
||
| TODO |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
|
|
||
| package socket | ||
|
|
||
| import ( | ||
| "time" | ||
| ) | ||
|
|
||
| // Config defines the socket metricset's configuration options. | ||
| type Config struct { | ||
| StatePeriod time.Duration `config:"state.period"` | ||
| SocketStatePeriod time.Duration `config:"socket.state.period"` | ||
| } | ||
|
|
||
| // Validate validates the host metricset config. | ||
| func (c *Config) Validate() error { | ||
| return nil | ||
| } | ||
|
|
||
| func (c *Config) effectiveStatePeriod() time.Duration { | ||
| if c.SocketStatePeriod != 0 { | ||
| return c.SocketStatePeriod | ||
| } | ||
| return c.StatePeriod | ||
| } | ||
|
|
||
| var defaultConfig = Config{ | ||
| StatePeriod: 1 * time.Hour, | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.