-
Notifications
You must be signed in to change notification settings - Fork 80
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
kaisecheng
merged 3 commits into
logstash-plugins:master
from
kaisecheng:geoip_database_xpack
Mar 1, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
# | ||
|
@@ -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) | ||
|
@@ -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" | ||
true | ||
rescue LoadError => e | ||
@logger.info("DatabaseManager is not in classpath", :version => LOGSTASH_VERSION, :exception => e) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. log in |
||
false | ||
end | ||
end | ||
|
||
end # class LogStash::Filters::GeoIP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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