MCPcopy
hub / github.com/crowdsecurity/crowdsec / NewUnixParserCtx

Function NewUnixParserCtx

pkg/parser/unix_parser.go:37–68  ·  view source on GitHub ↗
(patternDir string, dataDir string)

Source from the content-addressed store, hash-verified

35}
36
37func NewUnixParserCtx(patternDir string, dataDir string) (*UnixParserCtx, error) {
38 r := UnixParserCtx{}
39 r.Grok = grokky.NewBase()
40 // RE2 is enabled by default on linux, but can be disabled with re2_disable_grok_support
41 if runtime.GOOS == "linux" {
42 r.Grok.UseRe2 = !fflag.Re2DisableGrokSupport.IsEnabled()
43 } else {
44 r.Grok.UseRe2 = fflag.Re2GrokSupport.IsEnabled()
45 }
46
47 files, err := os.ReadDir(patternDir)
48 if err != nil {
49 return nil, err
50 }
51
52 r.DataFolder = dataDir
53
54 for _, file := range files {
55 if strings.Contains(file.Name(), ".") || file.IsDir() {
56 continue
57 }
58
59 if err := r.Grok.AddFromFile(filepath.Join(patternDir, file.Name())); err != nil {
60 log.Errorf("failed to load pattern %s: %v", file.Name(), err)
61 return nil, err
62 }
63 }
64
65 log.Debugf("Loaded %d pattern files", len(files))
66
67 return &r, nil
68}
69
70// Return new parsers
71// nodes and povfwnodes are already initialized in parser.LoadStages

Callers 4

LoadParsersFunction · 0.85
TestParserConfigsFunction · 0.85
prepTestsFunction · 0.85
TestGeneratePatternsDocFunction · 0.85

Calls 2

IsEnabledMethod · 0.45
NameMethod · 0.45

Tested by 3

TestParserConfigsFunction · 0.68
prepTestsFunction · 0.68
TestGeneratePatternsDocFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…