mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 12:25:53 +02:00
make CTI client available in cscli notifications (#3591)
This commit is contained in:
parent
5bc2b49387
commit
a79b92f280
1 changed files with 31 additions and 0 deletions
|
@ -30,6 +30,8 @@ import (
|
|||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csplugin"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/csprofiles"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/database"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/exprhelpers"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/models"
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
)
|
||||
|
@ -286,6 +288,14 @@ func (cli *cliNotifications) newTestCmd() *cobra.Command {
|
|||
if !ok {
|
||||
return fmt.Errorf("plugin name: '%s' does not exist", args[0])
|
||||
}
|
||||
|
||||
if cfg.API.CTI != nil && cfg.API.CTI.Enabled != nil && *cfg.API.CTI.Enabled {
|
||||
log.Infof("Crowdsec CTI helper enabled")
|
||||
if err := exprhelpers.InitCrowdsecCTI(cfg.API.CTI.Key, cfg.API.CTI.CacheTimeout, cfg.API.CTI.CacheSize, cfg.API.CTI.LogLevel); err != nil {
|
||||
log.Errorf("failed to init crowdsec cti: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Create a single profile with plugin name as notification name
|
||||
return pluginBroker.Init(ctx, cfg.PluginConfig, []*csconfig.ProfileCfg{
|
||||
{
|
||||
|
@ -393,6 +403,27 @@ cscli notifications reinject <alert_id> -a '{"remediation": true,"scenario":"not
|
|||
}
|
||||
}
|
||||
|
||||
if cfg.API.Server != nil && cfg.API.Server.DbConfig != nil {
|
||||
dbClient, err := database.NewClient(ctx, cfg.API.Server.DbConfig)
|
||||
if err != nil {
|
||||
log.Errorf("failed to get database client: %s", err)
|
||||
}
|
||||
|
||||
err = exprhelpers.Init(dbClient)
|
||||
if err != nil {
|
||||
log.Errorf("failed to init expr helpers: %s", err)
|
||||
}
|
||||
} else {
|
||||
log.Warnf("no database client available, expr helpers will not be available")
|
||||
}
|
||||
|
||||
if cfg.API.CTI != nil && cfg.API.CTI.Enabled != nil && *cfg.API.CTI.Enabled {
|
||||
log.Infof("Crowdsec CTI helper enabled")
|
||||
if err := exprhelpers.InitCrowdsecCTI(cfg.API.CTI.Key, cfg.API.CTI.CacheTimeout, cfg.API.CTI.CacheSize, cfg.API.CTI.LogLevel); err != nil {
|
||||
log.Errorf("failed to init crowdsec cti: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
err := pluginBroker.Init(ctx, cfg.PluginConfig, cfg.API.Server.Profiles, cfg.ConfigPaths)
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't initialize plugins: %w", err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue