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

Function initCrowdsec

cmd/crowdsec/crowdsec.go:28–71  ·  view source on GitHub ↗

initCrowdsec prepares the log processor service

(ctx context.Context, cConfig *csconfig.Config, hub *cwhub.Hub, testMode bool)

Source from the content-addressed store, hash-verified

26
27// initCrowdsec prepares the log processor service
28func initCrowdsec(ctx context.Context, cConfig *csconfig.Config, hub *cwhub.Hub, testMode bool) (*parser.Parsers, []acquisitionTypes.DataSource, error) {
29 var err error
30 if err = alertcontext.LoadConsoleContext(cConfig, hub); err != nil {
31 return nil, nil, fmt.Errorf("while loading context: %w", err)
32 }
33
34 err = exprhelpers.GeoIPInit(hub.GetDataDir())
35 if err != nil {
36 // GeoIP databases are not mandatory, do not make crowdsec fail if they are not present
37 log.Warnf("unable to initialize GeoIP: %s", err)
38 }
39
40 // Start loading configs
41 csParsers, err := parser.LoadParsers(cConfig, hub)
42 if err != nil {
43 return nil, nil, fmt.Errorf("while loading parsers: %w", err)
44 }
45
46 if err = LoadBuckets(cConfig, hub); err != nil {
47 return nil, nil, fmt.Errorf("while loading scenarios: %w", err)
48 }
49
50 // can be nerfed by a build flag
51 if err = LoadAppsecRules(hub); err != nil {
52 return nil, nil, err
53 }
54
55 if !testMode {
56 err = apiclient.InitLAPIClient(
57 ctx, cConfig.API.Client.Credentials.URL, cConfig.API.Client.Credentials.PapiURL,
58 cConfig.API.Client.Credentials.Login, cConfig.API.Client.Credentials.Password,
59 hub.GetInstalledListForAPI())
60 if err != nil {
61 return nil, nil, fmt.Errorf("while initializing LAPIClient: %w", err)
62 }
63 }
64
65 datasources, err := LoadAcquisition(ctx, cConfig, hub)
66 if err != nil {
67 return nil, nil, fmt.Errorf("while loading acquisition config: %w", err)
68 }
69
70 return csParsers, datasources, nil
71}
72
73func startParserRoutines(ctx context.Context, g *errgroup.Group, cConfig *csconfig.Config, parsers *parser.Parsers, stageCollector *parser.StageParseCollector) {
74 for idx := range cConfig.Crowdsec.ParserRoutinesCount {

Callers 2

reloadHandlerFunction · 0.85
ServeFunction · 0.85

Calls 9

LoadConsoleContextFunction · 0.92
GeoIPInitFunction · 0.92
LoadParsersFunction · 0.92
InitLAPIClientFunction · 0.92
LoadAcquisitionFunction · 0.85
GetDataDirMethod · 0.80
LoadBucketsFunction · 0.70
LoadAppsecRulesFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…