logstash-filter-ip2proxy 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa9eb567d56fcb6e98d32a54a8145b0888f6e2b50d1755aa91304a1edee714ab
4
- data.tar.gz: d336a63fa77ee0b5dbb5b05d708a97b9ab666e8765fc68f8ebcf94be63a85d36
3
+ metadata.gz: bfc6055c80454901e9029421d264d5f55121839710680c66825abb54a4313cfa
4
+ data.tar.gz: d52dc6d54dbb10403bd7b939eb5e27cc9e457a1a254efac24bd605da95375d7b
5
5
  SHA512:
6
- metadata.gz: d92c46b2b301680c47b9b04083c23068064273a23ef67821e3c856bec1e03705c6df79f030f54031d18b55b4a5397121c7cd765dff06d0907d6b26daf5ab13ac
7
- data.tar.gz: 1fc1c255a8dcb9abe9afcec1f8cde4f845441673da5abc32e84eb32ab86607d3c1252d371a7faaf1e5ab564660de19aac2ddbe4a605ee1e11787aa3191521e43
6
+ metadata.gz: eb5b6b3fa711ee6dfd3eb8cd0215467a6d8b599d7f5643ece09734f4ef7be69df5604a131ecd189ed3491a90dc8e6cc0d1214dc92d8f4bfa7fdaa5bac34ec767
7
+ data.tar.gz: 85b7dc3363c7c12b547db340dc5850fe423c03f00f224291df89e378edae868907771da44c37282ad84243f877da91d065c476b5b1374828787e9643bccefa1e
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2024 IP2Location.com
1
+ Copyright (c) 2025 IP2Location.com
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
data/README.md CHANGED
@@ -3,7 +3,7 @@ This is IP2Proxy filter plugin for Logstash that enables Logstash's users to rev
3
3
 
