Browse Source

Minor changes to specific logs (#900)

- Minor changes to specific logs
- Fix LAPI to not push signals to CAPI when disabled #907
ThinkChaos 3 years ago
parent
commit
448a227079

+ 3 - 3
cmd/crowdsec-cli/capi.go

@@ -32,7 +32,7 @@ func NewCapiCmd() *cobra.Command {
 				log.Fatal("Local API is disabled, please run this command on the local API machine")
 				log.Fatal("Local API is disabled, please run this command on the local API machine")
 			}
 			}
 			if csConfig.API.Server.OnlineClient == nil {
 			if csConfig.API.Server.OnlineClient == nil {
-				log.Fatalf("no configuration for crowdsec API in '%s'", *csConfig.FilePath)
+				log.Fatalf("no configuration for Central API in '%s'", *csConfig.FilePath)
 			}
 			}
 
 
 			return nil
 			return nil
@@ -112,11 +112,11 @@ func NewCapiCmd() *cobra.Command {
 				log.Fatalln("There is no configuration on 'api_client:'")
 				log.Fatalln("There is no configuration on 'api_client:'")
 			}
 			}
 			if csConfig.API.Server.OnlineClient == nil {
 			if csConfig.API.Server.OnlineClient == nil {
-				log.Fatalf("Please provide credentials for the API in '%s'", csConfig.API.Server.OnlineClient.CredentialsFilePath)
+				log.Fatalf("Please provide credentials for the Central API (CAPI) in '%s'", csConfig.API.Server.OnlineClient.CredentialsFilePath)
 			}
 			}
 
 
 			if csConfig.API.Server.OnlineClient.Credentials == nil {
 			if csConfig.API.Server.OnlineClient.Credentials == nil {
-				log.Fatalf("no credentials for crowdsec API in '%s'", csConfig.API.Server.OnlineClient.CredentialsFilePath)
+				log.Fatalf("no credentials for Central API (CAPI) in '%s'", csConfig.API.Server.OnlineClient.CredentialsFilePath)
 			}
 			}
 
 
 			password := strfmt.Password(csConfig.API.Server.OnlineClient.Credentials.Password)
 			password := strfmt.Password(csConfig.API.Server.OnlineClient.Credentials.Password)

+ 3 - 3
cmd/crowdsec-cli/console.go

@@ -23,7 +23,7 @@ func NewConsoleCmd() *cobra.Command {
 				log.Fatal("Local API is disabled, please run this command on the local API machine")
 				log.Fatal("Local API is disabled, please run this command on the local API machine")
 			}
 			}
 			if csConfig.API.Server.OnlineClient == nil {
 			if csConfig.API.Server.OnlineClient == nil {
-				log.Fatalf("no configuration for crowdsec API in '%s'", *csConfig.FilePath)
+				log.Fatalf("no configuration for Central API (CAPI) in '%s'", *csConfig.FilePath)
 			}
 			}
 
 
 			return nil
 			return nil
@@ -45,10 +45,10 @@ After running this command your will need to validate the enrollment in the weba
 				log.Fatal("Local API is disabled, please run this command on the local API machine")
 				log.Fatal("Local API is disabled, please run this command on the local API machine")
 			}
 			}
 			if csConfig.API.Server.OnlineClient == nil {
 			if csConfig.API.Server.OnlineClient == nil {
-				log.Fatalf("no configuration for crowdsec API in '%s'", *csConfig.FilePath)
+				log.Fatalf("no configuration for Central API (CAPI) in '%s'", *csConfig.FilePath)
 			}
 			}
 			if csConfig.API.Server.OnlineClient.Credentials == nil {
 			if csConfig.API.Server.OnlineClient.Credentials == nil {
-				log.Fatal("You must configure CAPI with `cscli capi register` before enrolling your instance")
+				log.Fatal("You must configure Central API (CAPI) with `cscli capi register` before enrolling your instance")
 			}
 			}
 			return nil
 			return nil
 		},
 		},

+ 1 - 1
cmd/crowdsec-cli/lapi.go

@@ -35,7 +35,7 @@ func NewLapiCmd() *cobra.Command {
 				log.Fatalln("There is no API->client configuration")
 				log.Fatalln("There is no API->client configuration")
 			}
 			}
 			if csConfig.API.Client.Credentials == nil {
 			if csConfig.API.Client.Credentials == nil {
-				log.Fatalf("no configuration for crowdsec API in '%s'", *csConfig.FilePath)
+				log.Fatalf("no configuration for Local API (LAPI) in '%s'", *csConfig.FilePath)
 			}
 			}
 			return nil
 			return nil
 		},
 		},

