decisions_table.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package main
  2. import (
  3. "fmt"
  4. "io"
  5. "strconv"
  6. "github.com/crowdsecurity/crowdsec/pkg/models"
  7. )
  8. func decisionsTable(out io.Writer, alerts *models.GetAlertsResponse, printMachine bool) {
  9. t := newTable(out)
  10. t.SetRowLines(false)
  11. header := []string{"ID", "Source", "Scope:Value", "Reason", "Action", "Country", "AS", "Events", "expiration", "Alert ID"}
  12. if printMachine {
  13. header = append(header, "Machine")
  14. }
  15. t.SetHeaders(header...)
  16. for _, alertItem := range *alerts {
  17. for _, decisionItem := range alertItem.Decisions {
  18. if *alertItem.Simulated {
  19. *decisionItem.Type = fmt.Sprintf("(simul)%s", *decisionItem.Type)
  20. }
  21. row := []string{
  22. strconv.Itoa(int(decisionItem.ID)),
  23. *decisionItem.Origin,
  24. *decisionItem.Scope + ":" + *decisionItem.Value,
  25. *decisionItem.Scenario,
  26. *decisionItem.Type,
  27. alertItem.Source.Cn,
  28. alertItem.Source.GetAsNumberName(),
  29. strconv.Itoa(int(*alertItem.EventsCount)),
  30. *decisionItem.Duration,
  31. strconv.Itoa(int(alertItem.ID)),
  32. }
  33. if printMachine {
  34. row = append(row, alertItem.MachineID)
  35. }
  36. t.AddRow(row...)
  37. }
  38. }
  39. t.Render()
  40. }