4
4
  For the methods to use IP2Proxy filter plugin with Elastic Stack (Elasticsearch, Filebeat, Logstash, and Kibana), please take a look on this [tutorial](https://blog.ip2location.com/knowledge-base/how-to-use-ip2proxy-filter-plugin-with-elastic-stack).
5
5
 
6
- *Note: This plugin works in Logstash 7 and Logstash 8.*
6
+ *Note: This plugin works in Logstash 7, 8 and 9*
7
7
 
8
8
 
9
9
  ## Dependencies (IP2PROXY BIN DATA FILE)
@@ -1,191 +1,191 @@
1
- # encoding: utf-8
2
- require "logstash/filters/base"
3
- require "logstash/namespace"
4
-
5
- require "logstash-filter-ip2proxy_jars"
6
-
7
- class LogStash::Filters::IP2Proxy < LogStash::Filters::Base
8
- config_name "ip2proxy"
9
-
10
- # The path to the IP2Proxy.BIN database file which Logstash should use.
11
- # If not specified, this will default to the IP2PROXY-LITE-PX1.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 => 'ip2proxy'
20
-
21
- # The field used to allow user to enable the use of cache.
22
- config :use_cache, :validate => :boolean, :default => true
23
-
24
- # The field used to allow user to enable the use of memory mapped file.
25
- config :use_memory_mapped, :validate => :boolean, :default => false
26
-
27
- # The field used to allow user to hide unsupported fields.
28
- config :hide_unsupported_fields, :validate => :boolean, :default => false
29
-
30
- # The field used to define lookup type.
31
- config :lookup_type, :validate => :string, :default => 'db'
32
-
33
- # The field used to define the apikey of IP2location.io.
34
- config :api_key, :validate => :string, :default => ''
35
-
36
- # The field used to define the size of the cache. It is not required and the default value is 10 000
37
- config :cache_size, :validate => :number, :required => false, :default => 10_000
38
-
39
- public
40
- def register
41
- if @lookup_type == "ws"
42
- @logger.info("Using IP2Location.io API")
43
- if @api_key == ""
44
- raise "An IP2Location.io API key is required. You may sign up for a free API key at https://www.ip2location.io/pricing."
45
- end
46
- else
47
- if @database.nil?
48
- @database = ::Dir.glob(::File.join(::File.expand_path("../../../vendor/", ::File.dirname(__FILE__)),"IP2PROXY-LITE-PX1.BIN")).first
49
-
50
- if @database.nil? || !File.exists?(@database)
51
- raise "You must specify 'database => ...' in your ip2proxy filter (I looked for '#{@database}')"
52
- end
53
- end
54
- @logger.info("Using ip2proxy database", :path => @database)
55
- end
56
-
57
- @ip2proxyfilter = org.logstash.filters.IP2ProxyFilter.new(@source, @target, @database, @use_memory_mapped, @hide_unsupported_fields, @lookup_type, @api_key)
58
- end
59
-
60
- public
61
- def filter(event)
62
- ip = event.get(@source)
63
-
64
- return unless filter?(event)
65
- if @lookup_type == "ws"
66
- if @ip2proxyfilter.handleEvent(event)
67
- filter_matched(event)
68
- else
69
- tag_iplookup_unsuccessful(event)
70
- end
71
- else
72
- if @use_cache
73
- if value = IP2ProxyCache.find(event, ip, @ip2proxyfilter, @cache_size).get('ip2proxy')
74
- event.set('ip2proxy', value)
75
- filter_matched(event)
76
- else
77
- tag_iplookup_unsuccessful(event)
78
- end
79
- else
80
- if @ip2proxyfilter.handleEvent(event)
81
- filter_matched(event)
82
- else
83
- tag_iplookup_unsuccessful(event)
84
- end
85
- end
86
- end
87
- end
88
-
89
- def tag_iplookup_unsuccessful(event)
90
- @logger.debug? && @logger.debug("IP #{event.get(@source)} was not found in the database", :event => event)
91
- end
92
-
93
- end # class LogStash::Filters::IP2Proxy
94
-
95
- class IP2ProxyOrderedHash
96
- ONE = 1
97
-
98
- attr_reader :times_queried # ip -> times queried
99
- attr_reader :hash
100
-
101
- def initialize
102
- @times_queried = Hash.new(0) # ip -> times queried
103
- @hash = {} # number of hits -> array of ips
104
- end
105
-
106
- def add(key)
107
- hash[ONE] ||= []
108
- hash[ONE] << key
109
- times_queried[key] = ONE
110
- end
111
-
112
- def reorder(key)
113
- number_of_queries = times_queried[key]
114
-
115
- hash[number_of_queries].delete(key)
116
- hash.delete(number_of_queries) if hash[number_of_queries].empty?
117
-
118
- hash[number_of_queries + 1] ||= []
119
- hash[number_of_queries + 1] << key
120
- end
121
-
122
- def increment(key)
123
- add(key) unless times_queried.has_key?(key)
124
- reorder(key)
125
- times_queried[key] += 1
126
- end
127
-
128
- def delete_least_used
129
- first_pile_with_something.shift.tap { |key| times_queried.delete(key) }
130
- end
131
-
132
- def first_pile_with_something
133
- hash[hash.keys.min]
134
- end
135
- end
136
-
137
- class IP2ProxyCache
138
- ONE_DAY_IN_SECONDS = 86_400
139
-
140
- @cache = {} # ip -> event
141
- @timestamps = {} # ip -> time of caching
142
- @times_queried = IP2ProxyOrderedHash.new # ip -> times queried
143
- @mutex = Mutex.new
144
-
145
- class << self
146
- attr_reader :cache
147
- attr_reader :timestamps
148
- attr_reader :times_queried
149
-
150
- def find(event, ip, filter, cache_size)
151
- synchronize do
152
- if cache.has_key?(ip)
153
- refresh_event(event, ip, filter) if too_old?(ip)
154
- else
155
- if cache_full?(cache_size)
156
- make_room
157
- end
158
- cache_event(event, ip, filter)
159
- end
160
- times_queried.increment(ip)
161
- cache[ip]
162
- end
163
- end
164
-
165
- def too_old?(ip)
166
- timestamps[ip] < Time.now - ONE_DAY_IN_SECONDS
167
- end
168
-
169
- def make_room
170
- key = times_queried.delete_least_used
171
- cache.delete(key)
172
- timestamps.delete(key)
173
- end
174
-
175
- def cache_full?(cache_size)
176
- cache.size >= cache_size
177
- end
178
-
179
- def cache_event(event, ip, filter)
180
- filter.handleEvent(event)
181
- cache[ip] = event
182
- timestamps[ip] = Time.now
183
- end
184
-
185
- def synchronize(&block)
186
- @mutex.synchronize(&block)
187
- end
188
-
189
- alias_method :refresh_event, :cache_event
190
- end
191
- end
1
+ # encoding: utf-8
2
+ require "logstash/filters/base"
3
+ require "logstash/namespace"
4
+
5
+ require "logstash-filter-ip2proxy_jars"
6
+
7
+ class LogStash::Filters::IP2Proxy < LogStash::Filters::Base
8
+ config_name "ip2proxy"
9
+
10
+ # The path to the IP2Proxy.BIN database file which Logstash should use.
11
+ # If not specified, this will default to the IP2PROXY-LITE-PX1.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 => 'ip2proxy'
20
+
21
+ # The field used to allow user to enable the use of cache.
22
+ config :use_cache, :validate => :boolean, :default => true
23
+
24
+ # The field used to allow user to enable the use of memory mapped file.
25
+ config :use_memory_mapped, :validate => :boolean, :default => false
26
+
27
+ # The field used to allow user to hide unsupported fields.
28
+ config :hide_unsupported_fields, :validate => :boolean, :default => false
29
+
30
+ # The field used to define lookup type.
31
+ config :lookup_type, :validate => :string, :default => 'db'
32
+
33
+ # The field used to define the apikey of IP2location.io.
34
+ config :api_key, :validate => :string, :default => ''
35
+
36
+ # The field used to define the size of the cache. It is not required and the default value is 10 000
37
+ config :cache_size, :validate => :number, :required => false, :default => 10_000
38
+
39
+ public
40
+ def register
41
+ if @lookup_type == "ws"
42
+ @logger.info("Using IP2Location.io API")
43
+ if @api_key == ""
44
+ raise "An IP2Location.io API key is required. You may sign up for a free API key at https://www.ip2location.io/pricing."
45
+ end
46
+ else
47
+ if @database.nil?
48
+ @database = ::Dir.glob(::File.join(::File.expand_path("../../../vendor/", ::File.dirname(__FILE__)),"IP2PROXY-LITE-PX1.BIN")).first
49
+
50
+ if @database.nil? || !File.exists?(@database)
51
+ raise "You must specify 'database => ...' in your ip2proxy filter (I looked for '#{@database}')"
52
+ end
53
+ end
54
+ @logger.info("Using ip2proxy database", :path => @database)
55
+ end
56
+
57
+ @ip2proxyfilter = org.logstash.filters.IP2ProxyFilter.new(@source, @target, @database, @use_memory_mapped, @hide_unsupported_fields, @lookup_type, @api_key)
58
+ end
59
+
60
+ public
61
+ def filter(event)
62
+ ip = event.get(@source)
63
+
64
+ return unless filter?(event)
65
+ if @lookup_type == "ws"
66
+ if @ip2proxyfilter.handleEvent(event)
67
+ filter_matched(event)
68
+ else
69
+ tag_iplookup_unsuccessful(event)
70
+ end
71
+ else
72
+ if @use_cache
73
+ if value = IP2ProxyCache.find(event, ip, @ip2proxyfilter, @cache_size).get('ip2proxy')
74
+ event.set('ip2proxy', value)
75
+ filter_matched(event)
76
+ else
77
+ tag_iplookup_unsuccessful(event)
78
+ end
79
+ else
80
+ if @ip2proxyfilter.handleEvent(event)
81
+ filter_matched(event)
82
+ else
83
+ tag_iplookup_unsuccessful(event)
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ def tag_iplookup_unsuccessful(event)
90
+ @logger.debug? && @logger.debug("IP #{event.get(@source)} was not found in the database", :event => event)
91
+ end
92
+
93
+ end # class LogStash::Filters::IP2Proxy
94
+
95
+ class IP2ProxyOrderedHash
96
+ ONE = 1
97
+
98
+ attr_reader :times_queried # ip -> times queried
99
+ attr_reader :hash
100
+
101
+ def initialize
102
+ @times_queried = Hash.new(0) # ip -> times queried
103
+ @hash = {} # number of hits -> array of ips
104
+ end
105
+
106
+ def add(key)
107
+ hash[ONE] ||= []
108
+ hash[ONE] << key
109
+ times_queried[key] = ONE
110
+ end
111
+
112
+ def reorder(key)
113
+ number_of_queries = times_queried[key]
114
+
115
+ hash[number_of_queries].delete(key)
116
+ hash.delete(number_of_queries) if hash[number_of_queries].empty?
117
+
118
+ hash[number_of_queries + 1] ||= []
119
+ hash[number_of_queries + 1] << key
120
+ end
121
+
122
+ def increment(key)
123
+ add(key) unless times_queried.has_key?(key)
124
+ reorder(key)
125
+ times_queried[key] += 1
126
+ end
127
+
128
+ def delete_least_used
129
+ first_pile_with_something.shift.tap { |key| times_queried.delete(key) }
130
+ end
131
+
132
+ def first_pile_with_something
133
+ hash[hash.keys.min]
134
+ end
135
+ end
136
+
137
+ class IP2ProxyCache
138
+ ONE_DAY_IN_SECONDS = 86_400
139
+
140
+ @cache = {} # ip -> event
141
+ @timestamps = {} # ip -> time of caching
142
+ @times_queried = IP2ProxyOrderedHash.new # ip -> times queried
143
+ @mutex = Mutex.new
144
+
145
+ class << self
146
+ attr_reader :cache
147
+ attr_reader :timestamps
148
+ attr_reader :times_queried
149
+
150
+ def find(event, ip, filter, cache_size)
151
+ synchronize do
152
+ if cache.has_key?(ip)
153
+ refresh_event(event, ip, filter) if too_old?(ip)
154
+ else
155
+ if cache_full?(cache_size)
156
+ make_room
157
+ end
158
+ cache_event(event, ip, filter)
159
+ end
160
+ times_queried.increment(ip)
161
+ cache[ip]
162
+ end
163
+ end
164
+
165
+ def too_old?(ip)
166
+ timestamps[ip] < Time.now - ONE_DAY_IN_SECONDS
167
+ end
168
+
169
+ def make_room
170
+ key = times_queried.delete_least_used
171
+ cache.delete(key)
172
+ timestamps.delete(key)
173
+ end
174
+
175
+ def cache_full?(cache_size)
176
+ cache.size >= cache_size
177
+ end
178
+
179
+ def cache_event(event, ip, filter)
180
+ filter.handleEvent(event)
181
+ cache[ip] = event
182
+ timestamps[ip] = Time.now
183
+ end
184
+
185
+ def synchronize(&block)
186
+ @mutex.synchronize(&block)
187
+ end
188
+
189
+ alias_method :refresh_event, :cache_event
190
+ end
191
+ end
@@ -1,4 +1,4 @@
1
- require 'jar_dependencies'
2
- require_jar('com.ip2proxy.ip2proxy', 'ip2proxy', '3.4.0')
3
- require_jar('com.google.gson', 'gson', '2.11.0')
4
- require_jar('org.logstash.filters', 'logstash-filter-ip2proxy', '2.4.0')
1
+ require 'jar_dependencies'
2
+ require_jar('com.ip2proxy.ip2proxy', 'ip2proxy', '3.5.0')
3
+ require_jar('com.google.gson', 'gson', '2.11.0')
4
+ require_jar('org.logstash.filters', 'logstash-filter-ip2proxy', '2.5.0')
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-filter-ip2proxy'
4
- s.version = '2.4.0'
4
+ s.version = '2.5.0'
5
5
  s.licenses = ['Apache-2.0']
6
6
  s.summary = "Logstash filter IP2Proxy"
7
7
  s.description = "IP2Proxy filter plugin for Logstash enables Logstash's users to reverse search of IP address to detect VPN servers, open proxies, web proxies, Tor exit nodes, search engine robots, data center ranges and residential proxies using IP2Proxy BIN database."
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-filter-ip2proxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - IP2Location
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-18 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: logstash-core-plugin-api
@@ -56,15 +55,14 @@ files:
56
55
  - spec/filters/ip2proxy_spec.rb
57
56
  - spec/spec_helper.rb
58
57
  - vendor/jar-dependencies/com/google/gson/gson/2.11.0/gson-2.11.0.jar
59
- - vendor/jar-dependencies/com/ip2proxy/ip2proxy/ip2proxy/3.4.0/ip2proxy-3.4.0.jar
60
- - vendor/jar-dependencies/org/logstash/filters/logstash-filter-ip2proxy/2.4.0/logstash-filter-ip2proxy-2.4.0.jar
58
+ - vendor/jar-dependencies/com/ip2proxy/ip2proxy/ip2proxy/3.5.0/ip2proxy-3.5.0.jar
59
+ - vendor/jar-dependencies/org/logstash/filters/logstash-filter-ip2proxy/2.5.0/logstash-filter-ip2proxy-2.5.0.jar
61
60
  homepage: https://www.ip2location.com
62
61
  licenses:
63
62
  - Apache-2.0
64
63
  metadata:
65
64
  logstash_plugin: 'true'
66
65
  logstash_group: filter
67
- post_install_message:
68
66
  rdoc_options: []
69
67
  require_paths:
70
68
  - lib
@@ -80,8 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
78
  - !ruby/object:Gem::Version
81
79
  version: '0'
82
80
  requirements: []
83
- rubygems_version: 3.5.18
84
- signing_key:
81
+ rubygems_version: 3.7.1
85
82
  specification_version: 4
86
83
  summary: Logstash filter IP2Proxy
87
84
  test_files: