Compare commits
1 commit
master
...
grok-concu
Author | SHA1 | Date | |
---|---|---|---|
|
d0aba7dd9a |
1 changed files with 22 additions and 3 deletions
|
@ -10,6 +10,7 @@ import (
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
"github.com/crowdsecurity/crowdsec/pkg/csconfig"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
"github.com/crowdsecurity/crowdsec/pkg/cwhub"
|
||||||
"github.com/crowdsecurity/crowdsec/pkg/fflag"
|
"github.com/crowdsecurity/crowdsec/pkg/fflag"
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
"github.com/crowdsecurity/grokky"
|
"github.com/crowdsecurity/grokky"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
@ -41,14 +42,32 @@ func Init(c map[string]interface{}) (*UnixParserCtx, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
r.DataFolder = c["data"].(string)
|
r.DataFolder = c["data"].(string)
|
||||||
|
filesList := make([]string, 0)
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
if strings.Contains(f.Name(), ".") {
|
if strings.Contains(f.Name(), ".") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := r.Grok.AddFromFile(path.Join(c["patterns"].(string), f.Name())); err != nil {
|
filesList = append(filesList, path.Join(c["patterns"].(string), f.Name()))
|
||||||
log.Errorf("failed to load pattern %s : %v", f.Name(), err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
g := new(errgroup.Group)
|
||||||
|
for i := 0; i < len(filesList); i += 10 {
|
||||||
|
start := i
|
||||||
|
end := start + 10
|
||||||
|
if end > len(filesList) {
|
||||||
|
end = len(filesList)
|
||||||
|
}
|
||||||
|
g.Go(func() error {
|
||||||
|
for _, f := range filesList[start:end] {
|
||||||
|
if err := r.Grok.AddFromFile(f); err != nil {
|
||||||
|
log.Errorf("failed to load pattern %s : %v", f, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if err := g.Wait(); err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
log.Debugf("Loaded %d pattern files", len(files))
|
log.Debugf("Loaded %d pattern files", len(files))
|
||||||
return &r, nil
|
return &r, nil
|
||||||
|
|
Loading…
Reference in a new issue