crowdsec/pkg/database/write.go
Thibault "bui" Koechlin 177480cff7
updated mysql plugin support (#135)
* add support for plugin, support mysql & so on

* fix queries

Co-authored-by: erenJag <erenJag>
Co-authored-by: AlteredCoder <AlteredCoder>
2020-07-16 16:05:03 +02:00

37 lines
1.1 KiB
Go

package database
import (
"fmt"
"sync/atomic"
"github.com/crowdsecurity/crowdsec/pkg/types"
log "github.com/sirupsen/logrus"
)
//we simply append the event to the transaction
func (c *Context) WriteBanApplication(ban types.BanApplication) error {
atomic.AddInt32(&c.count, 1)
c.lock.Lock()
defer c.lock.Unlock()
log.Debugf("Ban application being called : %s %s", ban.Scenario, ban.IpText)
ret := c.tx.Where(types.BanApplication{IpText: ban.IpText}).Assign(types.BanApplication{Until: ban.Until}).Assign(types.BanApplication{Reason: ban.Reason}).Assign(types.BanApplication{MeasureType: ban.MeasureType}).FirstOrCreate(&ban)
if ret.Error != nil {
return fmt.Errorf("failed to write ban record : %v", ret.Error)
}
return nil
}
func (c *Context) WriteSignal(sig types.SignalOccurence) error {
atomic.AddInt32(&c.count, 1)
c.lock.Lock()
defer c.lock.Unlock()
//log.Debugf("Ban signal being called : %s %s", sig.Scenario, sig.Source.Ip.String())
ret := c.tx.Create(&sig)
//sig.Scenario = sig.Scenario
if ret.Error != nil {
log.Errorf("FAILED : %+v \n", ret.Error)
return fmt.Errorf("failed to write signal occurrence : %v", ret.Error)
}
return nil
}