Skip to content

Commit 91e6046

Browse files
committed
added mac column / filter
1 parent 956d7a2 commit 91e6046

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

web/locales/en/plugin__network-observability-plugin.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@
156156
"Kinds": "Kinds",
157157
"Owner Kinds": "Owner Kinds",
158158
"Ports": "Ports",
159+
"MAC": "MAC",
159160
"Node IP": "Node IP",
160161
"Node Name": "Node Name",
161162
"Kubernetes Objects": "Kubernetes Objects",
@@ -207,6 +208,7 @@
207208
"A CIDR specification like 192.51.100.0/24, 2001:db8::/32": "A CIDR specification like 192.51.100.0/24, 2001:db8::/32",
208209
"Empty double quotes \"\" for an empty IP": "Empty double quotes \"\" for an empty IP",
209210
"Not a valid IPv4 or IPv6, nor a CIDR, nor an IP range separated by hyphen": "Not a valid IPv4 or IPv6, nor a CIDR, nor an IP range separated by hyphen",
211+
"Not a valid MAC address": "Not a valid MAC address",
210212
"Owner Name": "Owner Name",
211213
"Incomplete resource name, either kind, namespace or name is missing.": "Incomplete resource name, either kind, namespace or name is missing.",
212214
"Kind is empty": "Kind is empty",
@@ -224,6 +226,7 @@
224226
"A port number like 80, 21": "A port number like 80, 21",
225227
"A IANA name like HTTP, FTP": "A IANA name like HTTP, FTP",
226228
"Empty double quotes \"\" for undefined port": "Empty double quotes \"\" for undefined port",
229+
"Specify a single MAC address.": "Specify a single MAC address.",
227230
"Unknown protocol": "Unknown protocol",
228231
"Specify a single protocol number or name.": "Specify a single protocol number or name.",
229232
"Specify a single protocol following one of these rules:": "Specify a single protocol following one of these rules:",

web/src/model/filters.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export type FilterId =
3939
| 'address'
4040
| 'src_address'
4141
| 'dst_address'
42+
| 'mac'
43+
| 'src_mac'
44+
| 'dst_mac'
4245
| 'port'
4346
| 'src_port'
4447
| 'dst_port'

web/src/utils/columns.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ export enum ColumnsId {
2525
addr = 'Addr',
2626
srcaddr = 'SrcAddr',
2727
dstaddr = 'DstAddr',
28+
mac = 'Mac',
29+
srcmac = 'SrcMac',
30+
dstmac = 'DstMac',
2831
port = 'Port',
2932
srcport = 'SrcPort',
3033
dstport = 'DstPort',
@@ -212,6 +215,14 @@ export const getCommonColumns = (t: TFunction, withConcatenatedFields = true): C
212215
),
213216
width: 10
214217
},
218+
{
219+
id: ColumnsId.mac,
220+
name: t('MAC'),
221+
isSelected: false,
222+
value: f => getSrcOrDstValue(f.fields.SrcMac, f.fields.DstMac),
223+
sort: (a, b, col) => compareStrings((col.value(a) as string[]).join(''), (col.value(b) as string[]).join('')),
224+
width: 10
225+
},
215226
{
216227
id: ColumnsId.hostaddr,
217228
name: t('Node IP'),
@@ -375,6 +386,17 @@ export const getSrcColumns = (t: TFunction): Column[] => {
375386
sort: (a, b, col) => comparePorts(col.value(a) as number, col.value(b) as number),
376387
width: 10
377388
},
389+
{
390+
id: ColumnsId.srcmac,
391+
group: t('Source'),
392+
name: t('MAC'),
393+
fieldName: 'SrcMac',
394+
quickFilter: 'src_mac',
395+
isSelected: false,
396+
value: f => f.fields.SrcMac,
397+
sort: (a, b, col) => compareStrings(col.value(a) as string, col.value(b) as string),
398+
width: 10
399+
},
378400
{
379401
id: ColumnsId.srchostaddr,
380402
group: t('Source'),
@@ -479,6 +501,17 @@ export const getDstColumns = (t: TFunction): Column[] => {
479501
sort: (a, b, col) => comparePorts(col.value(a) as number, col.value(b) as number),
480502
width: 10
481503
},
504+
{
505+
id: ColumnsId.dstmac,
506+
group: t('Destination'),
507+
name: t('MAC'),
508+
fieldName: 'DstMac',
509+
quickFilter: 'dst_mac',
510+
isSelected: false,
511+
value: f => f.fields.DstMac,
512+
sort: (a, b, col) => compareStrings(col.value(a) as string, col.value(b) as string),
513+
width: 10
514+
},
482515
{
483516
id: ColumnsId.dsthostaddr,
484517
group: t('Destination'),

web/src/utils/filter-definitions.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export const getFilterDefinitions = (t: TFunction): FilterDefinition[] => {
140140
- ${t('Empty double quotes "" for an empty IP')}`;
141141

142142
const invalidIPMessage = t('Not a valid IPv4 or IPv6, nor a CIDR, nor an IP range separated by hyphen');
143+
const invalidMACMessage = t('Not a valid MAC address');
143144

144145
filterDefinitions = [
145146
...peers(
@@ -303,6 +304,25 @@ export const getFilterDefinitions = (t: TFunction): FilterDefinition[] => {
303304
singleFieldMapping('SrcPort'),
304305
singleFieldMapping('DstPort')
305306
),
307+
...peers(
308+
{
309+
id: 'mac',
310+
name: t('MAC'),
311+
component: FilterComponent.Text,
312+
category: FilterCategory.Common,
313+
getOptions: noOption,
314+
validate: (value: string) => {
315+
if (_.isEmpty(value)) {
316+
return invalid(t('Value is empty'));
317+
}
318+
return /^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})/.test(value) ? valid(value) : invalid(invalidMACMessage);
319+
},
320+
hint: t('Specify a single MAC address.'),
321+
fieldMatching: {}
322+
},
323+
singleFieldMapping('SrcMac'),
324+
singleFieldMapping('DstMac')
325+
),
306326
...peers(
307327
{
308328
id: 'host_address',

0 commit comments

Comments
 (0)