github.com/crowdsecurity/crowdsec@v1.6.1/cmd/crowdsec-cli/decisions_table.go (about)

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