This commit is contained in:
alteredCoder 2022-04-11 12:09:53 +02:00
parent 4f80e889d4
commit f96cb2a70d
3 changed files with 11 additions and 11 deletions

View file

@ -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())

View file

@ -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)

View file

@ -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
}