Skip to content

Commit

Permalink
Use additional fields to populate bytes/pkt counters
Browse files Browse the repository at this point in the history
Some devices out there (Cisco NSEL) use fields 231/232 as bytes
counters, when those are supposed to be layer 4 payload counters.

This updates the ECS fields populator to use those fields when the
expected ones are not found.

Fixes elastic#14212
  • Loading branch information
adriansr committed Jan 14, 2020
1 parent 326f661 commit 13a66ab
Show file tree
Hide file tree
Showing 5 changed files with 614 additions and 45 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Check content-type when creating new reader in s3 input. {pull}15252[15252] {issue}15225[15225]
- Fix session reset detection and a crash in Netflow input. {pull}14904[14904]
- netflow v9: Allow for options templates without scope fields. {pull}15449[15449]
- netflow v9: Fix bytes/packets counters on some devices (NSEL and Netstream). {pull}15449[15449]

*Heartbeat*

Expand Down
32 changes: 16 additions & 16 deletions x-pack/filebeat/input/netflow/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,22 +245,10 @@ func flowToBeatEvent(flow record.Record) (event beat.Event) {
ecsNetwork["transport"] = IPProtocol(proto).String()
ecsNetwork["iana_number"] = proto
}
countBytes, hasBytes := getKeyUint64(flow.Fields, "octetDeltaCount")
if !hasBytes {
countBytes, hasBytes = getKeyUint64(flow.Fields, "octetTotalCount")
}
countPkts, hasPkts := getKeyUint64(flow.Fields, "packetDeltaCount")
if !hasPkts {
countPkts, hasPkts = getKeyUint64(flow.Fields, "packetTotalCount")
}
revBytes, hasRevBytes := getKeyUint64(flow.Fields, "reverseOctetDeltaCount")
if !hasRevBytes {
revBytes, hasRevBytes = getKeyUint64(flow.Fields, "reverseOctetTotalCount")
}
revPkts, hasRevPkts := getKeyUint64(flow.Fields, "reversePacketDeltaCount")
if !hasRevPkts {
revPkts, hasRevPkts = getKeyUint64(flow.Fields, "reversePacketTotalCount")
}
countBytes, hasBytes := getKeyUint64Alternatives(flow.Fields, "octetDeltaCount", "octetTotalCount", "initiatorOctets")
countPkts, hasPkts := getKeyUint64Alternatives(flow.Fields, "packetDeltaCount", "packetTotalCount", "initiatorPackets")
revBytes, hasRevBytes := getKeyUint64Alternatives(flow.Fields, "reverseOctetDeltaCount", "reverseOctetTotalCount", "responderOctets")
revPkts, hasRevPkts := getKeyUint64Alternatives(flow.Fields, "reversePacketDeltaCount", "reversePacketTotalCount", "responderPackets")

if hasRevBytes {
ecsDest["bytes"] = revBytes
Expand Down Expand Up @@ -337,6 +325,18 @@ func getKeyUint64(dict record.Map, key string) (value uint64, found bool) {
return
}

func getKeyUint64Alternatives(dict record.Map, keys ...string) (value uint64, found bool) {
var iface interface{}
for _, key := range keys {
if iface, found = dict[key]; found {
if value, found = iface.(uint64); found {
return
}
}
}
return
}

func getKeyString(dict record.Map, key string) (value string, found bool) {
iface, found := dict[key]
if !found {
Expand Down
Loading

0 comments on commit 13a66ab

Please sign in to comment.