Add patterns_dir configuration option (#2868)

* Add patterns_dir configuration option

* Update config.yaml

---------

Co-authored-by: mmetc <92726601+mmetc@users.noreply.github.com>
This commit is contained in:
Christian Kampka 2024-03-25 16:20:16 +01:00 committed by GitHub
parent 2e1ddec107
commit f6bb8412c5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 7 additions and 1 deletions

View file

@ -13,6 +13,7 @@ type ConfigurationPaths struct {
HubDir string `yaml:"hub_dir,omitempty"` HubDir string `yaml:"hub_dir,omitempty"`
PluginDir string `yaml:"plugin_dir,omitempty"` PluginDir string `yaml:"plugin_dir,omitempty"`
NotificationDir string `yaml:"notification_dir,omitempty"` NotificationDir string `yaml:"notification_dir,omitempty"`
PatternDir string `yaml:"pattern_dir,omitempty"`
} }
func (c *Config) loadConfigurationPaths() error { func (c *Config) loadConfigurationPaths() error {
@ -33,6 +34,10 @@ func (c *Config) loadConfigurationPaths() error {
c.ConfigPaths.HubIndexFile = filepath.Clean(c.ConfigPaths.HubDir + "/.index.json") c.ConfigPaths.HubIndexFile = filepath.Clean(c.ConfigPaths.HubDir + "/.index.json")
} }
if c.ConfigPaths.PatternDir == "" {
c.ConfigPaths.PatternDir = filepath.Join(c.ConfigPaths.ConfigDir, "patterns/")
}
var configPathsCleanup = []*string{ var configPathsCleanup = []*string{
&c.ConfigPaths.HubDir, &c.ConfigPaths.HubDir,
&c.ConfigPaths.HubIndexFile, &c.ConfigPaths.HubIndexFile,
@ -41,6 +46,7 @@ func (c *Config) loadConfigurationPaths() error {
&c.ConfigPaths.SimulationFilePath, &c.ConfigPaths.SimulationFilePath,
&c.ConfigPaths.PluginDir, &c.ConfigPaths.PluginDir,
&c.ConfigPaths.NotificationDir, &c.ConfigPaths.NotificationDir,
&c.ConfigPaths.PatternDir,
} }
for _, k := range configPathsCleanup { for _, k := range configPathsCleanup {
if *k == "" { if *k == "" {

View file

@ -98,7 +98,7 @@ func NewParsers(hub *cwhub.Hub) *Parsers {
func LoadParsers(cConfig *csconfig.Config, parsers *Parsers) (*Parsers, error) { func LoadParsers(cConfig *csconfig.Config, parsers *Parsers) (*Parsers, error) {
var err error var err error
patternsDir := filepath.Join(cConfig.ConfigPaths.ConfigDir, "patterns/") patternsDir := cConfig.ConfigPaths.PatternDir
log.Infof("Loading grok library %s", patternsDir) 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": patternsDir, parsers.Ctx, err = Init(map[string]interface{}{"patterns": patternsDir,