Skip to content

Commit 8efee4c

Browse files
committed
get net events messages - web reimpl
1 parent dfe4f95 commit 8efee4c

File tree

4 files changed

+80
-3
lines changed

4 files changed

+80
-3
lines changed

web/src/api/ipfix.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable max-len */
22
import { TFunction } from 'i18next';
33
import { RecordType } from '../model/flow-query';
4+
import { NetworkEvent } from '../model/network-events';
45

56
// Please keep this file documented: it is used in doc generation
67
// To regenerate doc, run `make generate-doc` - and also check this page:
@@ -18,7 +19,7 @@ export const getRecordValue = (record: Record, fieldOrLabel: string, defaultValu
1819
* This is mandatory to ensure fields types
1920
*/
2021
if (record.fields[fieldOrLabel as keyof Fields] !== undefined) {
21-
return record.fields[fieldOrLabel as keyof Fields];
22+
return record.fields[fieldOrLabel as keyof Fields] as string | number | string[] | undefined;
2223
}
2324
// check if label exists
2425
if (record.labels[fieldOrLabel as keyof Labels] !== undefined) {
@@ -116,7 +117,7 @@ export interface Fields {
116117
/** Flow direction array from the network interface observation point */
117118
IfDirections?: IfDirection[];
118119
/** Network Events */
119-
NetworkEvents?: string[];
120+
NetworkEvents?: NetworkEvent[];
120121
/** Logical OR combination of unique TCP flags comprised in the flow, as per RFC-9293, with additional custom flags to represent the following per-packet combinations: SYN+ACK (0x100), FIN+ACK (0x200) and RST+ACK (0x400). */
121122
Flags?: number;
122123
/** Number of packets */

web/src/components/drawer/record/record-field.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { formatProtocol, getProtocolDocUrl } from '../../../utils/protocol';
2424
import { decomposeTCPFlagsBitfield, getTCPFlagsDocUrl } from '../../../utils/tcp-flags';
2525
import { Size } from '../../dropdowns/table-display-dropdown';
2626
import './record-field.css';
27+
import { networkEventToString } from '../../../model/network-events';
2728

2829
export type RecordFieldFilter = {
2930
type: 'filter' | 'switch';
@@ -647,6 +648,16 @@ export const RecordField: React.FC<RecordFieldProps> = ({
647648
: emptyText()
648649
);
649650
}
651+
case ColumnsId.networkEvents: {
652+
if (flow.fields.NetworkEvents && flow.fields.NetworkEvents.length > 0) {
653+
const asStrings = flow.fields.NetworkEvents.map(networkEventToString);
654+
if (asStrings.length === 2) {
655+
return doubleContainer(simpleTextWithTooltip(asStrings[0]), simpleTextWithTooltip(asStrings[1]));
656+
}
657+
// else we will show values as single joigned string
658+
return singleContainer(simpleTextWithTooltip(asStrings.join(', ')));
659+
}
660+
}
650661
default:
651662
if (Array.isArray(value) && value.length) {
652663
// we can only show two values properly with containers

web/src/model/network-events.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
export interface NetworkEvent {
3+
Feature?: string;
4+
Type?: string;
5+
Action?: string;
6+
Name?: string;
7+
Namespace?: string;
8+
Direction?: string;
9+
Message?: string;
10+
}
11+
12+
export const networkEventToString = (event: NetworkEvent) => {
13+
if (event.Feature === 'acl') {
14+
let action: string;
15+
switch (event.Action) {
16+
case 'allow':
17+
case 'allow-related':
18+
case 'allow-stateless':
19+
action = "Allowed";
20+
break;
21+
case 'drop':
22+
action = "Dropped";
23+
break;
24+
case 'pass':
25+
action = "Delegated to network policy";
26+
break;
27+
default:
28+
action = "Action " + event.Action
29+
break;
30+
}
31+
let msg: string = '';
32+
switch (event.Type) {
33+
case 'AdminNetworkPolicy':
34+
msg = `admin network policy ${event.Name}, direction ${event.Direction}`;
35+
break;
36+
case 'BaselineAdminNetworkPolicy':
37+
msg = `baseline admin network policy ${event.Name}, direction ${event.Direction}`;
38+
break;
39+
case 'MulticastNS':
40+
msg = `multicast in namespace ${event.Namespace}, direction ${event.Direction}`;
41+
break;
42+
case 'MulticastCluster':
43+
msg = `cluster multicast policy, direction ${event.Direction}`;
44+
break;
45+
case 'NetpolNode':
46+
msg = `default allow from local node policy, direction ${event.Direction}`;
47+
break;
48+
case 'NetworkPolicy':
49+
msg = `network policy ${event.Name}, direction ${event.Direction}`;
50+
break;
51+
case 'NetpolNamespace':
52+
msg = `network policies isolation in namespace ${event.Namespace}, direction ${event.Direction}`;
53+
break;
54+
case 'EgressFirewall':
55+
msg = `egress firewall in namespace ${event.Namespace}`;
56+
break;
57+
case 'UDNIsolation':
58+
msg = `UDN isolation of type ${event.Name}`;
59+
break;
60+
}
61+
return `${action} by ${msg}`;
62+
}
63+
return event.Message;
64+
}

web/src/utils/columns.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export enum ColumnsId {
8080
packetsab = 'Packets_AB',
8181
packetsba = 'Packets_BA',
8282
isfirst = 'IsFirst',
83-
numflow = 'numFlowLogs'
83+
numflow = 'numFlowLogs',
84+
networkEvents = 'NetworkEvents'
8485
}
8586

8687
export interface ColumnConfigDef {

0 commit comments

Comments
 (0)