mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-14 13:24:34 +02:00
- Don't allow running more than one alert flush job at a time to prevent runaway CPU usage in some case. (fix High CPU after Upgrade to 1.2.0 #1022) - Add a cscli alerts flush command to manually flush the alerts in the database (fixes Improvement/Manual flush mechanism #1023 ). - Enable cascading deletion on alerts as we upgraded ent: Deleting an alert in the database will automatically delete all related decisions, events and meta - Add an index on alerts.id to try to improve flush performance with very big sqlite database. - Flush alert now operates in batch
80 lines
1.9 KiB
Go
80 lines
1.9 KiB
Go
package schema
|
|
|
|
import (
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/entsql"
|
|
"entgo.io/ent/schema/edge"
|
|
"entgo.io/ent/schema/field"
|
|
"entgo.io/ent/schema/index"
|
|
)
|
|
|
|
// Alert holds the schema definition for the Alert entity.
|
|
type Alert struct {
|
|
ent.Schema
|
|
}
|
|
|
|
// Fields of the Alert.
|
|
func (Alert) Fields() []ent.Field {
|
|
return []ent.Field{
|
|
field.Time("created_at").
|
|
Default(time.Now),
|
|
field.Time("updated_at").
|
|
Default(time.Now),
|
|
field.String("scenario"),
|
|
field.String("bucketId").Default("").Optional(),
|
|
field.String("message").Default("").Optional(),
|
|
field.Int32("eventsCount").Default(0).Optional(),
|
|
field.Time("startedAt").Default(time.Now).Optional(),
|
|
field.Time("stoppedAt").Default(time.Now).Optional(),
|
|
field.String("sourceIp").
|
|
Optional(),
|
|
field.String("sourceRange").
|
|
Optional(),
|
|
field.String("sourceAsNumber").
|
|
Optional(),
|
|
field.String("sourceAsName").
|
|
Optional(),
|
|
field.String("sourceCountry").
|
|
Optional(),
|
|
field.Float32("sourceLatitude").
|
|
Optional(),
|
|
field.Float32("sourceLongitude").
|
|
Optional(),
|
|
field.String("sourceScope").Optional(),
|
|
field.String("sourceValue").Optional(),
|
|
field.Int32("capacity").Optional(),
|
|
field.String("leakSpeed").Optional(),
|
|
field.String("scenarioVersion").Optional(),
|
|
field.String("scenarioHash").Optional(),
|
|
field.Bool("simulated").Default(false),
|
|
}
|
|
}
|
|
|
|
// Edges of the Alert.
|
|
func (Alert) Edges() []ent.Edge {
|
|
return []ent.Edge{
|
|
edge.From("owner", Machine.Type).
|
|
Ref("alerts").
|
|
Unique(),
|
|
edge.To("decisions", Decision.Type).
|
|
Annotations(entsql.Annotation{
|
|
OnDelete: entsql.Cascade,
|
|
}),
|
|
edge.To("events", Event.Type).
|
|
Annotations(entsql.Annotation{
|
|
OnDelete: entsql.Cascade,
|
|
}),
|
|
edge.To("metas", Meta.Type).
|
|
Annotations(entsql.Annotation{
|
|
OnDelete: entsql.Cascade,
|
|
}),
|
|
}
|
|
}
|
|
|
|
func (Alert) Indexes() []ent.Index {
|
|
return []ent.Index{
|
|
index.Fields("id"),
|
|
}
|
|
}
|