Allow CrowdSec to start if geoip
data are not downloaded (#92)
* Allow CrowdSec to start if `geoip` data are not downloaded
This commit is contained in:
parent
68c749bc9c
commit
2e30793188
|
@ -19,6 +19,7 @@ type EnricherCtx struct {
|
||||||
Name string
|
Name string
|
||||||
Path string //path to .so ?
|
Path string //path to .so ?
|
||||||
RuntimeCtx interface{} //the internal context of plugin, given back over every call
|
RuntimeCtx interface{} //the internal context of plugin, given back over every call
|
||||||
|
initiated bool
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mimic plugin loading */
|
/* mimic plugin loading */
|
||||||
|
@ -40,8 +41,10 @@ func Loadplugin(path string) (EnricherCtx, error) {
|
||||||
|
|
||||||
c.RuntimeCtx, err = c.Init(map[string]string{"datadir": path})
|
c.RuntimeCtx, err = c.Init(map[string]string{"datadir": path})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("load (fake) plugin load : %v", err)
|
log.Warningf("load (fake) plugin load : %v", err)
|
||||||
|
c.initiated = false
|
||||||
}
|
}
|
||||||
|
c.initiated = true
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,18 +92,18 @@ func GeoIpInit(cfg map[string]string) (interface{}, error) {
|
||||||
var err error
|
var err error
|
||||||
ctx.dbc, err = geoip2.Open(cfg["datadir"] + "/GeoLite2-City.mmdb")
|
ctx.dbc, err = geoip2.Open(cfg["datadir"] + "/GeoLite2-City.mmdb")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("couldn't open geoip : %v", err)
|
log.Debugf("couldn't open geoip : %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ctx.dba, err = geoip2.Open(cfg["datadir"] + "/GeoLite2-ASN.mmdb")
|
ctx.dba, err = geoip2.Open(cfg["datadir"] + "/GeoLite2-ASN.mmdb")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("couldn't open geoip : %v", err)
|
log.Debugf("couldn't open geoip : %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.dbraw, err = maxminddb.Open(cfg["datadir"] + "/GeoLite2-ASN.mmdb")
|
ctx.dbraw, err = maxminddb.Open(cfg["datadir"] + "/GeoLite2-ASN.mmdb")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("couldn't open geoip : %v", err)
|
log.Debugf("couldn't open geoip : %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,13 +88,13 @@ func (n *Node) validate(pctx *UnixParserCtx) error {
|
||||||
}
|
}
|
||||||
method_found := false
|
method_found := false
|
||||||
for _, enricherCtx := range ECTX {
|
for _, enricherCtx := range ECTX {
|
||||||
if _, ok := enricherCtx.Funcs[static.Method]; ok {
|
if _, ok := enricherCtx.Funcs[static.Method]; ok && enricherCtx.initiated {
|
||||||
method_found = true
|
method_found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !method_found {
|
if !method_found {
|
||||||
return fmt.Errorf("the method '%s' doesn't exist", static.Method)
|
return fmt.Errorf("the method '%s' doesn't exist or the plugin has not been initialized", static.Method)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if static.Meta == "" && static.Parsed == "" && static.TargetByName == "" {
|
if static.Meta == "" && static.Parsed == "" && static.TargetByName == "" {
|
||||||
|
|
|
@ -148,7 +148,7 @@ func ProcessStatics(statics []types.ExtraField, p *types.Event, clog *logrus.Ent
|
||||||
processed := false
|
processed := false
|
||||||
/*still way too hackish, but : inject all the results in enriched, and */
|
/*still way too hackish, but : inject all the results in enriched, and */
|
||||||
for _, x := range ECTX {
|
for _, x := range ECTX {
|
||||||
if fptr, ok := x.Funcs[static.Method]; ok {
|
if fptr, ok := x.Funcs[static.Method]; ok && x.initiated {
|
||||||
clog.Tracef("Found method '%s'", static.Method)
|
clog.Tracef("Found method '%s'", static.Method)
|
||||||
ret, err := fptr(value, p, x.RuntimeCtx)
|
ret, err := fptr(value, p, x.RuntimeCtx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -165,7 +165,7 @@ func ProcessStatics(statics []types.ExtraField, p *types.Event, clog *logrus.Ent
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
clog.Warningf("method '%s' doesn't exist", static.Method)
|
clog.Warningf("method '%s' doesn't exist or plugin not initialized", static.Method)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !processed {
|
if !processed {
|
||||||
|
|
Loading…
Reference in a new issue