2022-10-07 09:05:35 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2023-11-24 14:57:32 +00:00
|
|
|
"strconv"
|
2022-10-07 09:05:35 +00:00
|
|
|
|
|
|
|
"github.com/aquasecurity/table"
|
|
|
|
"github.com/enescakir/emoji"
|
|
|
|
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
|
|
|
)
|
|
|
|
|
2023-11-24 14:57:32 +00:00
|
|
|
func listHubItemTable(out io.Writer, title string, items []*cwhub.Item) {
|
2022-10-07 09:05:35 +00:00
|
|
|
t := newLightTable(out)
|
|
|
|
t.SetHeaders("Name", fmt.Sprintf("%v Status", emoji.Package), "Version", "Local Path")
|
|
|
|
t.SetHeaderAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
|
|
|
t.SetAlignment(table.AlignLeft, table.AlignLeft, table.AlignLeft, table.AlignLeft)
|
|
|
|
|
2023-11-24 14:57:32 +00:00
|
|
|
for _, item := range items {
|
2023-12-05 12:38:52 +00:00
|
|
|
status := fmt.Sprintf("%v %s", item.State.Emoji(), item.State.Text())
|
|
|
|
t.AddRow(item.Name, status, item.State.LocalVersion, item.State.LocalPath)
|
2022-10-07 09:05:35 +00:00
|
|
|
}
|
|
|
|
renderTableTitle(out, title)
|
|
|
|
t.Render()
|
|
|
|
}
|
|
|
|
|
|
|
|
func scenarioMetricsTable(out io.Writer, itemName string, metrics map[string]int) {
|
|
|
|
if metrics["instantiation"] == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
t := newTable(out)
|
|
|
|
t.SetHeaders("Current Count", "Overflows", "Instantiated", "Poured", "Expired")
|
|
|
|
|
|
|
|
t.AddRow(
|
2023-11-24 14:57:32 +00:00
|
|
|
strconv.Itoa(metrics["curr_count"]),
|
|
|
|
strconv.Itoa(metrics["overflow"]),
|
|
|
|
strconv.Itoa(metrics["instantiation"]),
|
|
|
|
strconv.Itoa(metrics["pour"]),
|
|
|
|
strconv.Itoa(metrics["underflow"]),
|
2022-10-07 09:05:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
renderTableTitle(out, fmt.Sprintf("\n - (Scenario) %s:", itemName))
|
|
|
|
t.Render()
|
|
|
|
}
|
|
|
|
|
|
|
|
func parserMetricsTable(out io.Writer, itemName string, metrics map[string]map[string]int) {
|
|
|
|
t := newTable(out)
|
|
|
|
t.SetHeaders("Parsers", "Hits", "Parsed", "Unparsed")
|
|
|
|
|
2023-11-24 14:57:32 +00:00
|
|
|
// don't show table if no hits
|
|
|
|
showTable := false
|
|
|
|
|
2022-10-07 09:05:35 +00:00
|
|
|
for source, stats := range metrics {
|
|
|
|
if stats["hits"] > 0 {
|
|
|
|
t.AddRow(
|
|
|
|
source,
|
2023-11-24 14:57:32 +00:00
|
|
|
strconv.Itoa(stats["hits"]),
|
|
|
|
strconv.Itoa(stats["parsed"]),
|
|
|
|
strconv.Itoa(stats["unparsed"]),
|
2022-10-07 09:05:35 +00:00
|
|
|
)
|
2023-11-24 14:57:32 +00:00
|
|
|
showTable = true
|
2022-10-07 09:05:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-24 14:57:32 +00:00
|
|
|
if showTable {
|
2022-10-07 09:05:35 +00:00
|
|
|
renderTableTitle(out, fmt.Sprintf("\n - (Parser) %s:", itemName))
|
|
|
|
t.Render()
|
|
|
|
}
|
|
|
|
}
|