logstash-filter-ip2location 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ae61a9f5111858d201154f3657cb9ae277ac8586
4
+ data.tar.gz: df982bdc0edfc26f3f1b92296b734219cc77a365
5
+ SHA512:
6
+ metadata.gz: 5de6323f8fbc2878ec1dd18ee0cd42749ba7e71bdab5339ca102b236d42e4568f0b69dbdd0ecc482508993925e91f714bfe9e2432bc6a55b32552cca941fd01a
7
+ data.tar.gz: 189cd4149dee2808c06d9a85ed0bc4ad9abd5060f90867fb0c0930594c34a9e93391ce21d873e58b6c989dcab1432439d851393b6b1ffcabb4680dc2d55e6599
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ logstash_path = ENV["LOGSTASH_PATH"] || "../../logstash"
6
+ use_logstash_source = ENV["LOGSTASH_SOURCE"] && ENV["LOGSTASH_SOURCE"].to_s == "1"
7
+
8
+ if Dir.exist?(logstash_path) && use_logstash_source
9
+ gem 'logstash-core', :path => "#{logstash_path}/logstash-core"
10
+ gem 'logstash-core-plugin-api', :path => "#{logstash_path}/logstash-core-plugin-api"
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2017 IP2Location.com
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,28 @@
1
+ # IP2Location Filter Plugin
2
+ This is IP2Location Filter plugin for Logstash that enables the user to find the country, region or state, city, latitude and longitude, US ZIP code, time zone, Internet Service Provider (ISP) or company name, domain name, net speed, area code, weather station code, weather station name, mobile country code (MCC), mobile network code (MNC) and carrier brand, elevation, and usage type by IP address or hostname originates from. The library reads the geo location information from **IP2Location BIN data** file.
3
+
4
+ Supported IPv4 and IPv6 address.
5
+
6
+
7
+ ## Dependencies (IP2LOCATION BIN DATA FILE)
8
+ This plugin requires IP2Location BIN data file to function. You may download the BIN data file at
9
+ * IP2Location LITE BIN Data (Free): https://lite.ip2location.com
10
+ * IP2Location Commercial BIN Data (Comprehensive): https://www.ip2location.com/software/java-component
11
+
12
+
13
+ ## IP2Location Filter Configuration
14
+ |Setting|Input type|Required|
15
+ |---|---|---|
16
+ |source|string|Yes|
17
+ |database|a valid filesystem path|No|
18
+ |license|string|No|
19
+
20
+ * **source** field is a required setting that containing the IP address or hostname to get the ip information.
21
+ * **database** field is an optional setting that containing the path to the IP2Location BIN database file.
22
+ * **license** field is an optional setting that containing the license key value to remove the random 5 second delay in demo version.
23
+
24
+
25
+ ## Support
26
+ Email: support@ip2location.com
27
+
28
+ URL: [https://www.ip2location.com](https://www.ip2location.com)
@@ -0,0 +1,5 @@
1
+ # AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.
2
+
3
+ require 'jar_dependencies'
4
+ require_jar('com.ip2location.ip2location', 'ip2location', '8.0.2')
5
+ require_jar('org.logstash.filters', 'logstash-filter-ip2location', '1.0.0')
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+
5
+ require "logstash-filter-ip2location_jars"
6
+
7
+ class LogStash::Filters::IP2Location < LogStash::Filters::Base
8
+ config_name "ip2location"
9
+
10
+ # The path to the IP2Location.BIN database file which Logstash should use.
11
+ # If not specified, this will default to the IP2LOCATION-LITE-DB3.IPV6.BIN database that embedded in the plugin.
12
+ config :database, :validate => :path
13
+
14
+ # The field containing the IP address.
15
+ # If this field is an array, only the first value will be used.
16
+ config :source, :validate => :string, :required => true
17
+
18
+ # The field used to define iplocation as target.
19
+ config :target, :validate => :string, :default => 'ip2location'
20
+
21
+ # The field containing the license key.
22
+ # If this field is provided, The random 5-second delay will be removed.
23
+ config :license, :validate => :string, :default => ''
24
+
25
+ public
26
+ def register
27
+ if @database.nil?
28
+ @database = ::Dir.glob(::File.join(::File.expand_path("../../../vendor/", ::File.dirname(__FILE__)),"IP2LOCATION-LITE-DB3.IPV6.BIN")).first
29
+
30
+ if @database.nil? || !File.exists?(@database)
31
+ raise "You must specify 'database => ...' in your ip2location filter (I looked for '#{@database}')"
32
+ end
33
+ end
34
+
35
+ @logger.info("Using ip2location database", :path => @database)
36
+
37
+ @ip2locationfilter = org.logstash.filters.IP2LocationFilter.new(@source, @target, @database, @license)
38
+ end
39
+
40
+ public
41
+ def filter(event)
42
+ return unless filter?(event)
43
+ if @ip2locationfilter.handleEvent(event)
44
+ filter_matched(event)
45
+ else
46
+ tag_iplookup_unsuccessful(event)
47
+ end
48
+ end
49
+
50
+ def tag_iplookup_unsuccessful(event)
51
+ @logger.debug? && @logger.debug("IP #{event.get(@source)} was not found in the database", :event => event)
52
+ end
53
+
54
+ end # class LogStash::Filters::IP2Location
@@ -0,0 +1,25 @@
1
+ Gem::Specification.new do |s|
2
+
3
+ s.name = 'logstash-filter-ip2location'
4
+ s.version = '1.0.0'
5
+ s.licenses = ['Apache License (2.0)']
6
+ s.summary = "Logstash filter IP2Location"
7
+ s.description = "IP2Location plugin for Logstash filter"
8
+ s.authors = ["IP2Location"]
9
+ s.email = 'support@ip2location.com'
10
+ s.homepage = "https://www.ip2location.com"
11
+ s.require_paths = ["lib", "vendor/jar-dependencies"]
12
+
13
+ # Files
14
+ s.files = Dir["lib/**/*",'spec/**/*',"vendor/**/*","vendor/jar-dependencies/**/*.jar","*.gemspec","*.md","Gemfile","LICENSE"]
15
+
16
+ # Tests
17
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
18
+
19
+ # Special flag to let us know this is actually a logstash plugin
20
+ s.metadata = { "logstash_plugin" => "true", "logstash_group" => "filter" }
21
+
22
+ # Gem dependencies
23
+ s.add_runtime_dependency "logstash-core-plugin-api", "~> 2.0"
24
+ s.add_development_dependency "logstash-devutils"
25
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require_relative '../spec_helper'
3
+ require "logstash/filters/ip2location"
4
+
5
+ IP2LOCATIONDB = ::Dir.glob(::File.expand_path("../../vendor/", ::File.dirname(__FILE__))+"/IP2LOCATION-LITE-DB3.IPV6.BIN").first
6
+
7
+ describe LogStash::Filters::IP2Location do
8
+
9
+ describe "normal test" do
10
+ config <<-CONFIG
11
+ filter {
12
+ ip2location {
13
+ source => "ip"
14
+ #database => "#{IP2LOCATIONDB}"
15
+ }
16
+ }
17
+ CONFIG
18
+
19
+ sample("ip" => "8.8.8.8") do
20
+ expect(subject.get("ip2location")).not_to be_empty
21
+ expect(subject.get("ip2location")["country_short"]).to eq("US")
22
+ end
23
+ end
24
+
25
+ sample("ip" => "2a01:04f8:0d16:26c2::") do
26
+ expect(subject.get("ip2location")).not_to be_empty
27
+ expect(subject.get("ip2location")["country_short"]).to eq("DE")
28
+ end
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,2 @@
1
+ # encoding: utf-8
2
+ require "logstash/devutils/rspec/spec_helper"
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: logstash-filter-ip2location
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - IP2Location
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-11-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: logstash-core-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: logstash-devutils
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: IP2Location plugin for Logstash filter
42
+ email: support@ip2location.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - Gemfile
48
+ - LICENSE
49
+ - README.md
50
+ - lib/logstash-filter-ip2location_jars.rb
51
+ - lib/logstash/filters/ip2location.rb
52
+ - logstash-filter-ip2location.gemspec
53
+ - spec/filters/ip2location_spec.rb
54
+ - spec/spec_helper.rb
55
+ - vendor/IP2LOCATION-LITE-DB3.IPV6.BIN
56
+ - vendor/jar-dependencies/com/ip2location/ip2location/ip2location/8.0.2/ip2location-8.0.2.jar
57
+ - vendor/jar-dependencies/org/logstash/filters/logstash-filter-ip2location/1.0.0/logstash-filter-ip2location-1.0.0.jar
58
+ homepage: https://www.ip2location.com
59
+ licenses:
60
+ - Apache License (2.0)
61
+ metadata:
62
+ logstash_plugin: 'true'
63
+ logstash_group: filter
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ - vendor/jar-dependencies
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.6.14
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Logstash filter IP2Location
85
+ test_files:
86
+ - spec/filters/ip2location_spec.rb
87
+ - spec/spec_helper.rb