2020-05-15 09:39:16 +00:00
|
|
|
package parser
|
|
|
|
|
|
|
|
import (
|
|
|
|
log "github.com/sirupsen/logrus"
|
2023-06-13 11:16:13 +00:00
|
|
|
|
|
|
|
"github.com/crowdsecurity/crowdsec/pkg/types"
|
2020-05-15 09:39:16 +00:00
|
|
|
)
|
|
|
|
|
2023-06-13 11:16:13 +00:00
|
|
|
/* should be part of a package shared with enrich/geoip.go */
|
2024-04-15 20:06:59 +00:00
|
|
|
type EnrichFunc func(string, *types.Event, *log.Entry) (map[string]string, error)
|
2020-05-15 09:39:16 +00:00
|
|
|
type InitFunc func(map[string]string) (interface{}, error)
|
|
|
|
|
|
|
|
type EnricherCtx struct {
|
2021-09-09 14:27:30 +00:00
|
|
|
Registered map[string]*Enricher
|
|
|
|
}
|
|
|
|
|
|
|
|
type Enricher struct {
|
2020-05-15 09:39:16 +00:00
|
|
|
Name string
|
2021-09-09 14:27:30 +00:00
|
|
|
EnrichFunc EnrichFunc
|
2020-05-15 09:39:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mimic plugin loading */
|
2024-04-15 20:06:59 +00:00
|
|
|
func Loadplugin() (EnricherCtx, error) {
|
2021-09-09 14:27:30 +00:00
|
|
|
enricherCtx := EnricherCtx{}
|
|
|
|
enricherCtx.Registered = make(map[string]*Enricher)
|
2020-05-15 09:39:16 +00:00
|
|
|
|
2021-09-09 14:27:30 +00:00
|
|
|
EnrichersList := []*Enricher{
|
|
|
|
{
|
|
|
|
Name: "GeoIpCity",
|
|
|
|
EnrichFunc: GeoIpCity,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "GeoIpASN",
|
|
|
|
EnrichFunc: GeoIpASN,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "IpToRange",
|
|
|
|
EnrichFunc: IpToRange,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "reverse_dns",
|
|
|
|
EnrichFunc: reverse_dns,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "ParseDate",
|
|
|
|
EnrichFunc: ParseDate,
|
|
|
|
},
|
2022-12-06 12:47:29 +00:00
|
|
|
{
|
|
|
|
Name: "UnmarshalJSON",
|
|
|
|
EnrichFunc: unmarshalJSON,
|
|
|
|
},
|
2020-05-15 09:39:16 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 14:27:30 +00:00
|
|
|
for _, enricher := range EnrichersList {
|
|
|
|
log.Infof("Successfully registered enricher '%s'", enricher.Name)
|
|
|
|
enricherCtx.Registered[enricher.Name] = enricher
|
2020-05-15 09:39:16 +00:00
|
|
|
}
|
2021-04-16 17:13:48 +00:00
|
|
|
|
2021-09-09 14:27:30 +00:00
|
|
|
return enricherCtx, nil
|
2020-05-15 09:39:16 +00:00
|
|
|
}
|