Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print missing "AS" values as empty strings instead of "0 " #1867

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func AlertsToTable(alerts *models.GetAlertsResponse, printMachine bool) error {
*alertItem.Source.Value,
*alertItem.Scenario,
alertItem.Source.Cn,
alertItem.Source.AsNumber + " " + alertItem.Source.AsName,
alertItem.Source.GetAsNumberName(),
DecisionsFromAlert(alertItem),
*alertItem.StartAt,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/alerts_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func alertsTable(out io.Writer, alerts *models.GetAlertsResponse, printMachine b
displayVal,
*alertItem.Scenario,
alertItem.Source.Cn,
alertItem.Source.AsNumber + " " + alertItem.Source.AsName,
alertItem.Source.GetAsNumberName(),
DecisionsFromAlert(alertItem),
*alertItem.StartAt,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/decisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func DecisionsToTable(alerts *models.GetAlertsResponse, printMachine bool) error
*decisionItem.Scenario,
*decisionItem.Type,
alertItem.Source.Cn,
alertItem.Source.AsNumber + " " + alertItem.Source.AsName,
alertItem.Source.GetAsNumberName(),
fmt.Sprintf("%d", *alertItem.EventsCount),
*decisionItem.Duration,
fmt.Sprintf("%t", *decisionItem.Simulated),
Expand Down
2 changes: 1 addition & 1 deletion cmd/crowdsec-cli/decisions_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func decisionsTable(out io.Writer, alerts *models.GetAlertsResponse, printMachin
*decisionItem.Scenario,
*decisionItem.Type,
alertItem.Source.Cn,
alertItem.Source.AsNumber + " " + alertItem.Source.AsName,
alertItem.Source.GetAsNumberName(),
strconv.Itoa(int(*alertItem.EventsCount)),
*decisionItem.Duration,
strconv.Itoa(int(alertItem.ID)),
Expand Down
11 changes: 11 additions & 0 deletions pkg/models/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,14 @@ func (s Source) GetScope() string {
}
return *s.Scope
}

func (s Source) GetAsNumberName() string {
ret := ""
if s.AsNumber != "0" {
ret += s.AsNumber
}
if s.AsName != "" {
ret += " " + s.AsName
}
return ret
}
4 changes: 2 additions & 2 deletions tests/bats/80_alerts.bats
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ teardown() {

run -0 cscli alerts list -o raw
assert_line "id,scope,value,reason,country,as,decisions,created_at"
assert_line --regexp ".*,Ip,10.20.30.40,manual 'ban' from 'githubciXXXXXXXXXXXXXXXXXXXXXXXX([a-zA-Z0-9]{16})?',,\" \",ban:1,.*"
assert_line --regexp ".*,Ip,10.20.30.40,manual 'ban' from 'githubciXXXXXXXXXXXXXXXXXXXXXXXX([a-zA-Z0-9]{16})?',,,ban:1,.*"

run -0 cscli alerts list -o raw --machine
assert_line "id,scope,value,reason,country,as,decisions,created_at,machine"
assert_line --regexp "^[0-9]+,Ip,10.20.30.40,manual 'ban' from 'githubciXXXXXXXXXXXXXXXXXXXXXXXX([a-zA-Z0-9]{16})?',,\" \",ban:1,.*,githubciXXXXXXXXXXXXXXXXXXXXXXXX([a-zA-Z0-9]{16})?$"
assert_line --regexp "^[0-9]+,Ip,10.20.30.40,manual 'ban' from 'githubciXXXXXXXXXXXXXXXXXXXXXXXX([a-zA-Z0-9]{16})?',,,ban:1,.*,githubciXXXXXXXXXXXXXXXXXXXXXXXX([a-zA-Z0-9]{16})?$"
}

@test "cscli alerts inspect" {
Expand Down