Skip to content

Commit 0d630d9

Browse files
committed
network events to string
1 parent 01f00d0 commit 0d630d9

File tree

647 files changed

+111132
-3062
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

647 files changed

+111132
-3062
lines changed

cmd/flow_capture_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ func TestFlowTableDefaultDisplay(t *testing.T) {
3939
rows := strings.Split(buf.String(), "\n")
4040

4141
assert.Equal(t, 4, len(rows))
42-
assert.Equal(t, `Time SrcName SrcType DstName DstType DropBytes DropPackets DropState DropCause DnsId DnsLatency DnsRCode DnsErrno RTT NetworkEvents `, rows[0])
43-
assert.Equal(t, `17:25:28.703000 src-pod Pod dst-pod Pod 32B 1 TCP_INVALID_STATE SKB_DROP_REASON_TCP_INVALID_SEQUENCE 31319 1ms NoError 0 10µs hello `, rows[1])
44-
assert.Equal(t, `---------------- --------------------------------------------- -------- --------------------------------------------- -------- ------------ ------------ -------------------- ---------------------------------------- ------ ------ ------ ------ ------ ---------------- `, rows[2])
42+
assert.Equal(t, `Time SrcName SrcType DstName DstType DropBytes DropPackets DropState DropCause DnsId DnsLatency DnsRCode DnsErrno RTT NetworkEvents `, rows[0])
43+
assert.Equal(t, `17:25:28.703000 src-pod Pod dst-pod Pod 32B 1 TCP_INVALID_STATE SKB_DROP_REASON_TCP_INVALID_SEQUENCE 31319 1ms NoError 0 10µs Allowed by default allow from local node policy, direction Ingress `, rows[1])
44+
assert.Equal(t, `---------------- --------------------------------------------- -------- --------------------------------------------- -------- ------------ ------------ -------------------- ---------------------------------------- ------ ------ ------ ------ ------ ---------------- `, rows[2])
4545
assert.Empty(t, rows[3])
4646
}
4747

@@ -129,9 +129,9 @@ func TestFlowTableAdvancedDisplay(t *testing.T) {
129129
// set display without enrichment
130130
rows := getRows([]string{pktDropDisplay, dnsDisplay, rttDisplay, networkEventsDisplay}, []string{noEnrichment})
131131
assert.Equal(t, 4, len(rows))
132-
assert.Equal(t, `Time SrcAddr SrcPort DstAddr DstPort DropBytes DropPackets DropState DropCause DnsId DnsLatency DnsRCode DnsErrno RTT NetworkEvents `, rows[0])
133-
assert.Equal(t, `17:25:28.703000 10.128.0.29 1234 10.129.0.26 5678 32B 1 TCP_INVALID_STATE SKB_DROP_REASON_TCP_INVALID_SEQUENCE 31319 1ms NoError 0 10µs hello `, rows[1])
134-
assert.Equal(t, `---------------- ---------------------------------------- ------ ---------------------------------------- ------ ------------ ------------ -------------------- ---------------------------------------- ------ ------ ------ ------ ------ ---------------- `, rows[2])
132+
assert.Equal(t, `Time SrcAddr SrcPort DstAddr DstPort DropBytes DropPackets DropState DropCause DnsId DnsLatency DnsRCode DnsErrno RTT NetworkEvents `, rows[0])
133+
assert.Equal(t, `17:25:28.703000 10.128.0.29 1234 10.129.0.26 5678 32B 1 TCP_INVALID_STATE SKB_DROP_REASON_TCP_INVALID_SEQUENCE 31319 1ms NoError 0 10µs Allowed by default allow from local node policy, direction Ingress `, rows[1])
134+
assert.Equal(t, `---------------- ---------------------------------------- ------ ---------------------------------------- ------ ------------ ------------ -------------------- ---------------------------------------- ------ ------ ------ ------ ------ ---------------- `, rows[2])
135135
assert.Empty(t, rows[3])
136136

137137
// set display to standard
@@ -173,8 +173,8 @@ func TestFlowTableAdvancedDisplay(t *testing.T) {
173173
// set display to NetworkEvents
174174
rows = getRows([]string{networkEventsDisplay}, []string{noEnrichment})
175175
assert.Equal(t, 4, len(rows))
176-
assert.Equal(t, `Time SrcAddr SrcPort DstAddr DstPort NetworkEvents `, rows[0])
177-
assert.Equal(t, `17:25:28.703000 10.128.0.29 1234 10.129.0.26 5678 hello `, rows[1])
178-
assert.Equal(t, `---------------- ---------------------------------------- ------ ---------------------------------------- ------ ---------------- `, rows[2])
176+
assert.Equal(t, `Time SrcAddr SrcPort DstAddr DstPort NetworkEvents `, rows[0])
177+
assert.Equal(t, `17:25:28.703000 10.128.0.29 1234 10.129.0.26 5678 Allowed by default allow from local node policy, direction Ingress `, rows[1])
178+
assert.Equal(t, `---------------- ---------------------------------------- ------ ---------------------------------------- ------ ---------------- `, rows[2])
179179
assert.Empty(t, rows[3])
180180
}

cmd/map_format.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/jpillora/sizestr"
1010
"github.com/netobserv/flowlogs-pipeline/pkg/config"
11+
ovnmodel "github.com/ovn-org/ovn-kubernetes/go-controller/observability-lib/model"
1112
)
1213

