crowdsec/pkg/parser/unix_parser.go

42 lines
901 B
Go
Raw Normal View History

2020-05-15 09:39:16 +00:00
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 {
2020-05-27 14:31:08 +00:00
Grok grokky.Host
Stages []string
Profiling bool
DataFolder string
2020-05-15 09:39:16 +00:00
}
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
}
2020-05-27 14:31:08 +00:00
r.DataFolder = c["data"].(string)
2020-05-15 09:39:16 +00:00
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
}