Please be careful and selective when following examples you find online. The example you were following is dated nearly 2 years ago (31 March 2015), and many things have changed in the GeoIP plugin since that time. You no longer need to manually create a lon-lat field (coordinates
in the linked example), as Logstash now automatically does this for you. The auto-generated field is called location
. You also do not have to convert the field to a float, and the default target
is already called geoip
, so adding it (unless different from the default) is redundant.
With this simple config:
input { stdin {}}
filter { geoip { source => "message" } }
output { stdout { codec => rubydebug } }
I run Logstash, and paste 8.8.8.8
like this:
$ bin/logstash -f geo.conf
Sending Logstash's logs to /Users/buh/logstash-5.2.2/logs which is now configured via log4j2.properties
[2017-03-10T04:08:31,709][INFO ][logstash.filters.geoip ] Using geoip database {:path=>"/Users/buh/logstash-5.2.2/vendor/bundle/jruby/1.9/gems/logstash-filter-geoip-4.0.4-java/vendor/GeoLite2-City.mmdb"}
[2017-03-10T04:08:31,734][INFO ][logstash.pipeline ] Starting pipeline {"id"=>"main", "pipeline.workers"=>8, "pipeline.batch.size"=>125, "pipeline.batch.delay"=>5, "pipeline.max_inflight"=>1000}
[2017-03-10T04:08:31,744][INFO ][logstash.pipeline ] Pipeline main started
The stdin plugin is now waiting for input:
[2017-03-10T04:08:31,778][INFO ][logstash.agent ] Successfully started Logstash API endpoint {:port=>9600}
8.8.8.8
{
"@timestamp" => 2017-03-10T12:08:36.852Z,
"geoip" => {
"timezone" => "America/Los_Angeles",
"ip" => "8.8.8.8",
"latitude" => 37.386,
"continent_code" => "NA",
"city_name" => "Mountain View",
"country_code2" => "US",
"country_name" => "United States",
"dma_code" => 807,
"country_code3" => "US",
"region_name" => "California",
"location" => [
[0] -122.0838,
[1] 37.386
],
"postal_code" => "94035",
"longitude" => -122.0838,
"region_code" => "CA"
},
"@version" => "1",
"host" => "localhost.local",
"message" => "8.8.8.8"
}
It is the message
field in this config because that's the field that contains the input from STDIN
(from the stdin
input plugin).
If you know your source field, clientip
, contains an IP address, is it a standard routable internet address? The non-routable or private network blocks 10.0.0.0/8
, 172.16.0.0/12
, and 192.168.0.0/16
will not resolve to a location as they can be used by anyone, anywhere.
There may be other IP addresses not covered by the database.