Merge branch 'crowdsecurity:master' into master

This commit is contained in:
Manuel Sabban 2021-12-29 11:51:27 +01:00 committed by GitHub
commit 970f374b31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 49 additions and 17 deletions

View file

@ -37,7 +37,7 @@ func NewCompletionCmd() *cobra.Command {
$ source <(cscli completion bash)
` + "```" + `
### Zsh:
### Zsh:
` + "```shell" + `
# If shell completion is not already enabled in your environment,
# you will need to enable it. You can execute the following once:

View file

@ -295,7 +295,8 @@ func main() {
log.Fatalf(err.Error())
}
// Configure logging
if err = types.SetDefaultLoggerConfig(cConfig.Common.LogMedia, cConfig.Common.LogDir, *cConfig.Common.LogLevel); err != nil {
if err = types.SetDefaultLoggerConfig(cConfig.Common.LogMedia, cConfig.Common.LogDir, *cConfig.Common.LogLevel,
cConfig.Common.LogMaxSize, cConfig.Common.LogMaxFiles, cConfig.Common.LogMaxAge, cConfig.Common.CompressLogs); err != nil {
log.Fatal(err.Error())
}

View file

@ -60,7 +60,8 @@ func reloadHandler(sig os.Signal, cConfig *csconfig.Config) error {
log.Fatalf(err.Error())
}
// Configure logging
if err = types.SetDefaultLoggerConfig(cConfig.Common.LogMedia, cConfig.Common.LogDir, *cConfig.Common.LogLevel); err != nil {
if err = types.SetDefaultLoggerConfig(cConfig.Common.LogMedia, cConfig.Common.LogDir, *cConfig.Common.LogLevel,
cConfig.Common.LogMaxSize, cConfig.Common.LogMaxFiles, cConfig.Common.LogMaxAge, cConfig.Common.CompressLogs); err != nil {
log.Fatal(err.Error())
}

View file

@ -275,7 +275,7 @@ func TestLoggingDebugToFileConfig(t *testing.T) {
os.Remove(expectedFile)
// Configure logging
if err := types.SetDefaultLoggerConfig(cfg.LogMedia, cfg.LogDir, *cfg.LogLevel); err != nil {
if err := types.SetDefaultLoggerConfig(cfg.LogMedia, cfg.LogDir, *cfg.LogLevel, cfg.LogMaxSize, cfg.LogMaxFiles, cfg.LogMaxAge, cfg.CompressLogs); err != nil {
t.Fatal(err.Error())
}
api, err := NewServer(&cfg)
@ -337,7 +337,7 @@ func TestLoggingErrorToFileConfig(t *testing.T) {
os.Remove(expectedFile)
// Configure logging
if err := types.SetDefaultLoggerConfig(cfg.LogMedia, cfg.LogDir, *cfg.LogLevel); err != nil {
if err := types.SetDefaultLoggerConfig(cfg.LogMedia, cfg.LogDir, *cfg.LogLevel, cfg.LogMaxSize, cfg.LogMaxFiles, cfg.LogMaxAge, cfg.CompressLogs); err != nil {
t.Fatal(err.Error())
}
api, err := NewServer(&cfg)

View file

@ -88,6 +88,10 @@ type LocalApiServerCfg struct {
Profiles []*ProfileCfg `yaml:"-"`
LogLevel *log.Level `yaml:"log_level"`
UseForwardedForHeaders bool `yaml:"use_forwarded_for_headers,omitempty"`
CompressLogs *bool `yaml:"-"`
LogMaxSize int `yaml:"-"`
LogMaxAge int `yaml:"-"`
LogMaxFiles int `yaml:"-"`
}
type TLSCfg struct {
@ -102,6 +106,11 @@ func (c *Config) LoadAPIServer() error {
}
c.API.Server.LogDir = c.Common.LogDir
c.API.Server.LogMedia = c.Common.LogMedia
c.API.Server.CompressLogs = c.Common.CompressLogs
c.API.Server.LogMaxSize = c.Common.LogMaxSize
c.API.Server.LogMaxAge = c.Common.LogMaxAge
c.API.Server.LogMaxFiles = c.Common.LogMaxFiles
if err := c.API.Server.LoadProfiles(); err != nil {
return errors.Wrap(err, "while loading profiles for LAPI")
}

View file

@ -10,12 +10,16 @@ import (
/*daemonization/service related stuff*/
type CommonCfg struct {
Daemonize bool
PidDir string `yaml:"pid_dir"`
LogMedia string `yaml:"log_media"`
LogDir string `yaml:"log_dir,omitempty"` //if LogMedia = file
LogLevel *log.Level `yaml:"log_level"`
WorkingDir string `yaml:"working_dir,omitempty"` ///var/run
Daemonize bool
PidDir string `yaml:"pid_dir"`
LogMedia string `yaml:"log_media"`
LogDir string `yaml:"log_dir,omitempty"` //if LogMedia = file
LogLevel *log.Level `yaml:"log_level"`
WorkingDir string `yaml:"working_dir,omitempty"` ///var/run
CompressLogs *bool `yaml:"compress_logs,omitempty"`
LogMaxSize int `yaml:"log_max_size,omitempty"`
LogMaxAge int `yaml:"log_max_age,omitempty"`
LogMaxFiles int `yaml:"log_max_files,omitempty"`
}
func (c *Config) LoadCommon() error {

View file

@ -27,7 +27,7 @@ Default buckets have two main configuration options:
* leakspeed: duration needed for an event to leak. When an event
leaks, it disappear from the bucket.
## Trigger
## Trigger
It's a special type of bucket with a zero capacity. Thus, when an
event is poured in a trigger, it always raises an overflow.

View file

@ -22,16 +22,33 @@ var logFormatter log.Formatter
var LogOutput *lumberjack.Logger //io.Writer
var logLevel log.Level
func SetDefaultLoggerConfig(cfgMode string, cfgFolder string, cfgLevel log.Level) error {
func SetDefaultLoggerConfig(cfgMode string, cfgFolder string, cfgLevel log.Level, maxSize int, maxFiles int, maxAge int, compress *bool) error {
/*Configure logs*/
if cfgMode == "file" {
_maxsize := 500
if maxSize != 0 {
_maxsize = maxSize
}
_maxfiles := 3
if maxFiles != 0 {
_maxfiles = maxFiles
}
_maxage := 28
if maxAge != 0 {
_maxage = maxAge
}
_compress := true
if compress != nil {
_compress = *compress
}
LogOutput = &lumberjack.Logger{
Filename: cfgFolder + "/crowdsec.log",
MaxSize: 500, //megabytes
MaxBackups: 3,
MaxAge: 28, //days
Compress: true, //disabled by default
MaxSize: _maxsize,
MaxBackups: _maxfiles,
MaxAge: _maxage,
Compress: _compress,
}
log.SetOutput(LogOutput)
} else if cfgMode != "stdout" {