This commit is contained in:
Thibault bui Koechlin 2020-06-26 16:57:56 +02:00
parent 0aa0897acb
commit a910d14858
3 changed files with 12 additions and 12 deletions

View file

@ -39,10 +39,6 @@ type BackendManager struct {
backendPlugins map[string]BackendPlugin
}
var defaultMaxRecords = "1000"
var defaultMaxRecordsAge = "30d"
var defaultDbDebug = "false"
func NewBackendPlugin(outputConfig map[string]string) (*BackendManager, error) {
var files []string
var backendManager = &BackendManager{}
@ -102,10 +98,6 @@ func NewBackendPlugin(outputConfig map[string]string) (*BackendManager, error) {
// Add the interface and Init()
newPlugin.funcs = bInterface
newPlugin.Config["debug"] = defaultDbDebug
newPlugin.Config["max_records"] = defaultMaxRecords
newPlugin.Config["max_records_age"] = defaultMaxRecordsAge
// Merge backend config from main config file
if v, ok := outputConfig["debug"]; ok {
newPlugin.Config["debug"] = v
@ -119,6 +111,10 @@ func NewBackendPlugin(outputConfig map[string]string) (*BackendManager, error) {
newPlugin.Config["max_records_age"] = v
}
if v, ok := outputConfig["flush"]; ok {
newPlugin.Config["flush"] = v
}
err = newPlugin.funcs.Init(newPlugin.Config)
if err != nil {
return nil, fmt.Errorf("plugin '%s' init error : %s", newPlugin.Name, err)

View file

@ -21,11 +21,11 @@ import (
//OutputFactory is part of the main yaml configuration file, and holds generic backend config
type OutputFactory struct {
BackendFolder string `yaml:"backend"`
BackendFolder string `yaml:"backend,omitempty"`
//For the db GC : how many records can we keep at most
MaxRecords string `yaml:"max_records"`
MaxRecords string `yaml:"max_records,omitempty"`
//For the db GC what is the oldest records we tolerate
MaxRecordsAge string `yaml:"max_records_age"`
MaxRecordsAge string `yaml:"max_records_age,omitempty"`
//Should we automatically flush expired bans
Flush bool
Debug bool `yaml:"debug"`

View file

@ -7,6 +7,7 @@ import (
"time"
"github.com/crowdsecurity/crowdsec/pkg/types"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/jinzhu/gorm"
@ -63,7 +64,10 @@ func NewSQLite(cfg map[string]string) (*Context, error) {
c.Db.LogMode(true)
}
c.flush, _ = strconv.ParseBool(cfg["flush"])
c.flush, err = strconv.ParseBool(cfg["flush"])
if err != nil {
return nil, errors.Wrap(err, "Unable to parse 'flush' flag")
}
// Migrate the schema
c.Db.AutoMigrate(&types.EventSequence{}, &types.SignalOccurence{}, &types.BanApplication{})
c.Db.Model(&types.SignalOccurence{}).Related(&types.EventSequence{})