Skip to content

Commit b14aa5b

Browse files
committed
manage raw display
1 parent 3a7e78b commit b14aa5b

File tree

3 files changed

+68
-47
lines changed

3 files changed

+68
-47
lines changed

cmd/display.go

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -143,18 +143,20 @@ func getTop() tview.Primitive {
143143
// enrichment: TODO: replace with dropdowns or popup
144144
enrichmentTextView := tview.NewTextView().SetText(getEnrichmentText())
145145
enrichmentRow := tview.NewFlex().SetDirection(tview.FlexColumn).
146-
AddItem(enrichmentTextView, 0, 1, false).
147-
AddItem(tview.NewButton("←").SetSelectedFunc(func() {
148-
enrichment.prev()
149-
enrichmentTextView.SetText(getEnrichmentText())
150-
updateScreen()
151-
}), 5, 0, false).
152-
AddItem(tview.NewButton("→").SetSelectedFunc(func() {
153-
enrichment.next()
154-
enrichmentTextView.SetText(getEnrichmentText())
155-
updateScreen()
156-
}), 5, 0, false)
157-
146+
AddItem(enrichmentTextView, 0, 1, false)
147+
if display.getCurrentItem().name != rawDisplay {
148+
enrichmentRow.
149+
AddItem(tview.NewButton("←").SetSelectedFunc(func() {
150+
enrichment.prev()
151+
enrichmentTextView.SetText(getEnrichmentText())
152+
updateScreen()
153+
}), 5, 0, false).
154+
AddItem(tview.NewButton("→").SetSelectedFunc(func() {
155+
enrichment.next()
156+
enrichmentTextView.SetText(getEnrichmentText())
157+
updateScreen()
158+
}), 5, 0, false)
159+
}
158160
flexView.AddItem(enrichmentRow, 0, 1, false)
159161

160162
return flexView
@@ -235,6 +237,9 @@ func getBottom() tview.Primitive {
235237
}
236238

237239
func getEnrichmentText() string {
240+
if display.getCurrentItem().name == rawDisplay {
241+
return "Enrichment: n/a\n"
242+
}
238243
return fmt.Sprintf("Enrichment: %s\n", enrichment.getCurrentItem().name)
239244
}
240245

@@ -310,47 +315,54 @@ func updateTable() {
310315
return
311316
}
312317

313-
// main field, always show the end time
314-
cols := []string{
315-
"EndTime",
316-
}
317-
318-
// enrichment fields
319-
if enrichment.getCurrentItem().name != noOptions {
320-
cols = append(cols, enrichment.getCurrentItem().ids...)
318+
cols := []string{}
319+
if display.getCurrentItem().name == rawDisplay {
320+
cols = append(cols,
321+
rawDisplay,
322+
)
321323
} else {
322-
// TODO: add a new flag in the config to identify these as default non enriched fields
324+
// main field, always show the end time
323325
cols = append(cols,
324-
"SrcAddr",
325-
"SrcPort",
326-
"DstAddr",
327-
"DstPort",
326+
"EndTime",
328327
)
329-
}
330328

331-
// append interfaces and their directions between enrichment and features
332-
// this is useful for pkt drop, udns etc
333-
cols = append(cols,
334-
"Interfaces",
335-
"IfDirections",
336-
)
337-
338-
// standard / feature fields
339-
if display.getCurrentItem().name != standardDisplay {
340-
for _, col := range cfg.Columns {
341-
if col.Field != "" && slices.Contains(display.getCurrentItem().ids, col.Feature) {
342-
cols = append(cols, col.ID)
343-
}
329+
// enrichment fields
330+
if enrichment.getCurrentItem().name != noOptions {
331+
cols = append(cols, enrichment.getCurrentItem().ids...)
332+
} else {
333+
// TODO: add a new flag in the config to identify these as default non enriched fields
334+
cols = append(cols,
335+
"SrcAddr",
336+
"SrcPort",
337+
"DstAddr",
338+
"DstPort",
339+
)
344340
}
345-
} else {
346-
// TODO: add a new flag in the config to identify these as default feature fields
341+
342+
// append interfaces and their directions between enrichment and features
343+
// this is useful for pkt drop, udns etc
347344
cols = append(cols,
348-
"FlowDirection",
349-
"Proto",
350-
"Dscp",
351-
"Bytes",
352-
"Packets",
345+
"Interfaces",
346+
"IfDirections",
353347
)
348+
349+
// standard / feature fields
350+
if display.getCurrentItem().name != standardDisplay {
351+
for _, col := range cfg.Columns {
352+
if col.Field != "" && slices.Contains(display.getCurrentItem().ids, col.Feature) {
353+
cols = append(cols, col.ID)
354+
}
355+
}
356+
} else {
357+
// TODO: add a new flag in the config to identify these as default feature fields
358+
cols = append(cols,
359+
"FlowDirection",
360+
"Proto",
361+
"Dscp",
362+
"Bytes",
363+
"Packets",
364+
)
365+
}
354366
}
355367

356368
// lastFlows may change during the render so we make a copy first

cmd/map_format.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,9 @@ func toFieldName(id string) string {
462462
}
463463

464464
func ellipsize(text string, maxLen int) string {
465+
if maxLen == 0 {
466+
return text
467+
}
465468
lastSpaceIx := maxLen
466469
len := 0
467470
for i, r := range text {
@@ -477,6 +480,9 @@ func ellipsize(text string, maxLen int) string {
477480
}
478481

479482
func ToColWidth(id string) int {
483+
if id == rawDisplay {
484+
return 0
485+
}
480486
colIndex := slices.IndexFunc(cfg.Columns, func(c *ColumnConfig) bool { return c.ID == id })
481487
width := 6
482488
if colIndex != -1 {
@@ -506,6 +512,8 @@ func ToColValue(genericMap config.GenericMap, id string) string {
506512
outputStr := ""
507513

508514
switch id {
515+
case rawDisplay:
516+
outputStr = fmt.Sprintf("%v", genericMap)
509517
case "EndTime":
510518
if captureType == "Flow" {
511519
outputStr = toTimeString(genericMap, "TimeFlowEndMs")

cmd/options.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var (
4848
// no enrichment
4949
{name: noOptions},
5050
// per field enrichments
51+
{name: "IP & Port", ids: []string{"SrcAddr", "SrcPort", "DstAddr", "DstPort"}},
5152
{name: "Cluster", ids: []string{"ClusterName"}},
5253
{name: "Zone", ids: []string{"SrcZone", "DstZone"}},
5354
{name: "Host", ids: []string{"SrcK8S_HostIP", "DstK8S_HostIP", "SrcK8S_HostName", "DstK8S_HostName", "FlowDirection"}},
@@ -69,7 +70,7 @@ var (
6970
}},
7071
},
7172
// resource enrichment by default
72-
current: 6,
73+
current: 7,
7374
}
7475
)
7576

0 commit comments

Comments
 (0)