added flag crowdsec --warning (#1461)

This commit is contained in:
mmetc 2022-06-22 09:38:23 +02:00 committed by GitHub
parent c78c833400
commit d71279f023
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 46 additions and 40 deletions

View file

@ -98,7 +98,7 @@ func NewCapiCmd() *cobra.Command {
fmt.Printf("%s\n", string(apiConfigDump)) fmt.Printf("%s\n", string(apiConfigDump))
} }
log.Warningf(ReloadMessage()) log.Warning(ReloadMessage())
}, },
} }
cmdCapiRegister.Flags().StringVarP(&outputFile, "file", "f", "", "output file destination") cmdCapiRegister.Flags().StringVarP(&outputFile, "file", "f", "", "output file destination")

View file

@ -108,7 +108,7 @@ After running this command your will need to validate the enrollment in the weba
log.Fatalf("Could not enroll instance: %s", err) log.Fatalf("Could not enroll instance: %s", err)
} }
if resp.Response.StatusCode == 200 && !overwrite { if resp.Response.StatusCode == 200 && !overwrite {
log.Warningf("Instance already enrolled. You can use '--overwrite' to force enroll") log.Warning("Instance already enrolled. You can use '--overwrite' to force enroll")
return return
} }

View file

@ -111,7 +111,7 @@ Keep in mind the machine needs to be validated by an administrator on LAPI side
} else { } else {
fmt.Printf("%s\n", string(apiConfigDump)) fmt.Printf("%s\n", string(apiConfigDump))
} }
log.Warningf(ReloadMessage()) log.Warning(ReloadMessage())
}, },
} }
cmdLapiRegister.Flags().StringVarP(&apiURL, "url", "u", "", "URL of the API (ie. http://127.0.0.1)") cmdLapiRegister.Flags().StringVarP(&apiURL, "url", "u", "", "URL of the API (ie. http://127.0.0.1)")

View file

@ -400,7 +400,7 @@ func NewMetricsCmd() *cobra.Command {
log.Fatalf(err.Error()) log.Fatalf(err.Error())
} }
if !csConfig.Prometheus.Enabled { if !csConfig.Prometheus.Enabled {
log.Warningf("Prometheus is not enabled, can't show metrics") log.Warning("Prometheus is not enabled, can't show metrics")
os.Exit(1) os.Exit(1)
} }

View file

