Skip to content
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

feat(inputs.netflow): Add more fields for sFlow extended gateway packets #15521

Merged
merged 1 commit into from
Jun 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions plugins/inputs/netflow/sflow_v5.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"encoding/hex"
"fmt"
"net"
"strconv"
"strings"
"time"

"github.com/gopacket/gopacket"
Expand Down Expand Up @@ -246,12 +248,19 @@ func (d *sflowv5Decoder) decodeFlowRecords(records []sflow.FlowRecord) (map[stri
fields["dst_mask"] = record.DstMaskLen
case sflow.ExtendedGateway:
var err error
fields["next_hop_ip_version"] = record.NextHopIPVersion
if err != nil {
return nil, fmt.Errorf("decoding 'next_hop' failed: %w", err)
}
fields["next_hop"], err = decodeIP(record.NextHop)
if err != nil {
return nil, fmt.Errorf("decoding 'next_hop' failed: %w", err)
}
fields["bgp_as"] = record.AS
fields["bgp_src_as"] = record.SrcAS
fields["bgp_dst_as"] = record.ASDestinations
fields["bgp_as_path_type"] = record.ASPathType
fields["bgp_as_path_length"] = record.ASPathLength
fields["bgp_next_hop"], err = decodeIP(record.NextHop)
if err != nil {
return nil, fmt.Errorf("decoding 'bgp_next_hop' failed: %w", err)
Expand All @@ -260,6 +269,13 @@ func (d *sflowv5Decoder) decodeFlowRecords(records []sflow.FlowRecord) (map[stri
if len(record.ASPath) > 0 {
fields["bgp_next_as"] = record.ASPath[0]
}
fields["community_length"] = record.CommunitiesLength
parts := make([]string, 0, len(record.Communities))
for _, c := range record.Communities {
parts = append(parts, "0x"+strconv.FormatUint(uint64(c), 16))
}
fields["communities"] = strings.Join(parts, ",")
fields["local_pref"] = record.LocalPref
default:
return nil, fmt.Errorf("unhandled flow record type %T", r.Data)
}
Expand Down
Loading