Skip to content

Commit 1707125

Browse files
authored
Merge pull request #175 from jpinsonneau/376
NETOBSERV-376 UI: add mac address column / filter
2 parents 39efa09 + 91e6046 commit 1707125

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
@@ -178,6 +178,7 @@
178178
"Kinds": "Kinds",
179179
"Owner Kinds": "Owner Kinds",
180180
"Ports": "Ports",
181+
"MAC": "MAC",
181182
"Node IP": "Node IP",
182183
"Node Name": "Node Name",
183184
"Kubernetes Objects": "Kubernetes Objects",
@@ -229,6 +230,7 @@
229230
"A CIDR specification like 192.51.100.0/24, 2001:db8::/32": "A CIDR specification like 192.51.100.0/24, 2001:db8::/32",
230231
"Empty double quotes \"\" for an empty IP": "Empty double quotes \"\" for an empty IP",
231232
"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",
233+
"Not a valid MAC address": "Not a valid MAC address",
232234
"Owner Name": "Owner Name",
233235
"Incomplete resource name, either kind, namespace or name is missing.": "Incomplete resource name, either kind, namespace or name is missing.",
234236
"Kind is empty": "Kind is empty",
@@ -246,6 +248,7 @@
246248
"A port number like 80, 21": "A port number like 80, 21",
247249
"A IANA name like HTTP, FTP": "A IANA name like HTTP, FTP",
248250
"Empty double quotes \"\" for undefined port": "Empty double quotes \"\" for undefined port",
251+
"Specify a single MAC address.": "Specify a single MAC address.",
249252
"Unknown protocol": "Unknown protocol",
250253
"Specify a single protocol number or name.": "Specify a single protocol number or name.",
251254
"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
@@ -40,6 +40,9 @@ export type FilterId =
4040
| 'address'
4141
| 'src_address'
4242
| 'dst_address'
43+
| 'mac'
44+
| 'src_mac'
45+
| 'dst_mac'
4346
| 'port'
4447
| 'src_port'
4548
| '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)