Minor changes to specific logs (#900)

- Minor changes to specific logs
- Fix LAPI to not push signals to CAPI when disabled #907
This commit is contained in:
ThinkChaos 2021-08-25 12:30:05 -04:00 committed by GitHub
parent 488f28e3a3
commit 448a227079
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 29 additions and 23 deletions

View file

@ -32,7 +32,7 @@ func NewCapiCmd() *cobra.Command {
log.Fatal("Local API is disabled, please run this command on the local API machine")
}
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
@ -112,11 +112,11 @@ func NewCapiCmd() *cobra.Command {
log.Fatalln("There is no configuration on 'api_client:'")
}
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 {
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)

View file

@ -23,7 +23,7 @@ func NewConsoleCmd() *cobra.Command {
log.Fatal("Local API is disabled, please run this command on the local API machine")
}
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
@ -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")
}
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 {
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
},

View file

@ -35,7 +35,7 @@ func NewLapiCmd() *cobra.Command {
log.Fatalln("There is no API->client configuration")
}
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
},

View file

@ -38,7 +38,7 @@ api:
log_level: info
listen_uri: 127.0.0.1:8080
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
# tls:
# cert_file: /etc/crowdsec/ssl/cert.pem

View file

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

View file

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

View file

@ -37,7 +37,7 @@ api:
log_level: info
listen_uri: 0.0.0.0:8080
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
# tls:
# cert_file: /etc/crowdsec/ssl/cert.pem

View file

@ -166,12 +166,16 @@ func (c *Controller) CreateAlert(gctx *gin.Context) {
for _, alert := range input {
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)
return
}

View file

@ -111,7 +111,7 @@ func (c *Config) LoadAPIServer() error {
}
}
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 {
return err

View file

@ -3,6 +3,7 @@ package parser
import (
"fmt"
"io/ioutil"
"path"
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
@ -36,7 +37,7 @@ func Init(c map[string]interface{}) (*UnixParserCtx, error) {
}
r.DataFolder = c["data"].(string)
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)
return nil, err
}
@ -48,14 +49,15 @@ func Init(c map[string]interface{}) (*UnixParserCtx, error) {
func LoadParsers(cConfig *csconfig.Config, parsers *Parsers) (*Parsers, 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 */
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})
if err != nil {
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})
if err != nil {
return parsers, fmt.Errorf("failed to load postovflw parser patterns : %v", err)

View file

@ -31,7 +31,7 @@ api:
log_level: info
listen_uri: 127.0.0.1:8080
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
# tls:
# cert_file: /etc/crowdsec/ssl/cert.pem

View file

@ -29,7 +29,7 @@ api:
log_level: info
listen_uri: 127.0.0.1:8080
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
# tls:
# cert_file: /etc/crowdsec/ssl/cert.pem