@ -123,7 +123,7 @@ func runCrowdsec(cConfig *csconfig.Config, parsers *parser.Parsers) error {
} }
} }
log.Warningf("Starting processing data") log.Info("Starting processing data")
if err := acquisition.StartAcquisition(dataSources, inputLineChan, &acquisTomb); err != nil { if err := acquisition.StartAcquisition(dataSources, inputLineChan, &acquisTomb); err != nil {
log.Fatalf("starting acquisition error : %s", err) log.Fatalf("starting acquisition error : %s", err)
@ -228,7 +228,7 @@ func waitOnTomb() {
case <-acquisTomb.Dead(): case <-acquisTomb.Dead():
/*if it's acquisition dying it means that we were in "cat" mode. /*if it's acquisition dying it means that we were in "cat" mode.
while shutting down, we need to give time for all buckets to process in flight data*/ while shutting down, we need to give time for all buckets to process in flight data*/
log.Warningf("Acquisition is finished, shutting down") log.Warning("Acquisition is finished, shutting down")
/* /*
While it might make sense to want to shut-down parser/buckets/etc. as soon as acquisition is finished, While it might make sense to want to shut-down parser/buckets/etc. as soon as acquisition is finished,
we might have some pending buckets: buckets that overflowed, but whose LeakRoutine are still alive because they we might have some pending buckets: buckets that overflowed, but whose LeakRoutine are still alive because they

View file

@ -57,6 +57,7 @@ type Flags struct {
TraceLevel bool TraceLevel bool
DebugLevel bool DebugLevel bool
InfoLevel bool InfoLevel bool
WarnLevel bool
PrintVersion bool PrintVersion bool
SingleFileType string SingleFileType string
Labels map[string]string Labels map[string]string
@ -181,8 +182,9 @@ func (f *Flags) Parse() {
flag.StringVar(&f.ConfigFile, "c", csconfig.DefaultConfigPath("config.yaml"), "configuration file") flag.StringVar(&f.ConfigFile, "c", csconfig.DefaultConfigPath("config.yaml"), "configuration file")
flag.BoolVar(&f.TraceLevel, "trace", false, "VERY verbose") flag.BoolVar(&f.TraceLevel, "trace", false, "VERY verbose")
flag.BoolVar(&f.DebugLevel, "debug", false, "print debug-level on stdout") flag.BoolVar(&f.DebugLevel, "debug", false, "print debug-level on stderr")
flag.BoolVar(&f.InfoLevel, "info", false, "print info-level on stdout") flag.BoolVar(&f.InfoLevel, "info", false, "print info-level on stderr")
flag.BoolVar(&f.WarnLevel, "warning", false, "print warning-level on stderr")
flag.BoolVar(&f.PrintVersion, "version", false, "display version") flag.BoolVar(&f.PrintVersion, "version", false, "display version")
flag.StringVar(&f.OneShotDSN, "dsn", "", "Process a single data source in time-machine") flag.StringVar(&f.OneShotDSN, "dsn", "", "Process a single data source in time-machine")
flag.StringVar(&f.SingleFileType, "type", "", "Labels.type for file in time-machine") flag.StringVar(&f.SingleFileType, "type", "", "Labels.type for file in time-machine")
@ -224,14 +226,18 @@ func LoadConfig(cConfig *csconfig.Config) error {
return errors.New("You must run at least the API Server or crowdsec") return errors.New("You must run at least the API Server or crowdsec")
} }
if flags.DebugLevel { if flags.WarnLevel {
logLevel := log.DebugLevel logLevel := log.WarnLevel
cConfig.Common.LogLevel = &logLevel cConfig.Common.LogLevel = &logLevel
} }
if flags.InfoLevel || cConfig.Common.LogLevel == nil { if flags.InfoLevel || cConfig.Common.LogLevel == nil {
logLevel := log.InfoLevel logLevel := log.InfoLevel
cConfig.Common.LogLevel = &logLevel cConfig.Common.LogLevel = &logLevel
} }
if flags.DebugLevel {
logLevel := log.DebugLevel
cConfig.Common.LogLevel = &logLevel
}
if flags.TraceLevel { if flags.TraceLevel {
logLevel := log.TraceLevel logLevel := log.TraceLevel
cConfig.Common.LogLevel = &logLevel cConfig.Common.LogLevel = &logLevel

View file

@ -67,11 +67,11 @@ func registerPrometheus(config *csconfig.PrometheusCfg) {
return return
} }
if config.ListenAddr == "" { if config.ListenAddr == "" {
log.Warningf("prometheus is enabled, but the listen address is empty, using '127.0.0.1'") log.Warning("prometheus is enabled, but the listen address is empty, using '127.0.0.1'")
config.ListenAddr = "127.0.0.1" config.ListenAddr = "127.0.0.1"
} }
if config.ListenPort == 0 { if config.ListenPort == 0 {
log.Warningf("prometheus is enabled, but the listen port is empty, using '6060'") log.Warning("prometheus is enabled, but the listen port is empty, using '6060'")
config.ListenPort = 6060 config.ListenPort = 6060
} }

View file

@ -31,7 +31,7 @@ func runPour(input chan types.Event, holders []leaky.BucketFactory, buckets *lea
if err := z.UnmarshalText([]byte(parsed.MarshaledTime)); err != nil { if err := z.UnmarshalText([]byte(parsed.MarshaledTime)); err != nil {
log.Warningf("Failed to unmarshal time from event '%s' : %s", parsed.MarshaledTime, err) log.Warningf("Failed to unmarshal time from event '%s' : %s", parsed.MarshaledTime, err)
} else { } else {
log.Warningf("Starting buckets garbage collection ...") log.Warning("Starting buckets garbage collection ...")
if err = leaky.GarbageCollectBuckets(*z, buckets); err != nil { if err = leaky.GarbageCollectBuckets(*z, buckets); err != nil {
return fmt.Errorf("failed to start bucket GC : %s", err) return fmt.Errorf("failed to start bucket GC : %s", err)
} }

View file

@ -191,7 +191,7 @@ func HandleSignals(cConfig *csconfig.Config) error {
switch s { switch s {
// kill -SIGHUP XXXX // kill -SIGHUP XXXX
case syscall.SIGHUP: case syscall.SIGHUP:
log.Warningf("SIGHUP received, reloading") log.Warning("SIGHUP received, reloading")
if err := shutdown(s, cConfig); err != nil { if err := shutdown(s, cConfig); err != nil {
exitChan <- errors.Wrap(err, "failed shutdown") exitChan <- errors.Wrap(err, "failed shutdown")
break Loop break Loop
@ -202,7 +202,7 @@ func HandleSignals(cConfig *csconfig.Config) error {
} }
// ctrl+C, kill -SIGINT XXXX, kill -SIGTERM XXXX // ctrl+C, kill -SIGINT XXXX, kill -SIGTERM XXXX
case os.Interrupt, syscall.SIGTERM: case os.Interrupt, syscall.SIGTERM:
log.Warningf("SIGTERM received, shutting down") log.Warning("SIGTERM received, shutting down")
if err := shutdown(s, cConfig); err != nil { if err := shutdown(s, cConfig); err != nil {
exitChan <- errors.Wrap(err, "failed shutdown") exitChan <- errors.Wrap(err, "failed shutdown")
break Loop break Loop
@ -214,7 +214,7 @@ func HandleSignals(cConfig *csconfig.Config) error {
err := <-exitChan err := <-exitChan
if err == nil { if err == nil {
log.Warningf("Crowdsec service shutting down") log.Warning("Crowdsec service shutting down")
} }
return err return err
} }

View file

@ -475,7 +475,7 @@ func (a *apic) Pull() error {
break break
} }
if !toldOnce { if !toldOnce {
log.Warningf("scenario list is empty, will not pull yet") log.Warning("scenario list is empty, will not pull yet")
toldOnce = true toldOnce = true
} }
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)

View file

@ -207,7 +207,7 @@ func (c *Config) LoadAPIServer() error {
return err return err
} }
} else { } else {
log.Warningf("crowdsec local API is disabled") log.Warning("crowdsec local API is disabled")
c.DisableAPI = true c.DisableAPI = true
} }

View file

@ -39,7 +39,7 @@ func (c *Config) LoadCrowdsec() error {
} }
if c.Crowdsec == nil { if c.Crowdsec == nil {
log.Warningf("crowdsec agent is disabled") log.Warning("crowdsec agent is disabled")
c.DisableAgent = true c.DisableAgent = true
return nil return nil
} }
@ -68,7 +68,7 @@ func (c *Config) LoadCrowdsec() error {
c.Crowdsec.AcquisitionFiles = append(c.Crowdsec.AcquisitionFiles, files...) c.Crowdsec.AcquisitionFiles = append(c.Crowdsec.AcquisitionFiles, files...)
} }
if c.Crowdsec.AcquisitionDirPath == "" && c.Crowdsec.AcquisitionFilePath == "" { if c.Crowdsec.AcquisitionDirPath == "" && c.Crowdsec.AcquisitionFilePath == "" {
log.Warningf("no acquisition_path nor acquisition_dir") log.Warning("no acquisition_path nor acquisition_dir")
} }
if err := c.LoadSimulation(); err != nil { if err := c.LoadSimulation(); err != nil {
return errors.Wrap(err, "load error (simulation)") return errors.Wrap(err, "load error (simulation)")

View file

@ -31,7 +31,7 @@ func chooseHubBranch() (string, error) {
} }
if csVersion == "" { if csVersion == "" {
log.Warningf("Crowdsec version is not set, using master branch for the hub") log.Warning("Crowdsec version is not set, using master branch for the hub")
return "master", nil return "master", nil
} }

View file

@ -182,7 +182,7 @@ func (c *Client) UpdateCommunityBlocklist(alertItem *models.Alert) (int, int, in
var start_ip, start_sfx, end_ip, end_sfx int64 var start_ip, start_sfx, end_ip, end_sfx int64
var sz int var sz int
if decisionItem.Duration == nil { if decisionItem.Duration == nil {
log.Warningf("nil duration in community decision") log.Warning("nil duration in community decision")
continue continue
} }
duration, err := time.ParseDuration(*decisionItem.Duration) duration, err := time.ParseDuration(*decisionItem.Duration)
@ -190,7 +190,7 @@ func (c *Client) UpdateCommunityBlocklist(alertItem *models.Alert) (int, int, in
return 0, 0, 0, errors.Wrapf(ParseDurationFail, "decision duration '%v' : %s", decisionItem.Duration, err) return 0, 0, 0, errors.Wrapf(ParseDurationFail, "decision duration '%v' : %s", decisionItem.Duration, err)
} }
if decisionItem.Scope == nil { if decisionItem.Scope == nil {
log.Warningf("nil scope in community decision") log.Warning("nil scope in community decision")
continue continue
} }
/*if the scope is IP or Range, convert the value to integers */ /*if the scope is IP or Range, convert the value to integers */
@ -218,7 +218,7 @@ func (c *Client) UpdateCommunityBlocklist(alertItem *models.Alert) (int, int, in
/*for bulk delete of duplicate decisions*/ /*for bulk delete of duplicate decisions*/
if decisionItem.Value == nil { if decisionItem.Value == nil {
log.Warningf("nil value in community decision") log.Warning("nil value in community decision")
continue continue
} }
valueList = append(valueList, *decisionItem.Value) valueList = append(valueList, *decisionItem.Value)

View file

@ -150,7 +150,7 @@ func (c *Client) StartFlushScheduler(config *csconfig.FlushDBCfg) (*gocron.Sched
config.AgentsGC.LoginPasswordDuration = &duration config.AgentsGC.LoginPasswordDuration = &duration
} }
if config.AgentsGC.Api != nil { if config.AgentsGC.Api != nil {
log.Warningf("agents auto-delete for API auth is not supported (use cert or login_password)") log.Warning("agents auto-delete for API auth is not supported (use cert or login_password)")
} }
} }
if config.BouncersGC != nil { if config.BouncersGC != nil {
@ -169,7 +169,7 @@ func (c *Client) StartFlushScheduler(config *csconfig.FlushDBCfg) (*gocron.Sched
config.BouncersGC.ApiDuration = &duration config.BouncersGC.ApiDuration = &duration
} }
if config.BouncersGC.LoginPassword != nil { if config.BouncersGC.LoginPassword != nil {
log.Warningf("bouncers auto-delete for login/password auth is not supported (use cert or api)") log.Warning("bouncers auto-delete for login/password auth is not supported (use cert or api)")
} }
} }
baJob, err := scheduler.Every(1).Minute().Do(c.FlushAgentsAndBouncers, config.AgentsGC, config.BouncersGC) baJob, err := scheduler.Every(1).Minute().Do(c.FlushAgentsAndBouncers, config.AgentsGC, config.BouncersGC)

