Skip to content

Commit 5330730

Browse files
committed
network events to string
1 parent 245f6a0 commit 5330730

File tree

647 files changed

+111129
-3059
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

+111129
-3059
lines changed

cmd/flow_capture_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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, `End Time Src IP Src Port Dst IP Dst Port Dropped Bytes Dropped Packets Drop State Drop Cause Drop Flags DNS Id DNS Latency DNS RCode DNS Error Flow RTT Network Events `, 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 16 31319 1ms NoError 0 10µs hello `, rows[1])
134-
assert.Equal(t, `--------------- ---------- ---------- ---------- ---------- ----- ----- ---------- ---------- ---------- ----- ----- ----- ----- ----- --------------- `, rows[2])
132+
assert.Equal(t, `End Time Src IP Src Port Dst IP Dst Port Dropped Bytes Dropped Packets Drop State Drop Cause Drop Flags DNS Id DNS Latency DNS RCode DNS Error Flow RTT Network Events `, 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 16 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, `End Time Src IP Src Port Dst IP Dst Port Network Events `, 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, `End Time Src IP Src Port Dst IP Dst Port Network Events `, 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
@@ -9,6 +9,7 @@ import (
99

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

1415
const (
@@ -431,6 +432,47 @@ func toTimeString(genericMap config.GenericMap, fieldName string) string {
431432
return emptyText
432433
}
433434

435+
func networkEventsToString(flow config.GenericMap) string {
436+
if ne, found := flow["NetworkEvents"]; found {
437+
if neList, isList := ne.([]any); isList {
438+
var messages []string
439+
for _, item := range neList {
440+
if neItem, isMap := item.(map[string]any); isMap {
441+
messages = append(messages, networkEventItemToString(neItem))
442+
}
443+
}
444+
return strings.Join(messages, ", ")
445+
}
446+
}
447+
return ""
448+
}
449+
450+
func networkEventItemToString(in map[string]any) string {
451+
if msg := getAsString(in, "Message"); msg != "" {
452+
return msg
453+
}
454+
if feat := getAsString(in, "Feature"); feat == "acl" {
455+
aclObj := ovnmodel.ACLEvent{
456+
Action: getAsString(in, "Action"),
457+
Actor: getAsString(in, "Type"),
458+
Name: getAsString(in, "Name"),
459+
Namespace: getAsString(in, "Namespace"),
460+
Direction: getAsString(in, "Direction"),
461+
}
462+
return aclObj.String()
463+
}
464+
return ""
465+
}
466+
467+
func getAsString(in map[string]any, key string) string {
468+
if anyV, hasKey := in[key]; hasKey {
469+
if v, isStr := anyV.(string); isStr {
470+
return v
471+
}
472+
}
473+
return ""
474+
}
475+
434476
func toTitles(strs []string) []string {
435477
titleCaseStrs := []string{}
436478
for _, s := range strs {
@@ -504,6 +546,8 @@ func ToTableRow(genericMap config.GenericMap, colIDs []string) []interface{} {
504546
row = append(row, toDuration(genericMap, fieldName, time.Millisecond))
505547
case "TimeFlowRttMs":
506548
row = append(row, toDuration(genericMap, fieldName, time.Nanosecond))
549+
case "NetworkEvents":
550+
row = append(row, networkEventsToString(genericMap))
507551
default:
508552
// else simply pick field value as text from column name
509553
row = append(row, toValue(genericMap, fieldName))

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
@@ -22,17 +23,35 @@ require (
2223

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

3857
require (
@@ -63,7 +82,7 @@ require (
6382
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
6483
github.com/pkg/errors v0.9.1 // indirect
6584
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
66-
github.com/prometheus/client_golang v1.20.3 // indirect
85+
github.com/prometheus/client_golang v1.20.5 // indirect
6786
github.com/prometheus/client_model v0.6.1 // indirect
6887
github.com/prometheus/common v0.55.0 // indirect
6988
github.com/prometheus/procfs v0.15.1 // indirect
@@ -73,15 +92,15 @@ require (
7392
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
7493
github.com/xdg-go/scram v1.1.2 // indirect
7594
github.com/xdg-go/stringprep v1.0.4 // indirect
76-
golang.org/x/net v0.26.0 // indirect
77-
golang.org/x/oauth2 v0.21.0 // indirect
78-
golang.org/x/sys v0.25.0 // indirect
79-
golang.org/x/term v0.21.0 // indirect
80-
golang.org/x/text v0.16.0 // indirect
95+
golang.org/x/net v0.28.0 // indirect
96+
golang.org/x/oauth2 v0.22.0 // indirect
97+
golang.org/x/sys v0.26.0 // indirect
98+
golang.org/x/term v0.23.0 // indirect
99+
golang.org/x/text v0.17.0 // indirect
81100
golang.org/x/time v0.5.0 // indirect
82-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect
83-
google.golang.org/grpc v1.65.0 // indirect
84-
google.golang.org/protobuf v1.34.2
101+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect
102+
google.golang.org/grpc v1.67.1 // indirect
103+
google.golang.org/protobuf v1.35.1
85104
gopkg.in/inf.v0 v0.9.1 // indirect
86105
gopkg.in/yaml.v2 v2.4.0 // indirect
87106
k8s.io/api v0.31.1 // indirect

0 commit comments

Comments
 (0)