Skip to content

Commit

Permalink
Store alert remediations status in DB (#3115)
Browse files Browse the repository at this point in the history
  • Loading branch information
blotus committed Jul 16, 2024
1 parent 84c214a commit c4bfdf1
Show file tree
Hide file tree
Showing 12 changed files with 155 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/crowdsec-cli/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func (cli *cliAlerts) displayOneAlert(alert *models.Alert, withDetail bool) erro
- Date : {{.CreatedAt}}
- Machine : {{.MachineID}}
- Simulation : {{.Simulated}}
- Remediation : {{.Remediation}}
- Reason : {{.Scenario}}
- Events Count : {{.EventsCount}}
- Scope:Value : {{.Source.Scope}}{{if .Source.Value}}:{{.Source.Value}}{{end}}
Expand Down
7 changes: 4 additions & 3 deletions cmd/crowdsec-cli/decisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,10 @@ func (cli *cliDecisions) add(addIP, addRange, addDuration, addValue, addScope, a
Scope: &addScope,
Value: &addValue,
},
StartAt: &startAt,
StopAt: &stopAt,
CreatedAt: createdAt,
StartAt: &startAt,
StopAt: &stopAt,
CreatedAt: createdAt,
Remediation: true,
}
alerts = append(alerts, &alert)

Expand Down
1 change: 1 addition & 0 deletions pkg/apiserver/controllers/v1/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func FormatOneAlert(alert *ent.Alert) *models.Alert {
Capacity: &alert.Capacity,
Leakspeed: &alert.LeakSpeed,
Simulated: &alert.Simulated,
Remediation: alert.Remediation,
UUID: alert.UUID,
Source: &models.Source{
Scope: &alert.SourceScope,
Expand Down
6 changes: 3 additions & 3 deletions pkg/database/alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ func (c *Client) UpdateCommunityBlocklist(alertItem *models.Alert) (int, int, in
SetLeakSpeed(*alertItem.Leakspeed).
SetSimulated(*alertItem.Simulated).
SetScenarioVersion(*alertItem.ScenarioVersion).
SetScenarioHash(*alertItem.ScenarioHash)
SetScenarioHash(*alertItem.ScenarioHash).
SetRemediation(true) // it's from CAPI, we always have decisions

alertRef, err := alertB.Save(c.CTX)
if err != nil {
Expand Down Expand Up @@ -554,7 +555,6 @@ func (c *Client) createAlertChunk(machineID string, owner *ent.Machine, alerts [

if len(metaItem.Value) > 4095 {
c.Log.Warningf("truncated meta %s : value too long", metaItem.Key)

value = value[:4095]
}

Expand Down Expand Up @@ -618,6 +618,7 @@ func (c *Client) createAlertChunk(machineID string, owner *ent.Machine, alerts [
SetSimulated(*alertItem.Simulated).
SetScenarioVersion(*alertItem.ScenarioVersion).
SetScenarioHash(*alertItem.ScenarioHash).
SetRemediation(alertItem.Remediation).
SetUUID(alertItem.UUID).
AddEvents(events...).
AddMetas(metas...)
Expand Down Expand Up @@ -677,7 +678,6 @@ func (c *Client) createAlertChunk(machineID string, owner *ent.Machine, alerts [
}
}
}

return ret, nil
}

Expand Down
13 changes: 12 additions & 1 deletion pkg/database/ent/alert.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions pkg/database/ent/alert/alert.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions pkg/database/ent/alert/where.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions pkg/database/ent/alert_create.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pkg/database/ent/alert_update.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/database/ent/migrate/schema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 74 additions & 1 deletion pkg/database/ent/mutation.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/database/ent/schema/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (Alert) Fields() []ent.Field {
field.String("scenarioHash").Optional().Immutable(),
field.Bool("simulated").Default(false).Immutable(),
field.String("uuid").Optional().Immutable(), // this uuid is mostly here to ensure that CAPI/PAPI has a unique id for each alert
field.Bool("remediation").Optional().Immutable(),
}
}

Expand Down

0 comments on commit c4bfdf1

Please sign in to comment.