Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use EULA GeoIP2 Database with auto-update in Elastic license #176

Merged
merged 3 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
import:
- logstash-plugins/.ci:travis/travis.yml@1.x
- logstash-plugins/.ci:travis/travis.yml@1.x

env:
- DISTRIBUTION=default ELASTIC_STACK_VERSION=6.x
- DISTRIBUTION=default ELASTIC_STACK_VERSION=7.11.0
- DISTRIBUTION=default ELASTIC_STACK_VERSION=7.x
- DISTRIBUTION=default ELASTIC_STACK_VERSION=7.x SNAPSHOT=true
- DISTRIBUTION=default ELASTIC_STACK_VERSION=8.x SNAPSHOT=true
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 7.0.0
- Changed the plugin to use EULA GeoIP2 Database with auto-update [#176](https://github.com/logstash-plugins/logstash-filter-geoip/pull/176)
Available in Logstash 7.13+ Elastic license

## 6.0.5
- Fix database download task. Upgrade project to java 11 [#175](https://github.com/logstash-plugins/logstash-filter-geoip/pull/175)

Expand Down
53 changes: 40 additions & 13 deletions lib/logstash/filters/geoip.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# encoding: utf-8
require "logstash/filters/base"
require "logstash/namespace"

require "logstash-filter-geoip_jars"


# The GeoIP filter adds information about the geographical location of IP addresses,
# based on data from the Maxmind GeoLite2 database.
#
Expand Down Expand Up @@ -90,18 +90,8 @@ class LogStash::Filters::GeoIP < LogStash::Filters::Base

public
def register
if @database.nil?
@database = ::Dir.glob(::File.join(::File.expand_path("../../../vendor/", ::File.dirname(__FILE__)),"GeoLite2-#{@default_database_type}.mmdb")).first

if @database.nil? || !File.exists?(@database)
raise "You must specify 'database => ...' in your geoip filter (I looked for '#{@database}')"
end
end

@logger.info("Using geoip database", :path => @database)

@geoipfilter = org.logstash.filters.GeoIPFilter.new(@source, @target, @fields, @database, @cache_size)
end # def register
setup_filter(select_database_path)
end

public
def filter(event)
Expand All @@ -118,4 +108,41 @@ def tag_unsuccessful_lookup(event)
@tag_on_failure.each{|tag| event.tag(tag)}
end

def setup_filter(database_path)
@database = database_path
@logger.info("Using geoip database", :path => @database)
@geoipfilter = org.logstash.filters.GeoIPFilter.new(@source, @target, @fields, @database, @cache_size)
end

def terminate_filter
@logger.info("geoip plugin is terminating")
pipeline_id = execution_context.pipeline_id
execution_context.agent.stop_pipeline(pipeline_id)
end

def close
@database_manager.close unless @database_manager.nil?
end

def select_database_path
vendor_path = ::File.expand_path("../../../vendor/", ::File.dirname(__FILE__))

if load_database_manager?
@database_manager = LogStash::Filters::Geoip::DatabaseManager.new(self, @database, @default_database_type, vendor_path)
@database_manager.database_path
else
@database.nil? ? ::File.join(vendor_path, "GeoLite2-#{@default_database_type}.mmdb") : @database
end
end

def load_database_manager?
begin
require_relative "#{LogStash::Environment::LOGSTASH_HOME}/x-pack/lib/filters/geoip/database_manager"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try to load the database manager from xpack

true
rescue LoadError => e
@logger.info("DatabaseManager is not in classpath", :version => LOGSTASH_VERSION, :exception => e)
Copy link
Contributor Author

@kaisecheng kaisecheng Feb 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

log in info level for old version user

false
end
end

end # class LogStash::Filters::GeoIP
2 changes: 1 addition & 1 deletion logstash-filter-geoip.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|

s.name = 'logstash-filter-geoip'
s.version = '6.0.5'
s.version = '7.0.0'
s.licenses = ['Apache License (2.0)']
s.summary = "Adds geographical information about an IP address"
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
Expand Down
Loading