logstash-filter-ip2location 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +11 -11
- data/LICENSE +1 -1
- data/README.md +34 -3
- data/lib/logstash/filters/ip2location.rb +35 -15
- data/lib/logstash-filter-ip2location_jars.rb +2 -1
- data/logstash-filter-ip2location.gemspec +1 -1
- data/spec/filters/ip2location_spec.rb +31 -31
- data/spec/spec_helper.rb +2 -2
- data/vendor/jar-dependencies/com/google/gson/gson/2.11.0/gson-2.11.0.jar +0 -0
- data/vendor/jar-dependencies/org/logstash/filters/logstash-filter-ip2location/2.5.0/logstash-filter-ip2location-2.5.0.jar +0 -0
- metadata +5 -4
- data/vendor/jar-dependencies/org/logstash/filters/logstash-filter-ip2location/2.4.0/logstash-filter-ip2location-2.4.0.jar +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fb5dfb5ad31e4cea95d7279c2ed8c2ef8c8dca01b930aa359bf0f6e12d33350
|
4
|
+
data.tar.gz: 369974ed9ef54551651e242c9f12c7743dc4830795a2bb51256d20f241af1ada
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24fb83c8fd03b6eadc27e7d98e70b2c77c986d1761370f8795b8d31c1d913b35f61d79b9f9bbfe68e25b55ba8052615e6dc35989d91ffaf382fe3cc6127aab34
|
7
|
+
data.tar.gz: 4ec49c950dc0f02d634b93b5750c00f0990b192f9956aecdf3679308b8b122a15e97fb731a17f6c7794b2038d23670f614c713cb7feb270edb6ec0d415bc07a7
|
data/Gemfile
CHANGED
@@ -1,11 +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
|
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
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# IP2Location Filter Plugin
|
2
|
-
This is IP2Location filter plugin for Logstash that enables Logstash's users to add geolocation information such as country, region, district, city, latitude, longitude, ZIP code, time zone, Internet Service Provider (ISP), domain name, connection speed, IDD code, area code, weather station code, weather station name, mobile country code (MCC), mobile network code (MNC), mobile brand, elevation, usage type, address type, IAB category and ASN by IP address. The library reads the
|
2
|
+
This is IP2Location filter plugin for Logstash that enables Logstash's users to add geolocation information such as country, region, district, city, latitude, longitude, ZIP code, time zone, Internet Service Provider (ISP), domain name, connection speed, IDD code, area code, weather station code, weather station name, mobile country code (MCC), mobile network code (MNC), mobile brand, elevation, usage type, address type, IAB category and ASN by IP address. The library reads the geolocation information from **IP2Location BIN data** file and **IP2Location.io** data.
|
3
3
|
|
4
4
|
Supported IPv4 and IPv6 address.
|
5
5
|
|
@@ -13,6 +13,9 @@ This plugin requires IP2Location BIN data file to function. You may download the
|
|
13
13
|
* IP2Location LITE BIN Data (Free): https://lite.ip2location.com
|
14
14
|
* IP2Location Commercial BIN Data (Commercial): https://www.ip2location.com
|
15
15
|
|
16
|
+
## Dependencies (IP2LOCATION.IO DATA)
|
17
|
+
This plugin requires API key to function. You may sign up for a free API key at https://www.ip2location.io/pricing.
|
18
|
+
|
16
19
|
|
17
20
|
## Installation
|
18
21
|
Install this plugin by the following code:
|
@@ -38,7 +41,6 @@ filter {
|
|
38
41
|
}
|
39
42
|
}
|
40
43
|
|
41
|
-
|
42
44
|
output {
|
43
45
|
elasticsearch {
|
44
46
|
hosts => [ "localhost:9200" ]
|
@@ -46,7 +48,6 @@ output {
|
|
46
48
|
}
|
47
49
|
```
|
48
50
|
|
49
|
-
|
50
51
|
## Config File Example 2
|
51
52
|
```
|
52
53
|
input {
|
@@ -68,6 +69,32 @@ filter {
|
|
68
69
|
}
|
69
70
|
}
|
70
71
|
|
72
|
+
output {
|
73
|
+
elasticsearch {
|
74
|
+
hosts => [ "localhost:9200" ]
|
75
|
+
}
|
76
|
+
}
|
77
|
+
```
|
78
|
+
|
79
|
+
## Config File Example 3 using IP2Location.io
|
80
|
+
```
|
81
|
+
input {
|
82
|
+
beats {
|
83
|
+
port => "5043"
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
filter {
|
88
|
+
grok {
|
89
|
+
match => { "message" => "%{COMBINEDAPACHELOG}"}
|
90
|
+
}
|
91
|
+
ip2location {
|
92
|
+
source => "[source][address]"
|
93
|
+
lookup_type => "ws"
|
94
|
+
api_key => "YOUR_API_KEY"
|
95
|
+
}
|
96
|
+
}
|
97
|
+
|
71
98
|
|
72
99
|
output {
|
73
100
|
elasticsearch {
|
@@ -84,12 +111,16 @@ output {
|
|
84
111
|
|database|a valid filesystem path|No|
|
85
112
|
|use_memory_mapped|boolean|No|
|
86
113
|
|use_cache|boolean|No|
|
114
|
+
|lookup_type|string|No|
|
115
|
+
|api_key|string|No|
|
87
116
|
|hide_unsupported_fields|boolean|No|
|
88
117
|
|
89
118
|
* **source** field is a required setting that containing the IP address or hostname to get the ip information.
|
90
119
|
* **database** field is an optional setting that containing the path to the IP2Location BIN database file.
|
91
120
|
* **use_memory_mapped** field is an optional setting that used to allow user to enable the use of memory mapped file. Default value is false.
|
92
121
|
* **use_cache** field is an optional setting that used to allow user to enable the use of cache. Default value is true.
|
122
|
+
* **lookup_type** field is an optional setting that used to allow user to decide the lookup method either using IP2Location BIN database file(db) or IP2Location.io data(ws). Default value is db.
|
123
|
+
* **api_key** field is an optional setting that used to allow user to set the API Key of the IP2Location.io lookup.
|
93
124
|
* **hide_unsupported_fields** field is an optional setting that used to allow user to hide unsupported fields. Default value is false.
|
94
125
|
|
95
126
|
|
@@ -18,7 +18,7 @@ class LogStash::Filters::IP2Location < LogStash::Filters::Base
|
|
18
18
|
# If this field is an array, only the first value will be used.
|
19
19
|
config :source, :validate => :string, :required => true
|
20
20
|
|
21
|
-
# The field used to define
|
21
|
+
# The field used to define ip2location as target.
|
22
22
|
config :target, :validate => :string, :default => 'ip2location'
|
23
23
|
|
24
24
|
# The field used to allow user to enable the use of cache.
|
@@ -30,22 +30,34 @@ class LogStash::Filters::IP2Location < LogStash::Filters::Base
|
|
30
30
|
# The field used to allow user to hide unsupported fields.
|
31
31
|
config :hide_unsupported_fields, :validate => :boolean, :default => false
|
32
32
|
|
33
|
+
# The field used to define lookup type.
|
34
|
+
config :lookup_type, :validate => :string, :default => 'db'
|
35
|
+
|
36
|
+
# The field used to define the apikey of IP2location.io.
|
37
|
+
config :api_key, :validate => :string, :default => ''
|
38
|
+
|
33
39
|
# The field used to define the size of the cache. It is not required and the default value is 10 000
|
34
40
|
config :cache_size, :validate => :number, :required => false, :default => 10_000
|
35
41
|
|
36
42
|
public
|
37
43
|
def register
|
38
|
-
if @
|
39
|
-
@
|
40
|
-
|
41
|
-
|
42
|
-
|
44
|
+
if @lookup_type == "ws"
|
45
|
+
@logger.info("Using IP2Location.io API")
|
46
|
+
if @api_key == ""
|
47
|
+
raise "An IP2Location.io API key is required. You may sign up for a free API key at https://www.ip2location.io/pricing."
|
48
|
+
end
|
49
|
+
else
|
50
|
+
if @database.nil?
|
51
|
+
@database = ::Dir.glob(::File.join(::File.expand_path("../../../vendor/", ::File.dirname(__FILE__)),"IP2LOCATION-LITE-DB1.IPV6.BIN")).first
|
52
|
+
|
53
|
+
if @database.nil? || !File.exists?(@database)
|
54
|
+
raise "You must specify 'database => ...' in your ip2location filter (I looked for '#{@database}')"
|
55
|
+
end
|
43
56
|
end
|
57
|
+
@logger.info("Using ip2location database", :path => @database)
|
44
58
|
end
|
45
59
|
|
46
|
-
@
|
47
|
-
|
48
|
-
@ip2locationfilter = org.logstash.filters.IP2LocationFilter.new(@source, @target, @database, @use_memory_mapped, @hide_unsupported_fields)
|
60
|
+
@ip2locationfilter = org.logstash.filters.IP2LocationFilter.new(@source, @target, @database, @use_memory_mapped, @hide_unsupported_fields, @lookup_type, @api_key)
|
49
61
|
end
|
50
62
|
|
51
63
|
public
|
@@ -53,18 +65,26 @@ class LogStash::Filters::IP2Location < LogStash::Filters::Base
|
|
53
65
|
ip = event.get(@source)
|
54
66
|
|
55
67
|
return unless filter?(event)
|
56
|
-
if @
|
57
|
-
if
|
58
|
-
event.set('ip2location', value)
|
68
|
+
if @lookup_type == "ws"
|
69
|
+
if @ip2locationfilter.handleEvent(event)
|
59
70
|
filter_matched(event)
|
60
71
|
else
|
61
72
|
tag_iplookup_unsuccessful(event)
|
62
73
|
end
|
63
74
|
else
|
64
|
-
if @
|
65
|
-
|
75
|
+
if @use_cache
|
76
|
+
if value = IP2LocationCache.find(event, ip, @ip2locationfilter, @cache_size).get('ip2location')
|
77
|
+
event.set('ip2location', value)
|
78
|
+
filter_matched(event)
|
79
|
+
else
|
80
|
+
tag_iplookup_unsuccessful(event)
|
81
|
+
end
|
66
82
|
else
|
67
|
-
|
83
|
+
if @ip2locationfilter.handleEvent(event)
|
84
|
+
filter_matched(event)
|
85
|
+
else
|
86
|
+
tag_iplookup_unsuccessful(event)
|
87
|
+
end
|
68
88
|
end
|
69
89
|
end
|
70
90
|
end
|
@@ -1,3 +1,4 @@
|
|
1
1
|
require 'jar_dependencies'
|
2
2
|
require_jar('com.ip2location.ip2location', 'ip2location', '8.11.0')
|
3
|
-
require_jar('
|
3
|
+
require_jar('com.google.gson', 'gson', '2.11.0')
|
4
|
+
require_jar('org.logstash.filters', 'logstash-filter-ip2location', '2.5.0')
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-filter-ip2location'
|
4
|
-
s.version = '2.
|
4
|
+
s.version = '2.5.0'
|
5
5
|
s.licenses = ['Apache-2.0']
|
6
6
|
s.summary = "Logstash filter IP2Location"
|
7
7
|
s.description = "IP2Location filter plugin for Logstash enables Logstash's users to add geolocation information such as country, state, district, city, latitude, longitude, ZIP code, time zone, ISP, domain name, connection speed, IDD code, area code, weather station code, weather station name, MNC, MCC, mobile brand, elevation, usage type, address type, IAB category and ASN by IP address."
|
@@ -1,32 +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-DB1.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
|
-
|
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-DB1.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
32
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require "logstash/devutils/rspec/spec_helper"
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/devutils/rspec/spec_helper"
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-filter-ip2location
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IP2Location
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logstash-core-plugin-api
|
@@ -57,8 +57,9 @@ files:
|
|
57
57
|
- spec/filters/ip2location_spec.rb
|
58
58
|
- spec/spec_helper.rb
|
59
59
|
- vendor/IP2LOCATION-LITE-DB1.IPV6.BIN
|
60
|
+
- vendor/jar-dependencies/com/google/gson/gson/2.11.0/gson-2.11.0.jar
|
60
61
|
- vendor/jar-dependencies/com/ip2location/ip2location/ip2location/8.11.0/ip2location-8.11.0.jar
|
61
|
-
- vendor/jar-dependencies/org/logstash/filters/logstash-filter-ip2location/2.
|
62
|
+
- vendor/jar-dependencies/org/logstash/filters/logstash-filter-ip2location/2.5.0/logstash-filter-ip2location-2.5.0.jar
|
62
63
|
homepage: https://www.ip2location.com
|
63
64
|
licenses:
|
64
65
|
- Apache-2.0
|
@@ -81,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '0'
|
83
84
|
requirements: []
|
84
|
-
rubygems_version: 3.
|
85
|
+
rubygems_version: 3.5.18
|
85
86
|
signing_key:
|
86
87
|
specification_version: 4
|
87
88
|
summary: Logstash filter IP2Location
|