crowdsec/pkg/parser/enrich.go

61 lines
1.2 KiB
Go
Raw Normal View History

2020-05-15 09:39:16 +00:00
package parser
import (
log "github.com/sirupsen/logrus"
"github.com/crowdsecurity/crowdsec/pkg/types"
2020-05-15 09:39:16 +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 {
Registered map[string]*Enricher
}
type Enricher struct {
2020-05-15 09:39:16 +00:00
Name string
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) {
enricherCtx := EnricherCtx{}
enricherCtx.Registered = make(map[string]*Enricher)
2020-05-15 09:39:16 +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,
},
{
Name: "UnmarshalJSON",
EnrichFunc: unmarshalJSON,
},
2020-05-15 09:39:16 +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
}
return enricherCtx, nil
2020-05-15 09:39:16 +00:00
}