Skip to content

Commit

Permalink
cscli: display expired decisions' expiration time in red (#3357)
Browse files Browse the repository at this point in the history
* cscli decisions: display negative expiration times in red

* honor color flag
  • Loading branch information
mmetc authored Dec 11, 2024
1 parent 88c5f85 commit dada07b
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/crowdsec-cli/clidecision/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ package clidecision
import (
"io"
"strconv"
"strings"

"github.com/fatih/color"

"github.com/crowdsecurity/crowdsec/cmd/crowdsec-cli/cstable"
"github.com/crowdsecurity/crowdsec/pkg/models"
)

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)

header := []string{"ID", "Source", "Scope:Value", "Reason", "Action", "Country", "AS", "Events", "expiration", "Alert ID"}
Expand All @@ -25,6 +29,11 @@ func (cli *cliDecisions) decisionsTable(out io.Writer, alerts *models.GetAlertsR
*decisionItem.Type = "(simul)" + *decisionItem.Type
}

duration := *decisionItem.Duration
if strings.HasPrefix(duration, "-") && wantColor != "no" {
duration = color.RedString(duration)
}

row := []string{
strconv.Itoa(int(decisionItem.ID)),
*decisionItem.Origin,
Expand All @@ -34,7 +43,7 @@ func (cli *cliDecisions) decisionsTable(out io.Writer, alerts *models.GetAlertsR
alertItem.Source.Cn,
alertItem.Source.GetAsNumberName(),
strconv.Itoa(int(*alertItem.EventsCount)),
*decisionItem.Duration,
duration,
strconv.Itoa(int(alertItem.ID)),
}

Expand Down

0 comments on commit dada07b

Please sign in to comment.