initCrowdsec prepares the log processor service
(ctx context.Context, cConfig *csconfig.Config, hub *cwhub.Hub, testMode bool)
| 26 | |
| 27 | // initCrowdsec prepares the log processor service |
| 28 | func 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 | |
| 73 | func startParserRoutines(ctx context.Context, g *errgroup.Group, cConfig *csconfig.Config, parsers *parser.Parsers, stageCollector *parser.StageParseCollector) { |
| 74 | for idx := range cConfig.Crowdsec.ParserRoutinesCount { |
no test coverage detected
searching dependent graphs…