diff --git a/cmd/crowdsec-cli/console.go b/cmd/crowdsec-cli/console.go index c2ee8b383..3cf94db91 100644 --- a/cmd/crowdsec-cli/console.go +++ b/cmd/crowdsec-cli/console.go @@ -274,15 +274,15 @@ Disable given information push to the central API.`, Short: "Add label to send with alerts", DisableAutoGenTag: true, Run: func(cmd *cobra.Command, args []string) { - if _, ok := csConfig.API.Server.ConsoleConfig.LabelsToSend[key]; !ok { - csConfig.API.Server.ConsoleConfig.LabelsToSend[key] = make([]string, 0) + if _, ok := csConfig.Crowdsec.LabelsToSend[key]; !ok { + csConfig.Crowdsec.LabelsToSend[key] = make([]string, 0) } - data := csConfig.API.Server.ConsoleConfig.LabelsToSend[key] + data := csConfig.Crowdsec.LabelsToSend[key] for _, val := range values { if !inSlice(val, data) { data = append(data, val) } - csConfig.API.Server.ConsoleConfig.LabelsToSend[key] = data + csConfig.Crowdsec.LabelsToSend[key] = data } if err := csConfig.Crowdsec.DumpLabelConfigFile(); err != nil { log.Fatalf(err.Error()) diff --git a/pkg/csconfig/console.go b/pkg/csconfig/console.go index a68796847..37bc1ac9a 100644 --- a/pkg/csconfig/console.go +++ b/pkg/csconfig/console.go @@ -23,16 +23,14 @@ var CONSOLE_CONFIGS = []string{SEND_CUSTOM_SCENARIOS, SEND_MANUAL_SCENARIOS, SEN var DefaultConsoleConfigFilePath = DefaultConfigPath("console.yaml") type ConsoleConfig struct { - ShareManualDecisions *bool `yaml:"share_manual_decisions"` - ShareTaintedScenarios *bool `yaml:"share_tainted"` - ShareCustomScenarios *bool `yaml:"share_custom"` - ShareLabel *bool `yaml:"share_labels"` - LabelsToSend map[string][]string `yaml:"-"` + ShareManualDecisions *bool `yaml:"share_manual_decisions"` + ShareTaintedScenarios *bool `yaml:"share_tainted"` + ShareCustomScenarios *bool `yaml:"share_custom"` + ShareLabel *bool `yaml:"share_labels"` } func (c *LocalApiServerCfg) LoadConsoleConfig() error { c.ConsoleConfig = &ConsoleConfig{} - c.ConsoleConfig.LabelsToSend = make(map[string][]string) if _, err := os.Stat(c.ConsoleConfigPath); err != nil && os.IsNotExist(err) { log.Debugf("no console configuration to load") c.ConsoleConfig.ShareCustomScenarios = types.BoolPtr(true) diff --git a/pkg/csconfig/crowdsec_service.go b/pkg/csconfig/crowdsec_service.go index f93e06d84..bca616739 100644 --- a/pkg/csconfig/crowdsec_service.go +++ b/pkg/csconfig/crowdsec_service.go @@ -144,9 +144,11 @@ func (c *CrowdsecServiceCfg) DumpLabelConfigFile() error { return errors.Wrapf(err, "while marshaling ConsoleConfig (for %s)", DefaultLabelsConfigFilePath) } - if err := os.WriteFile(DefaultLabelsConfigFilePath, out, 0600); err != nil { + if err := os.WriteFile(c.ConsoleLabelsPath, out, 0600); err != nil { return errors.Wrapf(err, "while dumping console config to %s", DefaultLabelsConfigFilePath) } + log.Infof("%s file saved", c.ConsoleLabelsPath) + return nil }