hartfordfive/cloudflarebeat

go panic error caused by IPv6 address client.ip field

Opened this issue · 2 comments

I realized that when the field client.ip, of ELS Cloudflare API, is a IPv6 address, the cloudflarebeat stop working, caused by go panic error. The output of cloudflarebeat is:

2017-04-25T15:29:20-03:00 WARN Can not index event (status=400): {"type":"mapper_parsing_exception","reason":"failed to parse [client.ip]","caused_by":{"type":"illegal_argument_exception","reason":"failed to parse ip [2603:3005:90d:2500:e4ce:e41f:3a8b:6d49], not a valid ipv4 address (4 dots)"}}
panic: interface conversion: interface {} is nil, not map[string]interface {}

And the go panic error is:

goroutine 30 [running]:
panic(0xa46160, 0xc4203d52c0)
	/opt/go/src/runtime/panic.go:500 +0x1a1
github.com/hartfordfive/cloudflarebeat/cloudflare.BuildMapStr(0xc4204563f0, 0x6c8)
	/opt/go/packages/src/github.com/hartfordfive/cloudflarebeat/cloudflare/utils.go:171 +0x644c
github.com/hartfordfive/cloudflarebeat/cloudflare.(*LogConsumer).PrepareEvents(0xc4201d1000)
	/opt/go/packages/src/github.com/hartfordfive/cloudflarebeat/cloudflare/logconsumer.go:139 +0x65c
created by github.com/hartfordfive/cloudflarebeat/beater.(*Cloudflarebeat).DownloadAndPublish
	/opt/go/packages/src/github.com/hartfordfive/cloudflarebeat/beater/cloudflarebeat.go:142 +0xc1

@naukkuws can you tell me which version of cloudflarebeat you're using? At first glance it seems like this error seems like a mapping error due to the index template. Elasticsearch 2.x did not support IPv6 addresses for the "ip" type. I'll probably just have to update cloudflarebeat.template-es2x.json template so that anything currently typed as "ip" is changed to "string".

@hartfordfive, I did the modifications you suggested, but unfortunately the problem persists. Do you have any other suggestion? Do I have to do anything else?