fluent-plugin-geoip 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fluent-plugin-geoip.gemspec +1 -1
- data/lib/fluent/plugin/geoip.rb +7 -1
- data/test/plugin/test_filter_geoip.rb +88 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b35da517cb09039e887c3c2a4fc65878ea5c5de9
|
4
|
+
data.tar.gz: 69cd94d72b73b04b1f7344815c0b1aa96d98ba30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7083fe1c2cde0d12ed5da0954c3749d914ec0a78f26d4570cb8a3e62c7623d76e4711ea33788ddded0190dfc43a9dd7bd8f6c88329fd56022adc153cf651cd4
|
7
|
+
data.tar.gz: c4834cea64a1fbc55ea8b01cda60b3b7cc38f1a1daaaee66b2333e3c770a02f3cbaa04096e710406b221a890702ddf2b098b5f8f4f8cda238125a771c1781112
|
data/fluent-plugin-geoip.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-geoip"
|
7
|
-
spec.version = "0.8.
|
7
|
+
spec.version = "0.8.1"
|
8
8
|
spec.authors = ["Kentaro Yoshida"]
|
9
9
|
spec.email = ["y.ken.studio@gmail.com"]
|
10
10
|
spec.summary = %q{Fluentd Filter plugin to add information about geographical location of IP addresses with Maxmind GeoIP databases.}
|
data/lib/fluent/plugin/geoip.rb
CHANGED
@@ -164,7 +164,13 @@ module Fluent
|
|
164
164
|
position = placeholder_key.match(REGEXP_PLACEHOLDER_SINGLE)
|
165
165
|
next if position.nil? or geodata[position[:record_key]].nil?
|
166
166
|
keys = [position[:record_key]] + position[:geoip_key].split('.').map(&:to_sym)
|
167
|
-
|
167
|
+
value = geodata.dig(*keys)
|
168
|
+
value = if [:latitude, :longitude].include?(keys.last)
|
169
|
+
value || 0.0
|
170
|
+
else
|
171
|
+
value
|
172
|
+
end
|
173
|
+
placeholder[placeholder_key] = value
|
168
174
|
end
|
169
175
|
placeholder
|
170
176
|
end
|
@@ -13,6 +13,7 @@ class GeoipFilterTest < Test::Unit::TestCase
|
|
13
13
|
|
14
14
|
def filter(config, messages, use_v1=false)
|
15
15
|
d = create_driver(config, 'test', use_v1)
|
16
|
+
yield d if block_given?
|
16
17
|
d.run {
|
17
18
|
messages.each {|message|
|
18
19
|
d.filter(message, @time)
|
@@ -22,6 +23,15 @@ class GeoipFilterTest < Test::Unit::TestCase
|
|
22
23
|
filtered.map {|m| m[2] }
|
23
24
|
end
|
24
25
|
|
26
|
+
def setup_geoip_mock(d)
|
27
|
+
geoip = d.instance.instance_variable_get(:@geoip)
|
28
|
+
db = Object.new
|
29
|
+
def db.lookup(ip)
|
30
|
+
{}
|
31
|
+
end
|
32
|
+
geoip.instance_variable_set(:@geoip, db)
|
33
|
+
end
|
34
|
+
|
25
35
|
sub_test_case "configure" do
|
26
36
|
test "empty" do
|
27
37
|
assert_nothing_raised {
|
@@ -386,6 +396,32 @@ class GeoipFilterTest < Test::Unit::TestCase
|
|
386
396
|
filtered = filter(config, messages, true)
|
387
397
|
assert_equal(expected, filtered)
|
388
398
|
end
|
399
|
+
|
400
|
+
def test_filter_when_latitude_longitude_is_nil
|
401
|
+
config = %[
|
402
|
+
backend_library geoip2_c
|
403
|
+
geoip_lookup_key host
|
404
|
+
<record>
|
405
|
+
latitude ${location.latitude['host']}
|
406
|
+
longitude ${location.longitude['host']}
|
407
|
+
</record>
|
408
|
+
]
|
409
|
+
messages = [
|
410
|
+
{ "host" => "180.94.85.84", "message" => "nil latitude and longitude" }
|
411
|
+
]
|
412
|
+
expected = [
|
413
|
+
{
|
414
|
+
"host" => "180.94.85.84",
|
415
|
+
"message" => "nil latitude and longitude",
|
416
|
+
"latitude" => 0.0,
|
417
|
+
"longitude" => 0.0
|
418
|
+
}
|
419
|
+
]
|
420
|
+
filtered = filter(config, messages) do |d|
|
421
|
+
setup_geoip_mock(d)
|
422
|
+
end
|
423
|
+
assert_equal(expected, filtered)
|
424
|
+
end
|
389
425
|
end
|
390
426
|
|
391
427
|
sub_test_case "geoip2_compat" do
|
@@ -655,6 +691,32 @@ class GeoipFilterTest < Test::Unit::TestCase
|
|
655
691
|
filtered = filter(config, messages, true)
|
656
692
|
assert_equal(expected, filtered)
|
657
693
|
end
|
694
|
+
|
695
|
+
def test_filter_when_latitude_longitude_is_nil
|
696
|
+
config = %[
|
697
|
+
backend_library geoip2_compat
|
698
|
+
geoip_lookup_key host
|
699
|
+
<record>
|
700
|
+
latitude ${latitude['host']}
|
701
|
+
longitude ${longitude['host']}
|
702
|
+
</record>
|
703
|
+
]
|
704
|
+
messages = [
|
705
|
+
{ "host" => "180.94.85.84", "message" => "nil latitude and longitude" }
|
706
|
+
]
|
707
|
+
expected = [
|
708
|
+
{
|
709
|
+
"host" => "180.94.85.84",
|
710
|
+
"message" => "nil latitude and longitude",
|
711
|
+
"latitude" => 0.0,
|
712
|
+
"longitude" => 0.0
|
713
|
+
}
|
714
|
+
]
|
715
|
+
filtered = filter(config, messages) do |d|
|
716
|
+
setup_geoip_mock(d)
|
717
|
+
end
|
718
|
+
assert_equal(expected, filtered)
|
719
|
+
end
|
658
720
|
end
|
659
721
|
|
660
722
|
sub_test_case "geoip legacy" do
|
@@ -1008,6 +1070,32 @@ class GeoipFilterTest < Test::Unit::TestCase
|
|
1008
1070
|
filtered = filter(config, messages, true)
|
1009
1071
|
assert_equal(expected, filtered)
|
1010
1072
|
end
|
1073
|
+
|
1074
|
+
def test_filter_when_latitude_longitude_is_nil
|
1075
|
+
config = %[
|
1076
|
+
backend_library geoip
|
1077
|
+
geoip_lookup_key host
|
1078
|
+
<record>
|
1079
|
+
latitude ${latitude['host']}
|
1080
|
+
longitude ${longitude['host']}
|
1081
|
+
</record>
|
1082
|
+
]
|
1083
|
+
messages = [
|
1084
|
+
{ "host" => "180.94.85.84", "message" => "nil latitude and longitude" }
|
1085
|
+
]
|
1086
|
+
expected = [
|
1087
|
+
{
|
1088
|
+
"host" => "180.94.85.84",
|
1089
|
+
"message" => "nil latitude and longitude",
|
1090
|
+
"latitude" => 0.0,
|
1091
|
+
"longitude" => 0.0
|
1092
|
+
}
|
1093
|
+
]
|
1094
|
+
filtered = filter(config, messages) do |d|
|
1095
|
+
setup_geoip_mock(d)
|
1096
|
+
end
|
1097
|
+
assert_equal(expected, filtered)
|
1098
|
+
end
|
1011
1099
|
end
|
1012
1100
|
end
|
1013
1101
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-geoip
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kentaro Yoshida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -205,7 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
205
|
version: '0'
|
206
206
|
requirements: []
|
207
207
|
rubyforge_project:
|
208
|
-
rubygems_version: 2.6.
|
208
|
+
rubygems_version: 2.6.14
|
209
209
|
signing_key:
|
210
210
|
specification_version: 4
|
211
211
|
summary: Fluentd Filter plugin to add information about geographical location of IP
|