mirror of
https://github.com/crowdsecurity/crowdsec.git
synced 2025-05-11 04:15:54 +02:00
initial import
This commit is contained in:
parent
36fbed6ee8
commit
2016167654
299 changed files with 21245 additions and 0 deletions
39
pkg/parser/unix_parser.go
Normal file
39
pkg/parser/unix_parser.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package parser
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/crowdsecurity/crowdsec/pkg/types"
|
||||
"github.com/logrusorgru/grokky"
|
||||
"github.com/prometheus/common/log"
|
||||
)
|
||||
|
||||
type UnixParser struct {
|
||||
}
|
||||
|
||||
type UnixParserCtx struct {
|
||||
Grok grokky.Host
|
||||
Stages []string
|
||||
Profiling bool
|
||||
}
|
||||
|
||||
func (u UnixParser) IsParsable(ctx interface{}, l types.Line) (bool, error) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (u UnixParser) Init(c map[string]interface{}) (*UnixParserCtx, error) {
|
||||
r := UnixParserCtx{}
|
||||
r.Grok = grokky.NewBase()
|
||||
files, err := ioutil.ReadDir(c["patterns"].(string))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, f := range files {
|
||||
log.Debugf("Loading %s", f.Name())
|
||||
if err := r.Grok.AddFromFile(c["patterns"].(string) + f.Name()); err != nil {
|
||||
log.Errorf("failed to load pattern %s : %v", f.Name(), err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &r, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue