-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Add IP-addresses and MAC-addresses to event #6878
Changes from 3 commits
215b308
06c1a3d
bf696b1
70bf057
5bd56a1
5538abf
65463ab
3e438f8
959e2f6
5c20a52
df58825
1b09cd6
1cba03f
dfef568
1ef240d
7c44e2a
e909f81
dde24f7
993b2bc
014f5d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,10 @@ | |
type: keyword | ||
description: > | ||
OS family (e.g. redhat, debian, freebsd, windows). | ||
- name: net.ip | ||
description: > | ||
List of IP-addresses. | ||
- name: net.hw | ||
description: > | ||
List of hardware-addresses, usually MAC-addresses. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the type here would be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'll fix that |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package add_host_metadata | ||
|
||
import ( | ||
"net" | ||
"time" | ||
|
||
"github.com/elastic/beats/libbeat/beat" | ||
|
@@ -71,10 +72,54 @@ func (p *addHostMetadata) loadData() { | |
if p.info.OS.Build != "" { | ||
p.data.Put("host.os.build", p.info.OS.Build) | ||
} | ||
|
||
// IP-address and MAC-address | ||
var ipList, hwList = p.getNetInfo() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking to make this information optional, meaning it is not sent by default but we have a config option in the processor to enable it. Not sure yet how we should call the config options, any suggestions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looking at the code I was even wondering if we should separate mac address and ip. I think lots of people want to have the list of ip addresses but are less interested in the actual mac address. This could lead to a config like:
I don't like add_fields name to much but the gist is that we could add more fields in the future here. @andrewkroh Thoughts? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this a good idea, because without the feature you would then have to add a drop_fields processor causing unnecessary work. I'd have a default set of fields built into the processor's defaultConfig. Then if you want to change anything you must specific the full set of fields you want the process to add. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we do that for all fields or just for ip and mac? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @andrewkroh If I understand this correctly, my config example above would mean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Correct. That would give you only those two fields. But I wouldn't call it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My main issue going with the above suggestion is that if someone wants ip and mac in addition, he has to know all the other fields that are there to add them to the list. To not block the PR on this discussion perhaps we can go first with the initial suggestion of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have time to work on this on friday, so it would be great to have a decision by then. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @hypp We had a quick internal chat and decided to go with the proposal for |
||
p.data.Put("host.net.ip", ipList) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to call these fields There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fine by me! |
||
p.data.Put("host.net.hw", hwList) | ||
|
||
p.lastUpdate = time.Now() | ||
} | ||
} | ||
|
||
func (p addHostMetadata) getNetInfo() ([]string, []string) { | ||
var ipList []string | ||
var hwList []string | ||
|
||
// Get all interfaces and loop through them | ||
ifaces, err := net.Interfaces() | ||
if err != nil { | ||
return ipList, hwList | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead or returning the empty lists could we return here the error? Meaning it would return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure, do you have a code example of logging, that I could look at? |
||
} | ||
for _, i := range ifaces { | ||
// Skip loopback interfaces | ||
if i.Flags&net.FlagLoopback == net.FlagLoopback { | ||
continue | ||
} | ||
|
||
hw := i.HardwareAddr.String() | ||
// Skip empty hardware addresses | ||
if hw != "" { | ||
hwList = append(hwList, hw) | ||
} | ||
|
||
addrs, err := i.Addrs() | ||
if err != nil { | ||
return ipList, hwList | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar question as above. I wonder if in case of an error we should just log it but continue trying to collect the addresses from the interfaces instead of returning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a matter of taste, I prefer to fail fast. You decide. |
||
} | ||
for _, addr := range addrs { | ||
switch v := addr.(type) { | ||
case *net.IPNet: | ||
ipList = append(ipList, v.IP.String()) | ||
case *net.IPAddr: | ||
ipList = append(ipList, v.IP.String()) | ||
} | ||
} | ||
} | ||
|
||
return ipList, hwList | ||
} | ||
|
||
func (p addHostMetadata) String() string { | ||
return "add_host_metadata=[]" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use the type
ip
here: https://www.elastic.co/guide/en/elasticsearch/reference/6.2/ip.htmlThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, of course! I'll fix that too.