View file

@ -69,7 +69,7 @@ func TestBucket(t *testing.T) {
func watchTomb(tomb *tomb.Tomb) { func watchTomb(tomb *tomb.Tomb) {
for { for {
if tomb.Alive() == false { if tomb.Alive() == false {
log.Warningf("Tomb is dead") log.Warning("Tomb is dead")
break break
} }
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
@ -158,7 +158,7 @@ func testFile(t *testing.T, file string, bs string, holders []BucketFactory, res
t.Errorf("Failed to load testfile '%s' yaml error : %v", file, err) t.Errorf("Failed to load testfile '%s' yaml error : %v", file, err)
return false return false
} }
log.Warningf("end of test file") log.Warning("end of test file")
} }
var latest_ts time.Time var latest_ts time.Time
for _, in := range tf.Lines { for _, in := range tf.Lines {
@ -181,10 +181,10 @@ func testFile(t *testing.T, file string, bs string, holders []BucketFactory, res
t.Fatalf("Failed to pour : %s", err) t.Fatalf("Failed to pour : %s", err)
} }
if !ok { if !ok {
log.Warningf("Event wasn't poured") log.Warning("Event wasn't poured")
} }
} }
log.Warningf("Done pouring !") log.Warning("Done pouring !")
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
@ -194,7 +194,7 @@ POLL_AGAIN:
for fails < 2 { for fails < 2 {
select { select {
case ret := <-response: case ret := <-response:
log.Warningf("got one result") log.Warning("got one result")
results = append(results, ret) results = append(results, ret)
if ret.Overflow.Reprocess { if ret.Overflow.Reprocess {
log.Errorf("Overflow being reprocessed.") log.Errorf("Overflow being reprocessed.")
@ -203,13 +203,13 @@ POLL_AGAIN:
t.Fatalf("Failed to pour : %s", err) t.Fatalf("Failed to pour : %s", err)
} }
if !ok { if !ok {
log.Warningf("Event wasn't poured") log.Warning("Event wasn't poured")
} }
goto POLL_AGAIN goto POLL_AGAIN
} }
fails = 0 fails = 0
default: default:
log.Warningf("no more results") log.Warning("no more results")
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
fails += 1 fails += 1
} }
@ -223,7 +223,7 @@ POLL_AGAIN:
for { for {
if len(tf.Results) == 0 && len(results) == 0 { if len(tf.Results) == 0 && len(results) == 0 {
log.Warningf("Test is successful") log.Warning("Test is successful")
if dump { if dump {
if tmpFile, err = DumpBucketsStateAt(latest_ts, ".", buckets); err != nil { if tmpFile, err = DumpBucketsStateAt(latest_ts, ".", buckets); err != nil {
t.Fatalf("Failed dumping bucket state : %s", err) t.Fatalf("Failed dumping bucket state : %s", err)
@ -305,6 +305,6 @@ POLL_AGAIN:
log.Errorf("we expected: %s", spew.Sdump(tf.Results)) log.Errorf("we expected: %s", spew.Sdump(tf.Results))
return false return false
} }
log.Warningf("entry valid at end of loop") log.Warning("entry valid at end of loop")
} }
} }

View file

@ -266,7 +266,7 @@ func LoadBucket(bucketFactory *BucketFactory, tomb *tomb.Tomb) error {
} }
if bucketFactory.Filter == "" { if bucketFactory.Filter == "" {
bucketFactory.logger.Warningf("Bucket without filter, abort.") bucketFactory.logger.Warning("Bucket without filter, abort.")
return fmt.Errorf("bucket without filter directive") return fmt.Errorf("bucket without filter directive")
} }
bucketFactory.RunTimeFilter, err = expr.Compile(bucketFactory.Filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}}))) bucketFactory.RunTimeFilter, err = expr.Compile(bucketFactory.Filter, expr.Env(exprhelpers.GetExprEnv(map[string]interface{}{"evt": &types.Event{}})))

