diff --git a/pkg/cwplugin/backend.go b/pkg/cwplugin/backend.go index 043321f57..b30ded037 100644 --- a/pkg/cwplugin/backend.go +++ b/pkg/cwplugin/backend.go @@ -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) diff --git a/pkg/outputs/ouputs.go b/pkg/outputs/ouputs.go index e824fba7e..4a5c6b4dc 100644 --- a/pkg/outputs/ouputs.go +++ b/pkg/outputs/ouputs.go @@ -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"` diff --git a/pkg/sqlite/sqlite.go b/pkg/sqlite/sqlite.go index 7cdad2ee2..9e9f0a85a 100644 --- a/pkg/sqlite/sqlite.go +++ b/pkg/sqlite/sqlite.go @@ -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{})