瀏覽代碼

Log info capi whitelists (#2220)

* add infof command if err was nil

* Fix golint

* Make message more readable and log individual stats

* Missed a d

* Remove '

* simplify if/else logic

---------

Co-authored-by: Marco Mariani <marco@crowdsec.net>
Laurence Jones 2 年之前
父節點
當前提交
0416a41d58
共有 1 個文件被更改,包括 34 次插入32 次删除
  1. 34 32
      pkg/csconfig/api.go

+ 34 - 32
pkg/csconfig/api.go

@@ -229,42 +229,44 @@ func (c *Config) LoadAPIServer() error {
 		log.Warning("crowdsec local API is disabled from flag")
 	}
 
-	if c.API.Server != nil {
-
-		//inherit log level from common, then api->server
-		var logLevel log.Level
-		if c.API.Server.LogLevel != nil {
-			logLevel = *c.API.Server.LogLevel
-		} else if c.Common.LogLevel != nil {
-			logLevel = *c.Common.LogLevel
-		} else {
-			logLevel = log.InfoLevel
-		}
+	if c.API.Server == nil {
+		log.Warning("crowdsec local API is disabled")
+		c.DisableAPI = true
+		return nil
+	}
 
-		if c.API.Server.PapiLogLevel == nil {
-			c.API.Server.PapiLogLevel = &logLevel
-		}
+	//inherit log level from common, then api->server
+	var logLevel log.Level
+	if c.API.Server.LogLevel != nil {
+		logLevel = *c.API.Server.LogLevel
+	} else if c.Common.LogLevel != nil {
+		logLevel = *c.Common.LogLevel
+	} else {
+		logLevel = log.InfoLevel
+	}
 
-		if c.API.Server.OnlineClient != nil && c.API.Server.OnlineClient.CredentialsFilePath != "" {
-			if err := c.API.Server.OnlineClient.Load(); err != nil {
-				return errors.Wrap(err, "loading online client credentials")
-			}
-		}
-		if c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil {
-			log.Printf("push and pull to Central API disabled")
-		}
-		if err := c.LoadDBConfig(); err != nil {
-			return err
-		}
+	if c.API.Server.PapiLogLevel == nil {
+		c.API.Server.PapiLogLevel = &logLevel
+	}
 
-		if err := c.API.Server.LoadCapiWhitelists(); err != nil {
-			return err
+	if c.API.Server.OnlineClient != nil && c.API.Server.OnlineClient.CredentialsFilePath != "" {
+		if err := c.API.Server.OnlineClient.Load(); err != nil {
+			return errors.Wrap(err, "loading online client credentials")
 		}
+	}
+	if c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil {
+		log.Printf("push and pull to Central API disabled")
+	}
+	if err := c.LoadDBConfig(); err != nil {
+		return err
+	}
 
-	} else {
-		log.Warning("crowdsec local API is disabled")
-		c.DisableAPI = true
-		return nil
+	if err := c.API.Server.LoadCapiWhitelists(); err != nil {
+		return err
+	}
+
+	if c.API.Server.CapiWhitelistsPath != "" {
+		log.Infof("loaded capi whitelist from %s: %d IPs, %d CIDRs", c.API.Server.CapiWhitelistsPath, len(c.API.Server.CapiWhitelists.Ips), len(c.API.Server.CapiWhitelists.Cidrs))
 	}
 
 	if c.API.Server.Enable == nil {
@@ -361,7 +363,7 @@ func (s *LocalApiServerCfg) LoadCapiWhitelists() error {
 	for _, v := range fromCfg.Cidrs {
 		_, tnet, err := net.ParseCIDR(v)
 		if err != nil {
-			return fmt.Errorf("unable to parse cidr whitelist '%s' : %v.", v, err)
+			return fmt.Errorf("unable to parse cidr whitelist '%s' : %v", v, err)
 		}
 		s.CapiWhitelists.Cidrs = append(s.CapiWhitelists.Cidrs, tnet)
 	}