View file

@ -198,7 +198,7 @@ func EventsFromQueue(queue *Queue) []*models.Event {
*ovflwEvent.Timestamp = string(raw) *ovflwEvent.Timestamp = string(raw)
} }
} else { } else {
log.Warningf("Event has no parsed time, no runtime timestamp") log.Warning("Event has no parsed time, no runtime timestamp")
} }
events = append(events, &ovflwEvent) events = append(events, &ovflwEvent)

View file

@ -47,7 +47,7 @@ func GenDateParse(date string) (string, time.Time) {
now := time.Now().UTC() now := time.Now().UTC()
retstr, err := now.MarshalText() retstr, err := now.MarshalText()
if err != nil { if err != nil {
log.Warningf("Failed marshaling current time") log.Warning("Failed marshaling current time")
return "", time.Time{} return "", time.Time{}
} }
return string(retstr), now return string(retstr), now

View file

@ -193,7 +193,7 @@ func (n *Node) process(p *types.Event, ctx UnixParserCtx, expressionEnv map[stri
output, err := expr.Run(e.Filter, cachedExprEnv) output, err := expr.Run(e.Filter, cachedExprEnv)
if err != nil { if err != nil {
clog.Warningf("failed to run whitelist expr : %v", err) clog.Warningf("failed to run whitelist expr : %v", err)
clog.Debugf("Event leaving node : ko") clog.Debug("Event leaving node : ko")
return false, nil return false, nil
} }
switch out := output.(type) { switch out := output.(type) {

View file

@ -334,7 +334,7 @@ reCheck:
} }
func testFile(testSet []TestFile, pctx UnixParserCtx, nodes []Node) bool { func testFile(testSet []TestFile, pctx UnixParserCtx, nodes []Node) bool {
log.Warningf("Going to process one test set") log.Warning("Going to process one test set")
for _, tf := range testSet { for _, tf := range testSet {
//func testSubSet(testSet TestFile, pctx UnixParserCtx, nodes []Node) (bool, error) { //func testSubSet(testSet TestFile, pctx UnixParserCtx, nodes []Node) (bool, error) {
testOk, err := testSubSet(tf, pctx, nodes) testOk, err := testSubSet(tf, pctx, nodes)