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

Function LoadParsers

pkg/parser/unix_parser.go:108–174  ·  view source on GitHub ↗
(cConfig *csconfig.Config, hub *cwhub.Hub)

Source from the content-addressed store, hash-verified

106}
107
108func LoadParsers(cConfig *csconfig.Config, hub *cwhub.Hub) (*Parsers, error) {
109 var err error
110
111 patternDir := cConfig.ConfigPaths.PatternDir
112 log.Infof("Loading grok library %s", patternDir)
113
114 parsers := NewParsers(hub)
115
116 /* load base regexps for two grok parsers */
117 parsers.Ctx, err = NewUnixParserCtx(patternDir, cConfig.ConfigPaths.DataDir)
118 if err != nil {
119 return nil, fmt.Errorf("failed to load parser patterns: %w", err)
120 }
121
122 parsers.PovfwCtx, err = NewUnixParserCtx(patternDir, cConfig.ConfigPaths.DataDir)
123 if err != nil {
124 return nil, fmt.Errorf("failed to load postovflw parser patterns: %w", err)
125 }
126
127 /*
128 Load enrichers
129 */
130 log.Info("Loading enrich plugins")
131
132 parsers.EnricherCtx, err = Loadplugin()
133 if err != nil {
134 return nil, fmt.Errorf("failed to load enrich plugin: %w", err)
135 }
136
137 /*
138 Load the actual parsers
139 */
140
141 log.Infof("Loading parsers from %d files", len(parsers.StageFiles))
142
143 parsers.Nodes, err = LoadStages(parsers.StageFiles, parsers.Ctx, parsers.EnricherCtx)
144 if err != nil {
145 return nil, fmt.Errorf("failed to load parser config: %w", err)
146 }
147
148 if len(parsers.PovfwStageFiles) > 0 {
149 log.Info("Loading postoverflow parsers")
150
151 parsers.Povfwnodes, err = LoadStages(parsers.PovfwStageFiles, parsers.PovfwCtx, parsers.EnricherCtx)
152 if err != nil {
153 return nil, fmt.Errorf("failed to load postoverflow config: %w", err)
154 }
155 } else {
156 log.Info("No postoverflow parsers to load")
157
158 parsers.Povfwnodes = []Node{}
159 }
160
161 if cConfig.Prometheus != nil && cConfig.Prometheus.Enabled {
162 parsers.Ctx.Profiling = true
163 parsers.PovfwCtx.Profiling = true
164 }
165 /*

Callers 2

initCrowdsecFunction · 0.92
newContextDetectCmdMethod · 0.92

Calls 5

NewParsersFunction · 0.85
NewUnixParserCtxFunction · 0.85
LoadpluginFunction · 0.85
LoadStagesFunction · 0.85
InfoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…