+ 1 - 1
config/config.yaml

@@ -38,7 +38,7 @@ api:
     log_level: info
     log_level: info
     listen_uri: 127.0.0.1:8080
     listen_uri: 127.0.0.1:8080
     profiles_path: /etc/crowdsec/profiles.yaml
     profiles_path: /etc/crowdsec/profiles.yaml
-    online_client: # Crowdsec API credentials (to push signals and receive bad IPs)
+    online_client: # Central API credentials (to push signals and receive bad IPs)
       credentials_path: /etc/crowdsec/online_api_credentials.yaml
       credentials_path: /etc/crowdsec/online_api_credentials.yaml
 #    tls:
 #    tls:
 #      cert_file: /etc/crowdsec/ssl/cert.pem
 #      cert_file: /etc/crowdsec/ssl/cert.pem

+ 1 - 1
config/dev.yaml

@@ -36,7 +36,7 @@ api:
     tls:
     tls:
       #cert_file: ./cert.pem
       #cert_file: ./cert.pem
       #key_file: ./key.pem
       #key_file: ./key.pem
-    online_client: # Crowdsec API
+    online_client: # Central API
       credentials_path: ./config/online_api_credentials.yaml
       credentials_path: ./config/online_api_credentials.yaml
 prometheus:
 prometheus:
   enabled: true
   enabled: true

+ 1 - 1
config/user.yaml

@@ -33,7 +33,7 @@ api:
     #log_level: info
     #log_level: info
     listen_uri: 127.0.0.1:8080
     listen_uri: 127.0.0.1:8080
     profiles_path: /etc/crowdsec/profiles.yaml
     profiles_path: /etc/crowdsec/profiles.yaml
-    online_client: # Crowdsec API
+    online_client: # Central API
       credentials_path: /etc/crowdsec/online_api_credentials.yaml
       credentials_path: /etc/crowdsec/online_api_credentials.yaml
 prometheus:
 prometheus:
   enabled: true
   enabled: true

+ 1 - 1
docker/config.yaml

@@ -37,7 +37,7 @@ api:
     log_level: info
     log_level: info
     listen_uri: 0.0.0.0:8080
     listen_uri: 0.0.0.0:8080
     profiles_path: /etc/crowdsec/profiles.yaml
     profiles_path: /etc/crowdsec/profiles.yaml
-    online_client: # Crowdsec API credentials (to push signals and receive bad IPs)
+    online_client: # Central API credentials (to push signals and receive bad IPs)
       #credentials_path: /etc/crowdsec/online_api_credentials.yaml
       #credentials_path: /etc/crowdsec/online_api_credentials.yaml
 #    tls:
 #    tls:
 #      cert_file: /etc/crowdsec/ssl/cert.pem
 #      cert_file: /etc/crowdsec/ssl/cert.pem

+ 9 - 5
pkg/apiserver/controllers/v1/alerts.go

@@ -166,12 +166,16 @@ func (c *Controller) CreateAlert(gctx *gin.Context) {
 	for _, alert := range input {
 	for _, alert := range input {
 		alert.MachineID = machineID
 		alert.MachineID = machineID
 	}
 	}
-	select {
-	case c.CAPIChan <- input:
-		log.Debugf("alert sent to CAPI channel")
-	default:
-		log.Warningf("Cannot send alert to Central API channel")
+
+  	if c.CAPIChan != nil {
+		select {
+		case c.CAPIChan <- input:
+			log.Debug("alert sent to CAPI channel")
+		default:
+			log.Warning("Cannot send alert to Central API channel")
+		}
 	}
 	}
+
 	gctx.JSON(http.StatusCreated, alerts)
 	gctx.JSON(http.StatusCreated, alerts)
 	return
 	return
 }
 }

+ 1 - 1
pkg/csconfig/api.go

