mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-12 12:55:53 +02:00
cscli: display expired decisions' expiration time in red (#3357)
* cscli decisions: display negative expiration times in red * honor color flag
This commit is contained in:
parent
88c5f85064
commit
dada07b2da
1 changed files with 11 additions and 2 deletions
|
@ -3,13 +3,17 @@ package clidecision
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
|
|
||||||
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/cstable"
|
"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/cstable"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (cli *cliDecisions) decisionsTable(out io.Writer, alerts *models.GetAlertsResponse, printMachine bool) {
|
func (cli *cliDecisions) decisionsTable(out io.Writer, alerts *models.GetAlertsResponse, printMachine bool) {
|
||||||
t := cstable.New(out, cli.cfg().Cscli.Color)
|
wantColor := cli.cfg().Cscli.Color
|
||||||
|
t := cstable.New(out, wantColor)
|
||||||
t.SetRowLines(false)
|
t.SetRowLines(false)
|
||||||
|
|
||||||
header := []string{"ID", "Source", "Scope:Value", "Reason", "Action", "Country", "AS", "Events", "expiration", "Alert ID"}
|
header := []string{"ID", "Source", "Scope:Value", "Reason", "Action", "Country", "AS", "Events", "expiration", "Alert ID"}
|
||||||
|
@ -25,6 +29,11 @@ func (cli *cliDecisions) decisionsTable(out io.Writer, alerts *models.GetAlertsR
|
||||||
*decisionItem.Type = "(simul)" + *decisionItem.Type
|
*decisionItem.Type = "(simul)" + *decisionItem.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
duration := *decisionItem.Duration
|
||||||
|
if strings.HasPrefix(duration, "-") && wantColor != "no" {
|
||||||
|
duration = color.RedString(duration)
|
||||||
|
}
|
||||||
|
|
||||||
row := []string{
|
row := []string{
|
||||||
strconv.Itoa(int(decisionItem.ID)),
|
strconv.Itoa(int(decisionItem.ID)),
|
||||||
*decisionItem.Origin,
|
*decisionItem.Origin,
|
||||||
|
@ -34,7 +43,7 @@ func (cli *cliDecisions) decisionsTable(out io.Writer, alerts *models.GetAlertsR
|
||||||
alertItem.Source.Cn,
|
alertItem.Source.Cn,
|
||||||
alertItem.Source.GetAsNumberName(),
|
alertItem.Source.GetAsNumberName(),
|
||||||
strconv.Itoa(int(*alertItem.EventsCount)),
|
strconv.Itoa(int(*alertItem.EventsCount)),
|
||||||
*decisionItem.Duration,
|
duration,
|
||||||
strconv.Itoa(int(alertItem.ID)),
|
strconv.Itoa(int(alertItem.ID)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue