-
Notifications
You must be signed in to change notification settings - Fork 5k
[Auditbeat] Add message field to system module #9483
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 10 commits into
elastic:feature-auditbeat-host
from
cwurm:message_everywhere_squashed
Dec 12, 2018
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
34db7dc
Add message field and eventAction enum everywhere.
bb125d8
System testing: Base fields are top-level.
8b7cb87
Start enums at 0.
8a304cd
Adjust password change message.
39dfdbe
Disable test again, will fix later.
b2894dd
Make Hound happy
82406ba
Fix rebase
e7c6fb2
Handle when host has no IP
1323a4c
Fix user test data
48d5ac7
Update socket test data
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
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 |
|---|---|---|
|
|
@@ -8,7 +8,9 @@ import ( | |
| "bytes" | ||
| "encoding/binary" | ||
| "encoding/gob" | ||
| "fmt" | ||
| "io" | ||
| "math" | ||
| "net" | ||
| "strconv" | ||
| "time" | ||
|
|
@@ -41,7 +43,7 @@ const ( | |
| type eventAction uint8 | ||
|
|
||
| const ( | ||
| eventActionHost eventAction = iota + 1 | ||
| eventActionHost eventAction = iota | ||
| eventActionIDChanged | ||
| eventActionReboot | ||
| eventActionHostnameChanged | ||
|
|
@@ -123,12 +125,7 @@ func (host *Host) toMapStr() common.MapStr { | |
|
|
||
| var ipStrings []string | ||
| for _, addr := range host.addrs { | ||
| switch v := addr.(type) { | ||
| case *net.IPNet: | ||
| ipStrings = append(ipStrings, v.IP.String()) | ||
| case *net.IPAddr: | ||
| ipStrings = append(ipStrings, v.IP.String()) | ||
| } | ||
| ipStrings = append(ipStrings, ipString(addr)) | ||
| } | ||
| mapstr.Put("ip", ipStrings) | ||
|
|
||
|
|
@@ -144,6 +141,17 @@ func (host *Host) toMapStr() common.MapStr { | |
| return mapstr | ||
| } | ||
|
|
||
| func ipString(addr net.Addr) string { | ||
| switch v := addr.(type) { | ||
| case *net.IPNet: | ||
| return v.IP.String() | ||
| case *net.IPAddr: | ||
| return v.IP.String() | ||
| default: | ||
| return "" | ||
| } | ||
| } | ||
|
|
||
| func init() { | ||
| mb.Registry.MustAddMetricSet(moduleName, metricsetName, New, | ||
| mb.DefaultMetricSet(), | ||
|
|
@@ -317,11 +325,64 @@ func hostEvent(host *Host, eventType string, action eventAction) mb.Event { | |
| "kind": eventType, | ||
| "action": action.String(), | ||
| }, | ||
| "message": hostMessage(host, action), | ||
| }, | ||
| MetricSetFields: host.toMapStr(), | ||
| } | ||
| } | ||
|
|
||
| func hostMessage(host *Host, action eventAction) string { | ||
| var firstIP string | ||
| if len(host.addrs) > 0 { | ||
| firstIP = ipString(host.addrs[0]) | ||
| } | ||
|
|
||
| // Hostname + IP of the first non-loopback interface. | ||
| hostString := fmt.Sprintf("%v (IP: %v)", host.info.Hostname, firstIP) | ||
|
|
||
| var message string | ||
| switch action { | ||
| case eventActionHost: | ||
| message = fmt.Sprintf("%v host %v is up for %v", | ||
| host.info.OS.Name, hostString, fmtDuration(host.uptime)) | ||
| case eventActionIDChanged: | ||
| message = fmt.Sprintf("ID of host %v has changed", hostString) | ||
| case eventActionReboot: | ||
| message = fmt.Sprintf("Host %v restarted", hostString) | ||
| case eventActionHostnameChanged: | ||
| message = fmt.Sprintf("Hostname changed to %v", hostString) | ||
| case eventActionHostChanged: | ||
| message = fmt.Sprintf("Host %v changed", hostString) | ||
| } | ||
|
|
||
| return message | ||
| } | ||
|
|
||
| func fmtDuration(d time.Duration) string { | ||
|
||
| const dayMinutes = 60 * 24 | ||
|
|
||
| remainingMinutes := math.Floor(d.Minutes()) | ||
| days := math.Floor(remainingMinutes / dayMinutes) | ||
|
|
||
| remainingMinutes -= days * dayMinutes | ||
| hours := math.Floor(remainingMinutes / 60) | ||
|
|
||
| remainingMinutes -= hours * 60 | ||
| minutes := math.Floor(remainingMinutes) | ||
|
|
||
| return fmt.Sprintf("%.f %v, %.f %v, %.f %v", | ||
| days, inflect("day", int(days)), | ||
| hours, inflect("hour", int(hours)), | ||
| minutes, inflect("minute", int(minutes))) | ||
| } | ||
|
|
||
| func inflect(noun string, count int) string { | ||
cwurm marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if count == 1 { | ||
| return noun | ||
| } | ||
| return noun + "s" | ||
| } | ||
|
|
||
| func (ms *MetricSet) saveStateToDisk() error { | ||
| var buf bytes.Buffer | ||
| encoder := gob.NewEncoder(&buf) | ||
|
|
||
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
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
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.