2022-10-07 09:05:35 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
|
|
|
)
|
|
|
|
|
2024-02-01 21:36:21 +00:00
|
|
|
func (cli *cliDecisions) decisionsTable(out io.Writer, alerts *models.GetAlertsResponse, printMachine bool) {
|
2022-10-07 09:05:35 +00:00
|
|
|
t := newTable(out)
|
|
|
|
t.SetRowLines(false)
|
2024-02-01 21:36:21 +00:00
|
|
|
|
2022-10-07 09:05:35 +00:00
|
|
|
header := []string{"ID", "Source", "Scope:Value", "Reason", "Action", "Country", "AS", "Events", "expiration", "Alert ID"}
|
|
|
|
if printMachine {
|
|
|
|
header = append(header, "Machine")
|
|
|
|
}
|
2024-02-01 21:36:21 +00:00
|
|
|
|
2022-10-07 09:05:35 +00:00
|
|
|
t.SetHeaders(header...)
|
|
|
|
|
|
|
|
for _, alertItem := range *alerts {
|
|
|
|
for _, decisionItem := range alertItem.Decisions {
|
|
|
|
if *alertItem.Simulated {
|
|
|
|
*decisionItem.Type = fmt.Sprintf("(simul)%s", *decisionItem.Type)
|
|
|
|
}
|
2024-02-01 21:36:21 +00:00
|
|
|
|
2022-10-07 09:05:35 +00:00
|
|
|
row := []string{
|
|
|
|
strconv.Itoa(int(decisionItem.ID)),
|
|
|
|
*decisionItem.Origin,
|
|
|
|
*decisionItem.Scope + ":" + *decisionItem.Value,
|
|
|
|
*decisionItem.Scenario,
|
|
|
|
*decisionItem.Type,
|
|
|
|
alertItem.Source.Cn,
|
2022-11-14 08:55:53 +00:00
|
|
|
alertItem.Source.GetAsNumberName(),
|
2022-10-07 09:05:35 +00:00
|
|
|
strconv.Itoa(int(*alertItem.EventsCount)),
|
|
|
|
*decisionItem.Duration,
|
|
|
|
strconv.Itoa(int(alertItem.ID)),
|
|
|
|
}
|
|
|
|
|
|
|
|
if printMachine {
|
|
|
|
row = append(row, alertItem.MachineID)
|
|
|
|
}
|
|
|
|
|
|
|
|
t.AddRow(row...)
|
|
|
|
}
|
|
|
|
}
|
2024-02-01 21:36:21 +00:00
|
|
|
|
2022-10-07 09:05:35 +00:00
|
|
|
t.Render()
|
|
|
|
}
|