add cscli decisions import (#1038)

* add cscli decisions import

Co-authored-by: Sebastien Blot <sebastien@crowdsec.net>
Co-authored-by: bui <thibault@crowdsec.net>
This commit is contained in:
AlteredCoder 2021-12-15 11:39:37 +01:00 committed by GitHub
parent 6e272d3f88
commit 88d06260d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 254 additions and 22 deletions

View file

@ -125,7 +125,7 @@ func (c *Controller) CreateAlert(gctx *gin.Context) {
c.HandleDBErrors(gctx, err)
return
}
stopFlush := false
for _, alert := range input {
alert.MachineID = machineID
if len(alert.Decisions) != 0 {
@ -143,6 +143,10 @@ func (c *Controller) CreateAlert(gctx *gin.Context) {
break
}
}
decision := alert.Decisions[0]
if decision.Origin != nil && *decision.Origin == "cscli-import" {
stopFlush = true
}
continue
}
@ -164,7 +168,13 @@ func (c *Controller) CreateAlert(gctx *gin.Context) {
}
}
if stopFlush {
c.DBClient.CanFlush = false
}
alerts, err := c.DBClient.CreateAlert(machineID, input)
c.DBClient.CanFlush = true
if err != nil {
c.HandleDBErrors(gctx, err)
return