-
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
Update ICMP protocol to use ECS fields #10062
Changes from all commits
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 |
---|---|---|
|
@@ -21,12 +21,13 @@ import ( | |
"net" | ||
"time" | ||
|
||
"github.com/elastic/beats/libbeat/beat" | ||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/logp" | ||
"github.com/elastic/beats/libbeat/monitoring" | ||
"github.com/elastic/ecs/code/go/ecs" | ||
|
||
"github.com/elastic/beats/packetbeat/flows" | ||
"github.com/elastic/beats/packetbeat/pb" | ||
"github.com/elastic/beats/packetbeat/protos" | ||
|
||
"github.com/tsg/gopacket/layers" | ||
|
@@ -283,86 +284,68 @@ func (icmp *icmpPlugin) publishTransaction(trans *icmpTransaction) { | |
|
||
logp.Debug("icmp", "Publishing transaction. %s", &trans.tuple) | ||
|
||
// common fields - group "env" | ||
fields := common.MapStr{ | ||
"client": common.MapStr{ | ||
"ip": trans.tuple.srcIP, | ||
}, | ||
"server": common.MapStr{ | ||
"ip": trans.tuple.dstIP, | ||
}, | ||
} | ||
evt, pbf := pb.NewBeatEvent(trans.ts) | ||
pbf.Source = &ecs.Source{IP: trans.tuple.srcIP.String()} | ||
pbf.Destination = &ecs.Destination{IP: trans.tuple.dstIP.String()} | ||
pbf.Event.Dataset = "icmp" | ||
|
||
// common fields - group "event" | ||
fields["type"] = "icmp" // protocol name | ||
fields := evt.Fields | ||
fields["type"] = pbf.Event.Dataset | ||
fields["path"] = trans.tuple.dstIP // what is requested (dst ip) | ||
if trans.HasError() { | ||
fields["status"] = common.ERROR_STATUS | ||
} else { | ||
fields["status"] = common.OK_STATUS | ||
} | ||
if len(trans.notes) > 0 { | ||
fields["notes"] = trans.notes | ||
} | ||
|
||
// common fields - group "measurements" | ||
responsetime, hasResponseTime := trans.ResponseTimeMillis() | ||
if hasResponseTime { | ||
fields["responsetime"] = responsetime | ||
} | ||
switch icmp.direction(trans) { | ||
case directionFromInside: | ||
if trans.request != nil { | ||
fields["bytes_out"] = trans.request.length | ||
} | ||
if trans.response != nil { | ||
fields["bytes_in"] = trans.response.length | ||
} | ||
case directionFromOutside: | ||
if trans.request != nil { | ||
fields["bytes_in"] = trans.request.length | ||
} | ||
if trans.response != nil { | ||
fields["bytes_out"] = trans.response.length | ||
} | ||
icmpEvent := common.MapStr{ | ||
"version": trans.tuple.icmpVersion, | ||
} | ||
|
||
// event fields - group "icmp" | ||
icmpEvent := common.MapStr{} | ||
fields["icmp"] = icmpEvent | ||
|
||
icmpEvent["version"] = trans.tuple.icmpVersion | ||
pbf.Network.Transport = pbf.Event.Dataset | ||
if trans.tuple.icmpVersion == 6 { | ||
pbf.Network.Transport = "ipv6-icmp" | ||
} | ||
|
||
if trans.request != nil { | ||
request := common.MapStr{} | ||
icmpEvent["request"] = request | ||
pbf.Event.Start = trans.request.ts | ||
pbf.Source.Bytes = int64(trans.request.length) | ||
|
||
request["message"] = humanReadable(&trans.tuple, trans.request) | ||
request["type"] = trans.request.Type | ||
request["code"] = trans.request.code | ||
request := common.MapStr{ | ||
"message": humanReadable(&trans.tuple, trans.request), | ||
"type": trans.request.Type, | ||
"code": trans.request.code, | ||
} | ||
icmpEvent["request"] = request | ||
|
||
// TODO: Add more info. The IPv4/IPv6 payload could be interesting. | ||
// if icmp.SendRequest { | ||
// request["payload"] = "" | ||
// } | ||
pbf.ICMPType = trans.request.Type | ||
pbf.ICMPCode = trans.request.code | ||
} | ||
|
||
if trans.response != nil { | ||
response := common.MapStr{} | ||
pbf.Event.End = trans.response.ts | ||
pbf.Destination.Bytes = int64(trans.response.length) | ||
|
||
response := common.MapStr{ | ||
"message": humanReadable(&trans.tuple, trans.response), | ||
"type": trans.response.Type, | ||
"code": trans.response.code, | ||
} | ||
icmpEvent["response"] = response | ||
|
||
response["message"] = humanReadable(&trans.tuple, trans.response) | ||
response["type"] = trans.response.Type | ||
response["code"] = trans.response.code | ||
if trans.request == nil { | ||
pbf.ICMPType = trans.response.Type | ||
pbf.ICMPCode = trans.response.code | ||
} | ||
} | ||
|
||
// TODO: Add more info. The IPv4/IPv6 payload could be interesting. | ||
// if icmp.SendResponse { | ||
// response["payload"] = "" | ||
// } | ||
if len(trans.notes) == 1 { | ||
evt.PutValue("error.message", trans.notes[0]) | ||
} else if len(trans.notes) > 1 { | ||
evt.PutValue("error.message", trans.notes) | ||
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. From and ES perspective, I would say both are the same as 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. If there's more than one note/error then I'd rather sent them as discrete strings that are part of an array. As for whether to always send an array or not that doesn't really matter to me (or to ES). I'll probably refactor this when I get to the end of #7968, because I'm finding that each protocol had slightly different behavior w.r.t. 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. No strong preference either. |
||
} | ||
|
||
icmp.results(beat.Event{ | ||
Timestamp: trans.ts, | ||
Fields: fields, | ||
}) | ||
icmp.results(evt) | ||
} |
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.
Change in behaviour? Did not follow the code.
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.
This file is "new" code as part of the parent issue #7968. Yes, this is a behavior change. It needed to be less restrictive to allow for fields in the object that are not to be marshaled. These are helper fields used to derive and make decisions about other fields that are marshaled.
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.
Should this be mentioned in the changelog?
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.
No, this is new code that's never been released and it has no impact on the user.