1314
const (
@@ -416,6 +417,47 @@ func toTimeString(genericMap config.GenericMap, fieldName string) string {
416417
return emptyText
417418
}
418419

420+
func networkEventsToString(flow config.GenericMap) string {
421+
if ne, found := flow["NetworkEvents"]; found {
422+
if neList, isList := ne.([]any); isList {
423+
var messages []string
424+
for _, item := range neList {
425+
if neItem, isMap := item.(map[string]any); isMap {
426+
messages = append(messages, networkEventItemToString(neItem))
427+
}
428+
}
429+
return strings.Join(messages, ", ")
430+
}
431+
}
432+
return ""
433+
}
434+
435+
func networkEventItemToString(in map[string]any) string {
436+
if msg := getAsString(in, "Message"); msg != "" {
437+
return msg
438+
}
439+
if feat := getAsString(in, "Feature"); feat == "acl" {
440+
aclObj := ovnmodel.ACLEvent{
441+
Action: getAsString(in, "Action"),
442+
Actor: getAsString(in, "Type"),
443+
Name: getAsString(in, "Name"),
444+
Namespace: getAsString(in, "Namespace"),
445+
Direction: getAsString(in, "Direction"),
446+
}
447+
return aclObj.String()
448+
}
449+
return ""
450+
}
451+
452+
func getAsString(in map[string]any, key string) string {
453+
if anyV, hasKey := in[key]; hasKey {
454+
if v, isStr := anyV.(string); isStr {
455+
return v
456+
}
457+
}
458+
return ""
459+
}
460+
419461
func ToTableRow(genericMap config.GenericMap, cols []string) []interface{} {
420462
row := []interface{}{}
421463

@@ -474,6 +516,8 @@ func ToTableRow(genericMap config.GenericMap, cols []string) []interface{} {
474516
row = append(row, toText(genericMap, "DnsFlagsResponseCode"))
475517
case "RTT":
476518
row = append(row, toDuration(genericMap, "TimeFlowRttNs", time.Nanosecond))
519+
case "NetworkEvents":
520+
row = append(row, networkEventsToString(genericMap))
477521
default:
478522
// else simply pick field value as text from column name
479523
row = append(row, toText(genericMap, col))

cmd/root_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const (
4444
"PktDropLatestFlags":16,
4545
"PktDropLatestState":"TCP_INVALID_STATE",
4646
"PktDropPackets":1,
47-
"NetworkEvents":["hello"],
47+
"NetworkEvents":[{"Feature":"acl","Type":"NetpolNode","Action":"allow","Direction":"Ingress"}],
4848
"Proto":6,
4949
"SrcAddr":"10.128.0.29",
5050
"SrcK8S_HostIP":"10.0.1.1",

go.mod

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ require (
1010
github.com/google/gopacket v1.1.19
1111
github.com/jpillora/sizestr v1.0.0
1212
github.com/mattn/go-sqlite3 v1.14.24
13-
github.com/netobserv/flowlogs-pipeline v1.6.1-crc0
13+
github.com/netobserv/flowlogs-pipeline v1.7.0-community.0.20241203095621-9592b66e80cc
14+
github.com/ovn-org/ovn-kubernetes/go-controller v0.0.0-20241126140656-c95491e46334
1415
github.com/rodaine/table v1.3.0
1516
github.com/ryankurte/go-pcapng v0.0.0-20170712041429-73fd1a63fab4
1617
github.com/sirupsen/logrus v1.9.3
@@ -21,17 +22,35 @@ require (
2122

2223
require (
2324
github.com/blang/semver/v4 v4.0.0 // indirect
25+
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
26+
github.com/cenkalti/hub v1.0.1 // indirect
27+
github.com/cenkalti/rpc2 v0.0.0-20210604223624-c1acbc6ec984 // indirect
28+
github.com/containernetworking/cni v1.1.2 // indirect
29+
github.com/containernetworking/plugins v1.2.0 // indirect
30+
github.com/coreos/go-iptables v0.6.0 // indirect
31+
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
2432
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
2533
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
34+
github.com/go-logr/stdr v1.2.2 // indirect
2635
github.com/google/go-cmp v0.6.0 // indirect
2736
github.com/gorilla/websocket v1.5.0 // indirect
2837
github.com/klauspost/compress v1.17.9 // indirect
2938
github.com/moby/spdystream v0.4.0 // indirect
3039
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
31-
github.com/netobserv/netobserv-ebpf-agent v1.6.1-crc2.0.20240913155426-6ac7c5ccbf59 // indirect
40+
github.com/netobserv/netobserv-ebpf-agent v1.7.0-community.0.20241206141054-2ab577a88c12 // indirect
41+
github.com/ovn-org/libovsdb v0.7.1-0.20240820095311-ce1951614a20 // indirect
42+
github.com/russross/blackfriday/v2 v2.1.0 // indirect
43+
github.com/safchain/ethtool v0.3.1-0.20231027162144-83e5e0097c91 // indirect
44+
github.com/urfave/cli/v2 v2.27.2 // indirect
45+
github.com/vishvananda/netlink v1.3.0 // indirect
46+
github.com/vishvananda/netns v0.0.4 // indirect
3247
github.com/x448/float16 v0.8.4 // indirect
33-
k8s.io/component-base v0.30.2 // indirect
34-
sigs.k8s.io/controller-runtime v0.18.4 // indirect
48+
github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913 // indirect
49+
gopkg.in/gcfg.v1 v1.2.3 // indirect
50+
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
51+
gopkg.in/warnings.v0 v0.1.2 // indirect
52+
k8s.io/component-base v0.31.1 // indirect
53+
sigs.k8s.io/controller-runtime v0.19.0 // indirect
3554
)
3655

3756
require (
@@ -62,7 +81,7 @@ require (
6281
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
6382
github.com/pkg/errors v0.9.1 // indirect
6483
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
65-
github.com/prometheus/client_golang v1.20.3 // indirect
84+
github.com/prometheus/client_golang v1.20.5 // indirect
6685
github.com/prometheus/client_model v0.6.1 // indirect
6786
github.com/prometheus/common v0.55.0 // indirect
6887
github.com/prometheus/procfs v0.15.1 // indirect
@@ -72,15 +91,15 @@ require (
7291
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
7392
github.com/xdg-go/scram v1.1.2 // indirect
7493
github.com/xdg-go/stringprep v1.0.4 // indirect
75-
golang.org/x/net v0.26.0 // indirect
76-
golang.org/x/oauth2 v0.21.0 // indirect
77-
golang.org/x/sys v0.25.0 // indirect
78-
golang.org/x/term v0.21.0 // indirect
79-
golang.org/x/text v0.16.0 // indirect
94+
golang.org/x/net v0.28.0 // indirect
95+
golang.org/x/oauth2 v0.22.0 // indirect
96+
golang.org/x/sys v0.26.0 // indirect
97+
golang.org/x/term v0.23.0 // indirect
98+
golang.org/x/text v0.17.0 // indirect
8099
golang.org/x/time v0.5.0 // indirect
81-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
82-
google.golang.org/grpc v1.65.0 // indirect
83-
google.golang.org/protobuf v1.34.2 // indirect
100+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect
101+
google.golang.org/grpc v1.67.1 // indirect
102+
google.golang.org/protobuf v1.35.1 // indirect
84103
gopkg.in/inf.v0 v0.9.1 // indirect
85104
gopkg.in/yaml.v2 v2.4.0 // indirect
86105
gopkg.in/yaml.v3 v3.0.1 // indirect

0 commit comments

Comments
 (0)