@@ -111,7 +111,7 @@ func (c *Config) LoadAPIServer() error {
 			}
 			}
 		}
 		}
 		if c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil {
 		if c.API.Server.OnlineClient == nil || c.API.Server.OnlineClient.Credentials == nil {
-			log.Printf("push and pull to crowdsec API disabled")
+			log.Printf("push and pull to Central API disabled")
 		}
 		}
 		if err := c.LoadDBConfig(); err != nil {
 		if err := c.LoadDBConfig(); err != nil {
 			return err
 			return err

+ 6 - 4
pkg/parser/unix_parser.go

@@ -3,6 +3,7 @@ package parser
 import (
 import (
 	"fmt"
 	"fmt"
 	"io/ioutil"
 	"io/ioutil"
+        "path"
 
 
 	"github.com/crowdsecurity/crowdsec/pkg/csconfig"
 	"github.com/crowdsecurity/crowdsec/pkg/csconfig"
 
 
@@ -36,7 +37,7 @@ func Init(c map[string]interface{}) (*UnixParserCtx, error) {
 	}
 	}
 	r.DataFolder = c["data"].(string)
 	r.DataFolder = c["data"].(string)
 	for _, f := range files {
 	for _, f := range files {
-		if err := r.Grok.AddFromFile(c["patterns"].(string) + f.Name()); err != nil {
+		if err := r.Grok.AddFromFile(path.Join(c["patterns"].(string), f.Name())); err != nil {
 			log.Errorf("failed to load pattern %s : %v", f.Name(), err)
 			log.Errorf("failed to load pattern %s : %v", f.Name(), err)
 			return nil, err
 			return nil, err
 		}
 		}
@@ -48,14 +49,15 @@ func Init(c map[string]interface{}) (*UnixParserCtx, error) {
 func LoadParsers(cConfig *csconfig.Config, parsers *Parsers) (*Parsers, error) {
 func LoadParsers(cConfig *csconfig.Config, parsers *Parsers) (*Parsers, error) {
 	var err error
 	var err error
 
 
-	log.Infof("Loading grok library %s", cConfig.Crowdsec.ConfigDir+string("/patterns/"))
+	patternsDir := path.Join(cConfig.Crowdsec.ConfigDir, "patterns/")
+	log.Infof("Loading grok library %s", patternsDir)
 	/* load base regexps for two grok parsers */
 	/* load base regexps for two grok parsers */
-	parsers.Ctx, err = Init(map[string]interface{}{"patterns": cConfig.Crowdsec.ConfigDir + string("/patterns/"),
+	parsers.Ctx, err = Init(map[string]interface{}{"patterns": patternsDir,
 		"data": cConfig.Crowdsec.DataDir})
 		"data": cConfig.Crowdsec.DataDir})
 	if err != nil {
 	if err != nil {
 		return parsers, fmt.Errorf("failed to load parser patterns : %v", err)
 		return parsers, fmt.Errorf("failed to load parser patterns : %v", err)
 	}
 	}
-	parsers.Povfwctx, err = Init(map[string]interface{}{"patterns": cConfig.Crowdsec.ConfigDir + string("/patterns/"),
+	parsers.Povfwctx, err = Init(map[string]interface{}{"patterns": patternsDir,
 		"data": cConfig.Crowdsec.DataDir})
 		"data": cConfig.Crowdsec.DataDir})
 	if err != nil {
 	if err != nil {
 		return parsers, fmt.Errorf("failed to load postovflw parser patterns : %v", err)
 		return parsers, fmt.Errorf("failed to load postovflw parser patterns : %v", err)

+ 1 - 1
scripts/func_tests/config/config.yaml

@@ -31,7 +31,7 @@ api:
     log_level: info
     log_level: info
     listen_uri: 127.0.0.1:8080
     listen_uri: 127.0.0.1:8080
     profiles_path: /etc/crowdsec/profiles.yaml
     profiles_path: /etc/crowdsec/profiles.yaml
-    online_client: # Crowdsec API credentials (to push signals and receive bad IPs)
+    online_client: # Central API credentials (to push signals and receive bad IPs)
       credentials_path: /etc/crowdsec/online_api_credentials.yaml
       credentials_path: /etc/crowdsec/online_api_credentials.yaml
 #    tls:
 #    tls:
 #      cert_file: /etc/crowdsec/ssl/cert.pem
 #      cert_file: /etc/crowdsec/ssl/cert.pem

+ 1 - 1
scripts/func_tests/config/config_no_agent.yaml

@@ -29,7 +29,7 @@ api:
     log_level: info
     log_level: info
     listen_uri: 127.0.0.1:8080
     listen_uri: 127.0.0.1:8080
     profiles_path: /etc/crowdsec/profiles.yaml
     profiles_path: /etc/crowdsec/profiles.yaml
-    online_client: # Crowdsec API credentials (to push signals and receive bad IPs)
+    online_client: # Central API credentials (to push signals and receive bad IPs)
       credentials_path: /etc/crowdsec/online_api_credentials.yaml
       credentials_path: /etc/crowdsec/online_api_credentials.yaml
 #    tls:
 #    tls:
 #      cert_file: /etc/crowdsec/ssl/cert.pem
 #      cert_file: /etc/crowdsec/ssl/cert.pem