fluent-plugin-geoip 0.8.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -4
- data/Appraisals +0 -9
- data/README.md +92 -31
- data/dockerfiles/Dockerfile-ruby2.1 +1 -1
- data/dockerfiles/Dockerfile-ruby2.2 +1 -1
- data/dockerfiles/Dockerfile-ruby2.3 +1 -1
- data/dockerfiles/Dockerfile-ruby2.4 +1 -1
- data/fluent-plugin-geoip.gemspec +3 -4
- data/lib/fluent/plugin/filter_geoip.rb +16 -22
- data/lib/fluent/plugin/geoip.rb +2 -21
- data/lib/fluent/plugin/out_geoip.rb +23 -26
- data/test/helper.rb +4 -28
- data/test/plugin/test_filter_geoip.rb +46 -175
- data/test/plugin/test_out_geoip.rb +535 -550
- metadata +13 -23
- data/gemfiles/fluentd_v0.12_with_backport_dig.gemfile +0 -8
- data/gemfiles/fluentd_v0.12_without_backport_dig.gemfile +0 -7
@@ -1,24 +1,27 @@
|
|
1
1
|
require 'helper'
|
2
|
+
require 'fluent/plugin/out_geoip'
|
3
|
+
require 'fluent/test/driver/output'
|
2
4
|
|
3
5
|
class GeoipOutputTest < Test::Unit::TestCase
|
4
6
|
def setup
|
5
7
|
Fluent::Test.setup
|
6
8
|
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
CONFIG = %[
|
11
|
+
geoip_lookup_key host
|
12
|
+
enable_key_city geoip_city
|
13
|
+
tag geoip.${tag[1]}
|
14
|
+
]
|
15
|
+
|
16
|
+
def create_driver(conf = CONFIG, syntax: :v1)
|
17
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::GeoipOutput).configure(conf, syntax: syntax)
|
15
18
|
end
|
16
19
|
|
17
20
|
sub_test_case "configure" do
|
18
21
|
test "empty" do
|
19
|
-
|
22
|
+
assert_nothing_raised do
|
20
23
|
create_driver('')
|
21
|
-
|
24
|
+
end
|
22
25
|
end
|
23
26
|
|
24
27
|
test "missing required parameters" do
|
@@ -30,58 +33,59 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
30
33
|
test "minimum" do
|
31
34
|
d = create_driver %[
|
32
35
|
enable_key_city geoip_city
|
33
|
-
|
34
|
-
tag geoip.${tag}
|
36
|
+
tag geoip.${tag[1]}
|
35
37
|
]
|
36
38
|
assert_equal 'geoip_city', d.instance.config['enable_key_city']
|
37
39
|
end
|
38
40
|
|
41
|
+
test "invalid key name" do
|
42
|
+
assert_raise(Fluent::ConfigError.new("geoip: unsupported key cities")) do
|
43
|
+
create_driver('enable_key_cities')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
39
47
|
test "multiple key config" do
|
40
48
|
d = create_driver %[
|
41
49
|
geoip_lookup_key from.ip, to.ip
|
42
50
|
enable_key_city from_city, to_city
|
43
|
-
|
44
|
-
tag geoip.${tag}
|
51
|
+
tag geoip.${tag[1]}
|
45
52
|
]
|
46
53
|
assert_equal 'from_city, to_city', d.instance.config['enable_key_city']
|
47
54
|
end
|
48
55
|
|
49
56
|
test "multiple key config (bad configure)" do
|
50
|
-
assert_raise(Fluent::ConfigError)
|
57
|
+
assert_raise(Fluent::ConfigError) do
|
51
58
|
create_driver %[
|
52
59
|
geoip_lookup_key from.ip, to.ip
|
53
60
|
enable_key_city from_city
|
54
61
|
enable_key_region from_region
|
55
|
-
|
56
|
-
tag geoip.${tag}
|
62
|
+
tag geoip.${tag[1]}
|
57
63
|
]
|
58
|
-
|
64
|
+
end
|
59
65
|
end
|
60
66
|
|
61
67
|
test "invalid json structure w/ Ruby hash like" do
|
62
|
-
assert_raise(Fluent::
|
68
|
+
assert_raise(Fluent::ConfigParseError) do
|
63
69
|
create_driver %[
|
64
70
|
geoip_lookup_key host
|
65
71
|
<record>
|
66
72
|
invalid_json {"foo" => 123}
|
67
73
|
</record>
|
68
|
-
|
69
|
-
tag geoip.${tag}
|
74
|
+
tag geoip.${tag[1]}
|
70
75
|
]
|
71
|
-
|
76
|
+
end
|
72
77
|
end
|
73
78
|
|
74
79
|
test "invalid json structure w/ unquoted string literal" do
|
75
|
-
assert_raise(Fluent::
|
80
|
+
assert_raise(Fluent::ConfigParseError) do
|
76
81
|
create_driver %[
|
77
82
|
geoip_lookup_key host
|
78
83
|
<record>
|
79
84
|
invalid_json {"foo" : string, "bar" : 123}
|
80
85
|
</record>
|
81
|
-
|
82
|
-
tag geoip.${tag}
|
86
|
+
tag geoip.${tag[1]}
|
83
87
|
]
|
84
|
-
|
88
|
+
end
|
85
89
|
end
|
86
90
|
|
87
91
|
data(geoip: "geoip",
|
@@ -93,8 +97,7 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
93
97
|
<record>
|
94
98
|
city ${unknown["host"]}
|
95
99
|
</record>
|
96
|
-
|
97
|
-
tag geoip.${tag}
|
100
|
+
tag geoip.${tag[1]}
|
98
101
|
]
|
99
102
|
end
|
100
103
|
end
|
@@ -108,8 +111,7 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
108
111
|
<record>
|
109
112
|
city #{placeholder}
|
110
113
|
</record>
|
111
|
-
|
112
|
-
tag geoip.${tag}
|
114
|
+
tag geoip.${tag[1]}
|
113
115
|
]
|
114
116
|
end
|
115
117
|
|
@@ -120,8 +122,7 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
120
122
|
<record>
|
121
123
|
city ${city["host"]}
|
122
124
|
</record>
|
123
|
-
|
124
|
-
tag geoip.${tag}
|
125
|
+
tag geoip.${tag[1]}
|
125
126
|
]
|
126
127
|
end
|
127
128
|
end
|
@@ -135,18 +136,17 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
135
136
|
<record>
|
136
137
|
geoip_city ${city.names.en['host']}
|
137
138
|
</record>
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
d1.
|
143
|
-
d1.emit({'message' => 'missing field'})
|
139
|
+
tag geoip.${tag[1]}
|
140
|
+
])
|
141
|
+
d1.run(default_tag: 'input.access') do
|
142
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
143
|
+
d1.feed({'message' => 'missing field'})
|
144
144
|
end
|
145
|
-
|
146
|
-
assert_equal 2,
|
147
|
-
assert_equal 'geoip.access',
|
148
|
-
assert_equal 'Mountain View',
|
149
|
-
assert_equal nil,
|
145
|
+
events = d1.events
|
146
|
+
assert_equal 2, events.length
|
147
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
148
|
+
assert_equal 'Mountain View', events[0][2]['geoip_city']
|
149
|
+
assert_equal nil, events[1][2]['geoip_city']
|
150
150
|
end
|
151
151
|
|
152
152
|
def test_emit_tag_parts
|
@@ -156,15 +156,15 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
156
156
|
<record>
|
157
157
|
geoip_city ${city.names.en['host']}
|
158
158
|
</record>
|
159
|
-
tag geoip.${
|
160
|
-
]
|
161
|
-
d1.run do
|
162
|
-
d1.
|
159
|
+
tag geoip.${tag[1]}.${tag[2]}.${tag[3]}
|
160
|
+
])
|
161
|
+
d1.run(default_tag: '0.1.2.3') do
|
162
|
+
d1.feed({'host' => '66.102.3.80'})
|
163
163
|
end
|
164
|
-
|
165
|
-
assert_equal 1,
|
166
|
-
assert_equal 'geoip.1.2.3
|
167
|
-
assert_equal 'Mountain View',
|
164
|
+
events = d1.events
|
165
|
+
assert_equal 1, events.length
|
166
|
+
assert_equal 'geoip.1.2.3', events[0][0] # tag
|
167
|
+
assert_equal 'Mountain View', events[0][2]['geoip_city']
|
168
168
|
end
|
169
169
|
|
170
170
|
def test_emit_with_dot_key
|
@@ -175,17 +175,16 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
175
175
|
origin_country ${country.iso_code['ip.origin']}
|
176
176
|
dest_country ${country.iso_code['ip.dest']}
|
177
177
|
</record>
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
d1.emit({'ip.origin' => '66.102.3.80', 'ip.dest' => '8.8.8.8'})
|
178
|
+
tag geoip.${tag[1]}
|
179
|
+
])
|
180
|
+
d1.run(default_tag: 'input.access') do
|
181
|
+
d1.feed({'ip.origin' => '66.102.3.80', 'ip.dest' => '8.8.8.8'})
|
183
182
|
end
|
184
|
-
|
185
|
-
assert_equal 1,
|
186
|
-
assert_equal 'geoip.access',
|
187
|
-
assert_equal 'US',
|
188
|
-
assert_equal 'US',
|
183
|
+
events = d1.events
|
184
|
+
assert_equal 1, events.length
|
185
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
186
|
+
assert_equal 'US', events[0][2]['origin_country']
|
187
|
+
assert_equal 'US', events[0][2]['dest_country']
|
189
188
|
end
|
190
189
|
|
191
190
|
def test_emit_with_unknown_address
|
@@ -197,20 +196,19 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
197
196
|
geopoint [${location.longitude['host']}, ${location.latitude['host']}]
|
198
197
|
</record>
|
199
198
|
skip_adding_null_record false
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
d1.run do
|
199
|
+
tag geoip.${tag[1]}
|
200
|
+
], syntax: :v0)
|
201
|
+
d1.run(default_tag: 'input.access') do
|
204
202
|
# 203.0.113.1 is a test address described in RFC5737
|
205
|
-
d1.
|
206
|
-
d1.
|
203
|
+
d1.feed({'host' => '203.0.113.1', 'message' => 'invalid ip'})
|
204
|
+
d1.feed({'host' => '0', 'message' => 'invalid ip'})
|
207
205
|
end
|
208
|
-
|
209
|
-
assert_equal 2,
|
210
|
-
assert_equal 'geoip.access',
|
211
|
-
assert_equal nil,
|
212
|
-
assert_equal 'geoip.access',
|
213
|
-
assert_equal nil,
|
206
|
+
events = d1.events
|
207
|
+
assert_equal 2, events.length
|
208
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
209
|
+
assert_equal nil, events[0][2]['geoip_city']
|
210
|
+
assert_equal 'geoip.access', events[1][0] # tag
|
211
|
+
assert_equal nil, events[1][2]['geoip_city']
|
214
212
|
end
|
215
213
|
|
216
214
|
def test_emit_with_skip_unknown_address
|
@@ -222,25 +220,24 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
222
220
|
geopoint [${location.longitude['host']}, ${location.latitude['host']}]
|
223
221
|
</record>
|
224
222
|
skip_adding_null_record true
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
d1.run do
|
223
|
+
tag geoip.${tag[1]}
|
224
|
+
], syntax: :v0)
|
225
|
+
d1.run(default_tag: 'input.access') do
|
229
226
|
# 203.0.113.1 is a test address described in RFC5737
|
230
|
-
d1.
|
231
|
-
d1.
|
232
|
-
d1.
|
227
|
+
d1.feed({'host' => '203.0.113.1', 'message' => 'invalid ip'})
|
228
|
+
d1.feed({'host' => '0', 'message' => 'invalid ip'})
|
229
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'google bot'})
|
233
230
|
end
|
234
|
-
|
235
|
-
assert_equal 3,
|
236
|
-
assert_equal 'geoip.access',
|
237
|
-
assert_equal nil,
|
238
|
-
assert_equal nil,
|
239
|
-
assert_equal 'geoip.access',
|
240
|
-
assert_equal nil,
|
241
|
-
assert_equal nil,
|
242
|
-
assert_equal 'Mountain View',
|
243
|
-
assert_equal [-122.0574, 37.419200000000004],
|
231
|
+
events = d1.events
|
232
|
+
assert_equal 3, events.length
|
233
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
234
|
+
assert_equal nil, events[0][2]['geoip_city']
|
235
|
+
assert_equal nil, events[0][2]['geopoint']
|
236
|
+
assert_equal 'geoip.access', events[1][0] # tag
|
237
|
+
assert_equal nil, events[1][2]['geoip_city']
|
238
|
+
assert_equal nil, events[1][2]['geopoint']
|
239
|
+
assert_equal 'Mountain View', events[2][2]['geoip_city']
|
240
|
+
assert_equal [-122.0574, 37.419200000000004], events[2][2]['geopoint']
|
244
241
|
end
|
245
242
|
|
246
243
|
def test_emit_record_directive
|
@@ -263,50 +260,49 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
263
260
|
broken_array1 [${location.longitude['from.ip']}, ${location.latitude['undefined']}]
|
264
261
|
broken_array2 [${location.longitude['undefined']}, ${location.latitude['undefined']}]
|
265
262
|
</record>
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
d1.
|
271
|
-
d1.emit({'message' => 'missing field'})
|
263
|
+
tag geoip.${tag[1]}
|
264
|
+
], syntax: :v0)
|
265
|
+
d1.run(default_tag: 'input.access') do
|
266
|
+
d1.feed({'from' => {'ip' => '66.102.3.80'}})
|
267
|
+
d1.feed({'message' => 'missing field'})
|
272
268
|
end
|
273
|
-
|
274
|
-
assert_equal 2,
|
275
|
-
|
276
|
-
assert_equal 'geoip.access',
|
277
|
-
assert_equal 'Mountain View',
|
278
|
-
assert_equal 'United States',
|
279
|
-
assert_equal 37.419200000000004,
|
280
|
-
assert_equal -122.0574,
|
281
|
-
assert_equal '37.419200000000004,-122.0574',
|
282
|
-
assert_equal [-122.0574, 37.419200000000004],
|
269
|
+
events = d1.events
|
270
|
+
assert_equal 2, events.length
|
271
|
+
|
272
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
273
|
+
assert_equal 'Mountain View', events[0][2]['from_city']
|
274
|
+
assert_equal 'United States', events[0][2]['from_country']
|
275
|
+
assert_equal 37.419200000000004, events[0][2]['latitude']
|
276
|
+
assert_equal -122.0574, events[0][2]['longitude']
|
277
|
+
assert_equal '37.419200000000004,-122.0574', events[0][2]['float_concat']
|
278
|
+
assert_equal [-122.0574, 37.419200000000004], events[0][2]['float_array']
|
283
279
|
float_nest = {"lat" => 37.419200000000004, "lon" => -122.0574 }
|
284
|
-
assert_equal float_nest,
|
285
|
-
assert_equal '37.419200000000004,-122.0574',
|
286
|
-
assert_equal ["Mountain View", "United States"],
|
280
|
+
assert_equal float_nest, events[0][2]['float_nest']
|
281
|
+
assert_equal '37.419200000000004,-122.0574', events[0][2]['string_concat']
|
282
|
+
assert_equal ["Mountain View", "United States"], events[0][2]['string_array']
|
287
283
|
string_nest = {"city" => "Mountain View", "country_name" => "United States"}
|
288
|
-
assert_equal string_nest,
|
289
|
-
assert_equal nil,
|
290
|
-
assert_equal nil,
|
291
|
-
assert_equal [-122.0574, nil],
|
292
|
-
assert_equal [nil, nil],
|
293
|
-
|
294
|
-
assert_equal nil,
|
295
|
-
assert_equal nil,
|
296
|
-
assert_equal nil,
|
297
|
-
assert_equal nil,
|
298
|
-
assert_equal ',',
|
299
|
-
assert_equal [nil, nil],
|
284
|
+
assert_equal string_nest, events[0][2]['string_nest']
|
285
|
+
assert_equal nil, events[0][2]['unknown_city']
|
286
|
+
assert_equal nil, events[0][2]['undefined']
|
287
|
+
assert_equal [-122.0574, nil], events[0][2]['broken_array1']
|
288
|
+
assert_equal [nil, nil], events[0][2]['broken_array2']
|
289
|
+
|
290
|
+
assert_equal nil, events[1][2]['from_city']
|
291
|
+
assert_equal nil, events[1][2]['from_country']
|
292
|
+
assert_equal nil, events[1][2]['latitude']
|
293
|
+
assert_equal nil, events[1][2]['longitude']
|
294
|
+
assert_equal ',', events[1][2]['float_concat']
|
295
|
+
assert_equal [nil, nil], events[1][2]['float_array']
|
300
296
|
float_nest = {"lat" => nil, "lon" => nil}
|
301
|
-
assert_equal float_nest,
|
302
|
-
assert_equal ',',
|
303
|
-
assert_equal [nil, nil],
|
297
|
+
assert_equal float_nest, events[1][2]['float_nest']
|
298
|
+
assert_equal ',', events[1][2]['string_concat']
|
299
|
+
assert_equal [nil, nil], events[1][2]['string_array']
|
304
300
|
string_nest = {"city" => nil, "country_name" => nil}
|
305
|
-
assert_equal string_nest,
|
306
|
-
assert_equal nil,
|
307
|
-
assert_equal nil,
|
308
|
-
assert_equal [nil, nil],
|
309
|
-
assert_equal [nil, nil],
|
301
|
+
assert_equal string_nest, events[1][2]['string_nest']
|
302
|
+
assert_equal nil, events[1][2]['unknown_city']
|
303
|
+
assert_equal nil, events[1][2]['undefined']
|
304
|
+
assert_equal [nil, nil], events[1][2]['broken_array1']
|
305
|
+
assert_equal [nil, nil], events[1][2]['broken_array2']
|
310
306
|
end
|
311
307
|
|
312
308
|
def test_emit_record_directive_multiple_record
|
@@ -320,28 +316,27 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
320
316
|
to_country ${country.names.en['to.ip']}
|
321
317
|
string_array [${country.names.en['from.ip']}, ${country.names.en['to.ip']}]
|
322
318
|
</record>
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
d1.
|
328
|
-
d1.emit({'message' => 'missing field'})
|
319
|
+
tag geoip.${tag[1]}
|
320
|
+
], syntax: :v0)
|
321
|
+
d1.run(default_tag: 'input.access') do
|
322
|
+
d1.feed({'from' => {'ip' => '66.102.3.80'}, 'to' => {'ip' => '125.54.15.42'}})
|
323
|
+
d1.feed({'message' => 'missing field'})
|
329
324
|
end
|
330
|
-
|
331
|
-
assert_equal 2,
|
332
|
-
|
333
|
-
assert_equal 'geoip.access',
|
334
|
-
assert_equal 'Mountain View',
|
335
|
-
assert_equal 'United States',
|
336
|
-
assert_equal 'Tokorozawa',
|
337
|
-
assert_equal 'Japan',
|
338
|
-
assert_equal ['United States','Japan'],
|
339
|
-
|
340
|
-
assert_equal nil,
|
341
|
-
assert_equal nil,
|
342
|
-
assert_equal nil,
|
343
|
-
assert_equal nil,
|
344
|
-
assert_equal [nil, nil],
|
325
|
+
events = d1.events
|
326
|
+
assert_equal 2, events.length
|
327
|
+
|
328
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
329
|
+
assert_equal 'Mountain View', events[0][2]['from_city']
|
330
|
+
assert_equal 'United States', events[0][2]['from_country']
|
331
|
+
assert_equal 'Tokorozawa', events[0][2]['to_city']
|
332
|
+
assert_equal 'Japan', events[0][2]['to_country']
|
333
|
+
assert_equal ['United States','Japan'], events[0][2]['string_array']
|
334
|
+
|
335
|
+
assert_equal nil, events[1][2]['from_city']
|
336
|
+
assert_equal nil, events[1][2]['to_city']
|
337
|
+
assert_equal nil, events[1][2]['from_country']
|
338
|
+
assert_equal nil, events[1][2]['to_country']
|
339
|
+
assert_equal [nil, nil], events[1][2]['string_array']
|
345
340
|
end
|
346
341
|
|
347
342
|
def config_quoted_record
|
@@ -356,43 +351,42 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
356
351
|
location_array2 '[${location.longitude["host"]},${location.latitude["host"]}]'
|
357
352
|
peculiar_pattern '[GEOIP] message => {"lat":${location.latitude["host"]}, "lon":${location.longitude["host"]}}'
|
358
353
|
</record>
|
359
|
-
|
360
|
-
tag geoip.${tag}
|
354
|
+
tag geoip.${tag[1]}
|
361
355
|
]
|
362
356
|
end
|
363
357
|
|
364
358
|
def test_emit_quoted_record
|
365
|
-
d1 = create_driver(config_quoted_record
|
366
|
-
d1.run do
|
367
|
-
d1.
|
359
|
+
d1 = create_driver(config_quoted_record)
|
360
|
+
d1.run(default_tag: 'input.access') do
|
361
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
368
362
|
end
|
369
|
-
|
370
|
-
assert_equal 1,
|
371
|
-
assert_equal 'geoip.access',
|
363
|
+
events = d1.events
|
364
|
+
assert_equal 1, events.length
|
365
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
372
366
|
location_properties = { "country_code" => "US", "lat" => 37.419200000000004, "lon"=> -122.0574 }
|
373
|
-
assert_equal location_properties,
|
374
|
-
assert_equal '37.419200000000004,-122.0574',
|
375
|
-
assert_equal 'US',
|
376
|
-
assert_equal [-122.0574, 37.419200000000004],
|
377
|
-
assert_equal [-122.0574, 37.419200000000004],
|
378
|
-
assert_equal '[GEOIP] message => {"lat":37.419200000000004, "lon":-122.0574}',
|
367
|
+
assert_equal location_properties, events[0][2]['location_properties']
|
368
|
+
assert_equal '37.419200000000004,-122.0574', events[0][2]['location_string']
|
369
|
+
assert_equal 'US', events[0][2]['location_string2']
|
370
|
+
assert_equal [-122.0574, 37.419200000000004], events[0][2]['location_array']
|
371
|
+
assert_equal [-122.0574, 37.419200000000004], events[0][2]['location_array2']
|
372
|
+
assert_equal '[GEOIP] message => {"lat":37.419200000000004, "lon":-122.0574}', events[0][2]['peculiar_pattern']
|
379
373
|
end
|
380
374
|
|
381
375
|
def test_emit_v1_config_compatibility
|
382
|
-
d1 = create_driver(config_quoted_record
|
383
|
-
d1.run do
|
384
|
-
d1.
|
376
|
+
d1 = create_driver(config_quoted_record)
|
377
|
+
d1.run(default_tag: 'input.access') do
|
378
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
385
379
|
end
|
386
|
-
|
387
|
-
assert_equal 1,
|
388
|
-
assert_equal 'geoip.access',
|
380
|
+
events = d1.events
|
381
|
+
assert_equal 1, events.length
|
382
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
389
383
|
location_properties = { "country_code" => "US", "lat" => 37.419200000000004, "lon"=> -122.0574 }
|
390
|
-
assert_equal location_properties,
|
391
|
-
assert_equal '37.419200000000004,-122.0574',
|
392
|
-
assert_equal 'US',
|
393
|
-
assert_equal [-122.0574, 37.419200000000004],
|
394
|
-
assert_equal [-122.0574, 37.419200000000004],
|
395
|
-
assert_equal '[GEOIP] message => {"lat":37.419200000000004, "lon":-122.0574}',
|
384
|
+
assert_equal location_properties, events[0][2]['location_properties']
|
385
|
+
assert_equal '37.419200000000004,-122.0574', events[0][2]['location_string']
|
386
|
+
assert_equal 'US', events[0][2]['location_string2']
|
387
|
+
assert_equal [-122.0574, 37.419200000000004], events[0][2]['location_array']
|
388
|
+
assert_equal [-122.0574, 37.419200000000004], events[0][2]['location_array2']
|
389
|
+
assert_equal '[GEOIP] message => {"lat":37.419200000000004, "lon":-122.0574}', events[0][2]['peculiar_pattern']
|
396
390
|
end
|
397
391
|
|
398
392
|
def test_emit_multiline_v1_config
|
@@ -407,17 +401,16 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
407
401
|
"longitude": "${location.longitude['host']}"
|
408
402
|
}
|
409
403
|
</record>
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
404
|
+
tag geoip.${tag[1]}
|
405
|
+
])
|
406
|
+
d1.run(default_tag: 'input.access') do
|
407
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
415
408
|
end
|
416
|
-
|
417
|
-
assert_equal 1,
|
418
|
-
assert_equal 'geoip.access',
|
409
|
+
events = d1.events
|
410
|
+
assert_equal 1, events.length
|
411
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
419
412
|
location_properties = { "city"=>"Mountain View", "country_code"=>"US", "latitude"=>37.419200000000004, "longitude"=>-122.0574 }
|
420
|
-
assert_equal location_properties,
|
413
|
+
assert_equal location_properties, events[0][2]['location_properties']
|
421
414
|
end
|
422
415
|
end
|
423
416
|
|
@@ -429,18 +422,17 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
429
422
|
<record>
|
430
423
|
geoip_city ${city['host']}
|
431
424
|
</record>
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
d1.
|
437
|
-
d1.emit({'message' => 'missing field'})
|
425
|
+
tag geoip.${tag[1]}
|
426
|
+
])
|
427
|
+
d1.run(default_tag: 'input.access') do
|
428
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
429
|
+
d1.feed({'message' => 'missing field'})
|
438
430
|
end
|
439
|
-
|
440
|
-
assert_equal 2,
|
441
|
-
assert_equal 'geoip.access',
|
442
|
-
assert_equal 'Mountain View',
|
443
|
-
assert_equal nil,
|
431
|
+
events = d1.events
|
432
|
+
assert_equal 2, events.length
|
433
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
434
|
+
assert_equal 'Mountain View', events[0][2]['geoip_city']
|
435
|
+
assert_equal nil, events[1][2]['geoip_city']
|
444
436
|
end
|
445
437
|
|
446
438
|
def test_emit_tag_parts
|
@@ -450,15 +442,15 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
450
442
|
<record>
|
451
443
|
geoip_city ${city['host']}
|
452
444
|
</record>
|
453
|
-
tag geoip.${
|
454
|
-
]
|
455
|
-
d1.run do
|
456
|
-
d1.
|
445
|
+
tag geoip.${tag[1]}.${tag[2]}.${tag[3]}
|
446
|
+
])
|
447
|
+
d1.run(default_tag: '0.1.2.3') do
|
448
|
+
d1.feed({'host' => '66.102.3.80'})
|
457
449
|
end
|
458
|
-
|
459
|
-
assert_equal 1,
|
460
|
-
assert_equal 'geoip.1.2.3
|
461
|
-
assert_equal 'Mountain View',
|
450
|
+
events = d1.events
|
451
|
+
assert_equal 1, events.length
|
452
|
+
assert_equal 'geoip.1.2.3', events[0][0] # tag
|
453
|
+
assert_equal 'Mountain View', events[0][2]['geoip_city']
|
462
454
|
end
|
463
455
|
|
464
456
|
def test_emit_with_dot_key
|
@@ -469,17 +461,16 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
469
461
|
origin_country ${country_code['ip.origin']}
|
470
462
|
dest_country ${country_code['ip.dest']}
|
471
463
|
</record>
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
d1.emit({'ip.origin' => '66.102.3.80', 'ip.dest' => '8.8.8.8'})
|
464
|
+
tag geoip.${tag[1]}
|
465
|
+
])
|
466
|
+
d1.run(default_tag: 'input.access') do
|
467
|
+
d1.feed({'ip.origin' => '66.102.3.80', 'ip.dest' => '8.8.8.8'})
|
477
468
|
end
|
478
|
-
|
479
|
-
assert_equal 1,
|
480
|
-
assert_equal 'geoip.access',
|
481
|
-
assert_equal 'US',
|
482
|
-
assert_equal 'US',
|
469
|
+
events = d1.events
|
470
|
+
assert_equal 1, events.length
|
471
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
472
|
+
assert_equal 'US', events[0][2]['origin_country']
|
473
|
+
assert_equal 'US', events[0][2]['dest_country']
|
483
474
|
end
|
484
475
|
|
485
476
|
def test_emit_with_unknown_address
|
@@ -491,20 +482,19 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
491
482
|
geopoint [${longitude['host']}, ${latitude['host']}]
|
492
483
|
</record>
|
493
484
|
skip_adding_null_record false
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
d1.run do
|
485
|
+
tag geoip.${tag[1]}
|
486
|
+
], syntax: :v0)
|
487
|
+
d1.run(default_tag: 'input.access') do
|
498
488
|
# 203.0.113.1 is a test address described in RFC5737
|
499
|
-
d1.
|
500
|
-
d1.
|
489
|
+
d1.feed({'host' => '203.0.113.1', 'message' => 'invalid ip'})
|
490
|
+
d1.feed({'host' => '0', 'message' => 'invalid ip'})
|
501
491
|
end
|
502
|
-
|
503
|
-
assert_equal 2,
|
504
|
-
assert_equal 'geoip.access',
|
505
|
-
assert_equal nil,
|
506
|
-
assert_equal 'geoip.access',
|
507
|
-
assert_equal nil,
|
492
|
+
events = d1.events
|
493
|
+
assert_equal 2, events.length
|
494
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
495
|
+
assert_equal nil, events[0][2]['geoip_city']
|
496
|
+
assert_equal 'geoip.access', events[1][0] # tag
|
497
|
+
assert_equal nil, events[1][2]['geoip_city']
|
508
498
|
end
|
509
499
|
|
510
500
|
def test_emit_with_skip_unknown_address
|
@@ -516,25 +506,24 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
516
506
|
geopoint [${longitude['host']}, ${latitude['host']}]
|
517
507
|
</record>
|
518
508
|
skip_adding_null_record true
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
d1.run do
|
509
|
+
tag geoip.${tag[1]}
|
510
|
+
], syntax: :v0)
|
511
|
+
d1.run(default_tag: 'input.access') do
|
523
512
|
# 203.0.113.1 is a test address described in RFC5737
|
524
|
-
d1.
|
525
|
-
d1.
|
526
|
-
d1.
|
513
|
+
d1.feed({'host' => '203.0.113.1', 'message' => 'invalid ip'})
|
514
|
+
d1.feed({'host' => '0', 'message' => 'invalid ip'})
|
515
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'google bot'})
|
527
516
|
end
|
528
|
-
|
529
|
-
assert_equal 3,
|
530
|
-
assert_equal 'geoip.access',
|
531
|
-
assert_equal nil,
|
532
|
-
assert_equal nil,
|
533
|
-
assert_equal 'geoip.access',
|
534
|
-
assert_equal nil,
|
535
|
-
assert_equal nil,
|
536
|
-
assert_equal 'Mountain View',
|
537
|
-
assert_equal [-122.0574, 37.419200000000004],
|
517
|
+
events = d1.events
|
518
|
+
assert_equal 3, events.length
|
519
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
520
|
+
assert_equal nil, events[0][2]['geoip_city']
|
521
|
+
assert_equal nil, events[0][2]['geopoint']
|
522
|
+
assert_equal 'geoip.access', events[1][0] # tag
|
523
|
+
assert_equal nil, events[1][2]['geoip_city']
|
524
|
+
assert_equal nil, events[1][2]['geopoint']
|
525
|
+
assert_equal 'Mountain View', events[2][2]['geoip_city']
|
526
|
+
assert_equal [-122.0574, 37.419200000000004], events[2][2]['geopoint']
|
538
527
|
end
|
539
528
|
|
540
529
|
def test_emit_record_directive
|
@@ -557,50 +546,49 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
557
546
|
broken_array1 [${longitude['from.ip']}, ${latitude['undefined']}]
|
558
547
|
broken_array2 [${longitude['undefined']}, ${latitude['undefined']}]
|
559
548
|
</record>
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
d1.
|
565
|
-
d1.emit({'message' => 'missing field'})
|
549
|
+
tag geoip.${tag[1]}
|
550
|
+
], syntax: :v0)
|
551
|
+
d1.run(default_tag: 'input.access') do
|
552
|
+
d1.feed({'from' => {'ip' => '66.102.3.80'}})
|
553
|
+
d1.feed({'message' => 'missing field'})
|
566
554
|
end
|
567
|
-
|
568
|
-
assert_equal 2,
|
569
|
-
|
570
|
-
assert_equal 'geoip.access',
|
571
|
-
assert_equal 'Mountain View',
|
572
|
-
assert_equal 'United States',
|
573
|
-
assert_equal 37.419200000000004,
|
574
|
-
assert_equal -122.0574,
|
575
|
-
assert_equal '37.419200000000004,-122.0574',
|
576
|
-
assert_equal [-122.0574, 37.419200000000004],
|
555
|
+
events = d1.events
|
556
|
+
assert_equal 2, events.length
|
557
|
+
|
558
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
559
|
+
assert_equal 'Mountain View', events[0][2]['from_city']
|
560
|
+
assert_equal 'United States', events[0][2]['from_country']
|
561
|
+
assert_equal 37.419200000000004, events[0][2]['latitude']
|
562
|
+
assert_equal -122.0574, events[0][2]['longitude']
|
563
|
+
assert_equal '37.419200000000004,-122.0574', events[0][2]['float_concat']
|
564
|
+
assert_equal [-122.0574, 37.419200000000004], events[0][2]['float_array']
|
577
565
|
float_nest = {"lat" => 37.419200000000004, "lon" => -122.0574 }
|
578
|
-
assert_equal float_nest,
|
579
|
-
assert_equal '37.419200000000004,-122.0574',
|
580
|
-
assert_equal ["Mountain View", "United States"],
|
566
|
+
assert_equal float_nest, events[0][2]['float_nest']
|
567
|
+
assert_equal '37.419200000000004,-122.0574', events[0][2]['string_concat']
|
568
|
+
assert_equal ["Mountain View", "United States"], events[0][2]['string_array']
|
581
569
|
string_nest = {"city" => "Mountain View", "country_name" => "United States"}
|
582
|
-
assert_equal string_nest,
|
583
|
-
assert_equal nil,
|
584
|
-
assert_equal nil,
|
585
|
-
assert_equal [-122.0574, nil],
|
586
|
-
assert_equal [nil, nil],
|
587
|
-
|
588
|
-
assert_equal nil,
|
589
|
-
assert_equal nil,
|
590
|
-
assert_equal nil,
|
591
|
-
assert_equal nil,
|
592
|
-
assert_equal ',',
|
593
|
-
assert_equal [nil, nil],
|
570
|
+
assert_equal string_nest, events[0][2]['string_nest']
|
571
|
+
assert_equal nil, events[0][2]['unknown_city']
|
572
|
+
assert_equal nil, events[0][2]['undefined']
|
573
|
+
assert_equal [-122.0574, nil], events[0][2]['broken_array1']
|
574
|
+
assert_equal [nil, nil], events[0][2]['broken_array2']
|
575
|
+
|
576
|
+
assert_equal nil, events[1][2]['from_city']
|
577
|
+
assert_equal nil, events[1][2]['from_country']
|
578
|
+
assert_equal nil, events[1][2]['latitude']
|
579
|
+
assert_equal nil, events[1][2]['longitude']
|
580
|
+
assert_equal ',', events[1][2]['float_concat']
|
581
|
+
assert_equal [nil, nil], events[1][2]['float_array']
|
594
582
|
float_nest = {"lat" => nil, "lon" => nil}
|
595
|
-
assert_equal float_nest,
|
596
|
-
assert_equal ',',
|
597
|
-
assert_equal [nil, nil],
|
583
|
+
assert_equal float_nest, events[1][2]['float_nest']
|
584
|
+
assert_equal ',', events[1][2]['string_concat']
|
585
|
+
assert_equal [nil, nil], events[1][2]['string_array']
|
598
586
|
string_nest = {"city" => nil, "country_name" => nil}
|
599
|
-
assert_equal string_nest,
|
600
|
-
assert_equal nil,
|
601
|
-
assert_equal nil,
|
602
|
-
assert_equal [nil, nil],
|
603
|
-
assert_equal [nil, nil],
|
587
|
+
assert_equal string_nest, events[1][2]['string_nest']
|
588
|
+
assert_equal nil, events[1][2]['unknown_city']
|
589
|
+
assert_equal nil, events[1][2]['undefined']
|
590
|
+
assert_equal [nil, nil], events[1][2]['broken_array1']
|
591
|
+
assert_equal [nil, nil], events[1][2]['broken_array2']
|
604
592
|
end
|
605
593
|
|
606
594
|
def test_emit_record_directive_multiple_record
|
@@ -614,28 +602,27 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
614
602
|
to_country ${country_name['to.ip']}
|
615
603
|
string_array [${country_name['from.ip']}, ${country_name['to.ip']}]
|
616
604
|
</record>
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
d1.
|
622
|
-
d1.emit({'message' => 'missing field'})
|
605
|
+
tag geoip.${tag[1]}
|
606
|
+
], syntax: :v0)
|
607
|
+
d1.run(default_tag: 'input.access') do
|
608
|
+
d1.feed({'from' => {'ip' => '66.102.3.80'}, 'to' => {'ip' => '125.54.15.42'}})
|
609
|
+
d1.feed({'message' => 'missing field'})
|
623
610
|
end
|
624
|
-
|
625
|
-
assert_equal 2,
|
626
|
-
|
627
|
-
assert_equal 'geoip.access',
|
628
|
-
assert_equal 'Mountain View',
|
629
|
-
assert_equal 'United States',
|
630
|
-
assert_equal 'Tokorozawa',
|
631
|
-
assert_equal 'Japan',
|
632
|
-
assert_equal ['United States','Japan'],
|
633
|
-
|
634
|
-
assert_equal nil,
|
635
|
-
assert_equal nil,
|
636
|
-
assert_equal nil,
|
637
|
-
assert_equal nil,
|
638
|
-
assert_equal [nil, nil],
|
611
|
+
events = d1.events
|
612
|
+
assert_equal 2, events.length
|
613
|
+
|
614
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
615
|
+
assert_equal 'Mountain View', events[0][2]['from_city']
|
616
|
+
assert_equal 'United States', events[0][2]['from_country']
|
617
|
+
assert_equal 'Tokorozawa', events[0][2]['to_city']
|
618
|
+
assert_equal 'Japan', events[0][2]['to_country']
|
619
|
+
assert_equal ['United States','Japan'], events[0][2]['string_array']
|
620
|
+
|
621
|
+
assert_equal nil, events[1][2]['from_city']
|
622
|
+
assert_equal nil, events[1][2]['to_city']
|
623
|
+
assert_equal nil, events[1][2]['from_country']
|
624
|
+
assert_equal nil, events[1][2]['to_country']
|
625
|
+
assert_equal [nil, nil], events[1][2]['string_array']
|
639
626
|
end
|
640
627
|
|
641
628
|
def config_quoted_record
|
@@ -650,43 +637,42 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
650
637
|
location_array2 '[${longitude["host"]},${latitude["host"]}]'
|
651
638
|
peculiar_pattern '[GEOIP] message => {"lat":${latitude["host"]}, "lon":${longitude["host"]}}'
|
652
639
|
</record>
|
653
|
-
|
654
|
-
tag geoip.${tag}
|
640
|
+
tag geoip.${tag[1]}
|
655
641
|
]
|
656
642
|
end
|
657
643
|
|
658
644
|
def test_emit_quoted_record
|
659
|
-
d1 = create_driver(config_quoted_record
|
660
|
-
d1.run do
|
661
|
-
d1.
|
645
|
+
d1 = create_driver(config_quoted_record)
|
646
|
+
d1.run(default_tag: 'input.access') do
|
647
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
662
648
|
end
|
663
|
-
|
664
|
-
assert_equal 1,
|
665
|
-
assert_equal 'geoip.access',
|
649
|
+
events = d1.events
|
650
|
+
assert_equal 1, events.length
|
651
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
666
652
|
location_properties = { "country_code" => "US", "lat" => 37.419200000000004, "lon"=> -122.0574 }
|
667
|
-
assert_equal location_properties,
|
668
|
-
assert_equal '37.419200000000004,-122.0574',
|
669
|
-
assert_equal 'US',
|
670
|
-
assert_equal [-122.0574, 37.419200000000004],
|
671
|
-
assert_equal [-122.0574, 37.419200000000004],
|
672
|
-
assert_equal '[GEOIP] message => {"lat":37.419200000000004, "lon":-122.0574}',
|
653
|
+
assert_equal location_properties, events[0][2]['location_properties']
|
654
|
+
assert_equal '37.419200000000004,-122.0574', events[0][2]['location_string']
|
655
|
+
assert_equal 'US', events[0][2]['location_string2']
|
656
|
+
assert_equal [-122.0574, 37.419200000000004], events[0][2]['location_array']
|
657
|
+
assert_equal [-122.0574, 37.419200000000004], events[0][2]['location_array2']
|
658
|
+
assert_equal '[GEOIP] message => {"lat":37.419200000000004, "lon":-122.0574}', events[0][2]['peculiar_pattern']
|
673
659
|
end
|
674
660
|
|
675
661
|
def test_emit_v1_config_compatibility
|
676
|
-
d1 = create_driver(config_quoted_record
|
677
|
-
d1.run do
|
678
|
-
d1.
|
662
|
+
d1 = create_driver(config_quoted_record)
|
663
|
+
d1.run(default_tag: 'input.access') do
|
664
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
679
665
|
end
|
680
|
-
|
681
|
-
assert_equal 1,
|
682
|
-
assert_equal 'geoip.access',
|
666
|
+
events = d1.events
|
667
|
+
assert_equal 1, events.length
|
668
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
683
669
|
location_properties = { "country_code" => "US", "lat" => 37.419200000000004, "lon"=> -122.0574 }
|
684
|
-
assert_equal location_properties,
|
685
|
-
assert_equal '37.419200000000004,-122.0574',
|
686
|
-
assert_equal 'US',
|
687
|
-
assert_equal [-122.0574, 37.419200000000004],
|
688
|
-
assert_equal [-122.0574, 37.419200000000004],
|
689
|
-
assert_equal '[GEOIP] message => {"lat":37.419200000000004, "lon":-122.0574}',
|
670
|
+
assert_equal location_properties, events[0][2]['location_properties']
|
671
|
+
assert_equal '37.419200000000004,-122.0574', events[0][2]['location_string']
|
672
|
+
assert_equal 'US', events[0][2]['location_string2']
|
673
|
+
assert_equal [-122.0574, 37.419200000000004], events[0][2]['location_array']
|
674
|
+
assert_equal [-122.0574, 37.419200000000004], events[0][2]['location_array2']
|
675
|
+
assert_equal '[GEOIP] message => {"lat":37.419200000000004, "lon":-122.0574}', events[0][2]['peculiar_pattern']
|
690
676
|
end
|
691
677
|
|
692
678
|
def test_emit_multiline_v1_config
|
@@ -701,222 +687,222 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
701
687
|
"longitude": "${longitude['host']}"
|
702
688
|
}
|
703
689
|
</record>
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
690
|
+
tag geoip.${tag[1]}
|
691
|
+
])
|
692
|
+
d1.run(default_tag: 'input.access') do
|
693
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
709
694
|
end
|
710
|
-
|
711
|
-
assert_equal 1,
|
712
|
-
assert_equal 'geoip.access',
|
695
|
+
events = d1.events
|
696
|
+
assert_equal 1, events.length
|
697
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
713
698
|
location_properties = { "city"=>"Mountain View", "country_code"=>"US", "latitude"=>37.419200000000004, "longitude"=>-122.0574 }
|
714
|
-
assert_equal location_properties,
|
699
|
+
assert_equal location_properties, events[0][2]['location_properties']
|
715
700
|
end
|
716
701
|
end
|
717
702
|
|
718
703
|
sub_test_case "geoip legacy" do
|
719
704
|
def test_emit
|
720
705
|
d1 = create_driver(%[
|
706
|
+
backend_library geoip
|
721
707
|
geoip_lookup_key host
|
722
708
|
enable_key_city geoip_city
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
d1.
|
728
|
-
d1.emit({'message' => 'missing field'})
|
709
|
+
tag geoip.${tag[1]}
|
710
|
+
])
|
711
|
+
d1.run(default_tag: 'input.access') do
|
712
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
713
|
+
d1.feed({'message' => 'missing field'})
|
729
714
|
end
|
730
|
-
|
731
|
-
assert_equal 2,
|
732
|
-
assert_equal 'geoip.access',
|
733
|
-
assert_equal 'Mountain View',
|
734
|
-
assert_equal nil,
|
715
|
+
events = d1.events
|
716
|
+
assert_equal 2, events.length
|
717
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
718
|
+
assert_equal 'Mountain View', events[0][2]['geoip_city']
|
719
|
+
assert_equal nil, events[1][2]['geoip_city']
|
735
720
|
end
|
736
721
|
|
737
722
|
def test_emit_tag_option
|
738
723
|
d1 = create_driver(%[
|
724
|
+
backend_library geoip
|
739
725
|
geoip_lookup_key host
|
740
726
|
<record>
|
741
727
|
geoip_city ${city['host']}
|
742
728
|
</record>
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
d1.
|
748
|
-
d1.emit({'message' => 'missing field'})
|
729
|
+
tag geoip.${tag[1]}
|
730
|
+
])
|
731
|
+
d1.run(default_tag: 'input.access') do
|
732
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
733
|
+
d1.feed({'message' => 'missing field'})
|
749
734
|
end
|
750
|
-
|
751
|
-
assert_equal 2,
|
752
|
-
assert_equal 'geoip.access',
|
753
|
-
assert_equal 'Mountain View',
|
754
|
-
assert_equal nil,
|
735
|
+
events = d1.events
|
736
|
+
assert_equal 2, events.length
|
737
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
738
|
+
assert_equal 'Mountain View', events[0][2]['geoip_city']
|
739
|
+
assert_equal nil, events[1][2]['geoip_city']
|
755
740
|
end
|
756
741
|
|
757
742
|
def test_emit_tag_parts
|
758
743
|
d1 = create_driver(%[
|
744
|
+
backend_library geoip
|
759
745
|
geoip_lookup_key host
|
760
746
|
<record>
|
761
747
|
geoip_city ${city['host']}
|
762
748
|
</record>
|
763
|
-
tag geoip.${
|
764
|
-
]
|
765
|
-
d1.run do
|
766
|
-
d1.
|
749
|
+
tag geoip.${tag[1]}.${tag[2]}.${tag[3]}
|
750
|
+
])
|
751
|
+
d1.run(default_tag: '0.1.2.3') do
|
752
|
+
d1.feed({'host' => '66.102.3.80'})
|
767
753
|
end
|
768
|
-
|
769
|
-
assert_equal 1,
|
770
|
-
assert_equal 'geoip.1.2.3
|
771
|
-
assert_equal 'Mountain View',
|
754
|
+
events = d1.events
|
755
|
+
assert_equal 1, events.length
|
756
|
+
assert_equal 'geoip.1.2.3', events[0][0] # tag
|
757
|
+
assert_equal 'Mountain View', events[0][2]['geoip_city']
|
772
758
|
end
|
773
759
|
|
774
760
|
def test_emit_with_dot_key
|
775
761
|
d1 = create_driver(%[
|
762
|
+
backend_library geoip
|
776
763
|
geoip_lookup_key ip.origin, ip.dest
|
777
764
|
<record>
|
778
765
|
origin_country ${country_code['ip.origin']}
|
779
766
|
dest_country ${country_code['ip.dest']}
|
780
767
|
</record>
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
d1.emit({'ip.origin' => '66.102.3.80', 'ip.dest' => '8.8.8.8'})
|
768
|
+
tag geoip.${tag[1]}
|
769
|
+
])
|
770
|
+
d1.run(default_tag: 'input.access') do
|
771
|
+
d1.feed({'ip.origin' => '66.102.3.80', 'ip.dest' => '8.8.8.8'})
|
786
772
|
end
|
787
|
-
|
788
|
-
assert_equal 1,
|
789
|
-
assert_equal 'geoip.access',
|
790
|
-
assert_equal 'US',
|
791
|
-
assert_equal 'US',
|
773
|
+
events = d1.events
|
774
|
+
assert_equal 1, events.length
|
775
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
776
|
+
assert_equal 'US', events[0][2]['origin_country']
|
777
|
+
assert_equal 'US', events[0][2]['dest_country']
|
792
778
|
end
|
793
779
|
|
794
780
|
def test_emit_nested_attr
|
795
781
|
d1 = create_driver(%[
|
782
|
+
backend_library geoip
|
796
783
|
geoip_lookup_key host.ip
|
797
784
|
enable_key_city geoip_city
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
d1.
|
803
|
-
d1.emit({'message' => 'missing field'})
|
785
|
+
tag geoip.${tag[1]}
|
786
|
+
])
|
787
|
+
d1.run(default_tag: 'input.access') do
|
788
|
+
d1.feed({'host' => {'ip' => '66.102.3.80'}, 'message' => 'valid ip'})
|
789
|
+
d1.feed({'message' => 'missing field'})
|
804
790
|
end
|
805
|
-
|
806
|
-
assert_equal 2,
|
807
|
-
assert_equal 'geoip.access',
|
808
|
-
assert_equal 'Mountain View',
|
809
|
-
assert_equal nil,
|
791
|
+
events = d1.events
|
792
|
+
assert_equal 2, events.length
|
793
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
794
|
+
assert_equal 'Mountain View', events[0][2]['geoip_city']
|
795
|
+
assert_equal nil, events[1][2]['geoip_city']
|
810
796
|
end
|
811
797
|
|
812
798
|
def test_emit_with_unknown_address
|
813
799
|
d1 = create_driver(%[
|
800
|
+
backend_library geoip
|
814
801
|
geoip_lookup_key host
|
815
802
|
<record>
|
816
803
|
geoip_city ${city['host']}
|
817
804
|
geopoint [${longitude['host']}, ${latitude['host']}]
|
818
805
|
</record>
|
819
806
|
skip_adding_null_record false
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
d1.run do
|
807
|
+
tag geoip.${tag[1]}
|
808
|
+
], syntax: :v0)
|
809
|
+
d1.run(default_tag: 'input.access') do
|
824
810
|
# 203.0.113.1 is a test address described in RFC5737
|
825
|
-
d1.
|
826
|
-
d1.
|
811
|
+
d1.feed({'host' => '203.0.113.1', 'message' => 'invalid ip'})
|
812
|
+
d1.feed({'host' => '0', 'message' => 'invalid ip'})
|
827
813
|
end
|
828
|
-
|
829
|
-
assert_equal 2,
|
830
|
-
assert_equal 'geoip.access',
|
831
|
-
assert_equal nil,
|
832
|
-
assert_equal 'geoip.access',
|
833
|
-
assert_equal nil,
|
814
|
+
events = d1.events
|
815
|
+
assert_equal 2, events.length
|
816
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
817
|
+
assert_equal nil, events[0][2]['geoip_city']
|
818
|
+
assert_equal 'geoip.access', events[1][0] # tag
|
819
|
+
assert_equal nil, events[1][2]['geoip_city']
|
834
820
|
end
|
835
821
|
|
836
822
|
def test_emit_with_skip_unknown_address
|
837
823
|
d1 = create_driver(%[
|
824
|
+
backend_library geoip
|
838
825
|
geoip_lookup_key host
|
839
826
|
<record>
|
840
827
|
geoip_city ${city['host']}
|
841
828
|
geopoint [${longitude['host']}, ${latitude['host']}]
|
842
829
|
</record>
|
843
830
|
skip_adding_null_record true
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
d1.run do
|
831
|
+
tag geoip.${tag[1]}
|
832
|
+
], syntax: :v0)
|
833
|
+
d1.run(default_tag: 'input.access') do
|
848
834
|
# 203.0.113.1 is a test address described in RFC5737
|
849
|
-
d1.
|
850
|
-
d1.
|
851
|
-
d1.
|
835
|
+
d1.feed({'host' => '203.0.113.1', 'message' => 'invalid ip'})
|
836
|
+
d1.feed({'host' => '0', 'message' => 'invalid ip'})
|
837
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'google bot'})
|
852
838
|
end
|
853
|
-
|
854
|
-
assert_equal 3,
|
855
|
-
assert_equal 'geoip.access',
|
856
|
-
assert_equal nil,
|
857
|
-
assert_equal nil,
|
858
|
-
assert_equal 'geoip.access',
|
859
|
-
assert_equal nil,
|
860
|
-
assert_equal nil,
|
861
|
-
assert_equal 'Mountain View',
|
862
|
-
assert_equal [-122.05740356445312, 37.4192008972168],
|
863
|
-
|
839
|
+
events = d1.events
|
840
|
+
assert_equal 3, events.length
|
841
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
842
|
+
assert_equal nil, events[0][2]['geoip_city']
|
843
|
+
assert_equal nil, events[0][2]['geopoint']
|
844
|
+
assert_equal 'geoip.access', events[1][0] # tag
|
845
|
+
assert_equal nil, events[1][2]['geoip_city']
|
846
|
+
assert_equal nil, events[1][2]['geopoint']
|
847
|
+
assert_equal 'Mountain View', events[2][2]['geoip_city']
|
848
|
+
assert_equal [-122.05740356445312, 37.4192008972168], events[2][2]['geopoint']
|
864
849
|
end
|
865
850
|
|
866
851
|
def test_emit_multiple_key
|
867
852
|
d1 = create_driver(%[
|
853
|
+
backend_library geoip
|
868
854
|
geoip_lookup_key from.ip, to.ip
|
869
855
|
enable_key_city from_city, to_city
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
d1.
|
875
|
-
d1.emit({'message' => 'missing field'})
|
856
|
+
tag geoip.${tag[1]}
|
857
|
+
])
|
858
|
+
d1.run(default_tag: 'input.access') do
|
859
|
+
d1.feed({'from' => {'ip' => '66.102.3.80'}, 'to' => {'ip' => '125.54.15.42'}})
|
860
|
+
d1.feed({'message' => 'missing field'})
|
876
861
|
end
|
877
|
-
|
878
|
-
assert_equal 2,
|
879
|
-
assert_equal 'geoip.access',
|
880
|
-
assert_equal 'Mountain View',
|
881
|
-
assert_equal 'Tokorozawa',
|
882
|
-
assert_equal nil,
|
883
|
-
assert_equal nil,
|
862
|
+
events = d1.events
|
863
|
+
assert_equal 2, events.length
|
864
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
865
|
+
assert_equal 'Mountain View', events[0][2]['from_city']
|
866
|
+
assert_equal 'Tokorozawa', events[0][2]['to_city']
|
867
|
+
assert_equal nil, events[1][2]['from_city']
|
868
|
+
assert_equal nil, events[1][2]['to_city']
|
884
869
|
end
|
885
870
|
|
886
871
|
def test_emit_multiple_key_multiple_record
|
887
872
|
d1 = create_driver(%[
|
873
|
+
backend_library geoip
|
888
874
|
geoip_lookup_key from.ip, to.ip
|
889
875
|
enable_key_city from_city, to_city
|
890
876
|
enable_key_country_name from_country, to_country
|
891
|
-
|
892
|
-
|
893
|
-
|
894
|
-
|
895
|
-
d1.
|
896
|
-
d1.
|
897
|
-
d1.emit({'message' => 'missing field'})
|
877
|
+
tag geoip.${tag[1]}
|
878
|
+
])
|
879
|
+
d1.run(default_tag: 'input.access') do
|
880
|
+
d1.feed({'from' => {'ip' => '66.102.3.80'}, 'to' => {'ip' => '125.54.15.42'}})
|
881
|
+
d1.feed({'from' => {'ip' => '66.102.3.80'}})
|
882
|
+
d1.feed({'message' => 'missing field'})
|
898
883
|
end
|
899
|
-
|
900
|
-
assert_equal 3,
|
901
|
-
assert_equal 'geoip.access',
|
902
|
-
assert_equal 'Mountain View',
|
903
|
-
assert_equal 'United States',
|
904
|
-
assert_equal 'Tokorozawa',
|
905
|
-
assert_equal 'Japan',
|
906
|
-
|
907
|
-
assert_equal 'Mountain View',
|
908
|
-
assert_equal 'United States',
|
909
|
-
assert_equal nil,
|
910
|
-
assert_equal nil,
|
911
|
-
|
912
|
-
assert_equal nil,
|
913
|
-
assert_equal nil,
|
914
|
-
assert_equal nil,
|
915
|
-
assert_equal nil,
|
884
|
+
events = d1.events
|
885
|
+
assert_equal 3, events.length
|
886
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
887
|
+
assert_equal 'Mountain View', events[0][2]['from_city']
|
888
|
+
assert_equal 'United States', events[0][2]['from_country']
|
889
|
+
assert_equal 'Tokorozawa', events[0][2]['to_city']
|
890
|
+
assert_equal 'Japan', events[0][2]['to_country']
|
891
|
+
|
892
|
+
assert_equal 'Mountain View', events[1][2]['from_city']
|
893
|
+
assert_equal 'United States', events[1][2]['from_country']
|
894
|
+
assert_equal nil, events[1][2]['to_city']
|
895
|
+
assert_equal nil, events[1][2]['to_country']
|
896
|
+
|
897
|
+
assert_equal nil, events[2][2]['from_city']
|
898
|
+
assert_equal nil, events[2][2]['from_country']
|
899
|
+
assert_equal nil, events[2][2]['to_city']
|
900
|
+
assert_equal nil, events[2][2]['to_country']
|
916
901
|
end
|
917
902
|
|
918
903
|
def test_emit_record_directive
|
919
904
|
d1 = create_driver(%[
|
905
|
+
backend_library geoip
|
920
906
|
geoip_lookup_key from.ip
|
921
907
|
<record>
|
922
908
|
from_city ${city['from.ip']}
|
@@ -934,54 +920,54 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
934
920
|
broken_array1 [${longitude['from.ip']}, ${latitude['undefined']}]
|
935
921
|
broken_array2 [${longitude['undefined']}, ${latitude['undefined']}]
|
936
922
|
</record>
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
d1.
|
942
|
-
d1.emit({'message' => 'missing field'})
|
923
|
+
tag geoip.${tag[1]}
|
924
|
+
], syntax: :v0)
|
925
|
+
d1.run(default_tag: 'input.access') do
|
926
|
+
d1.feed({'from' => {'ip' => '66.102.3.80'}})
|
927
|
+
d1.feed({'message' => 'missing field'})
|
943
928
|
end
|
944
|
-
|
945
|
-
assert_equal 2,
|
946
|
-
|
947
|
-
assert_equal 'geoip.access',
|
948
|
-
assert_equal 'Mountain View',
|
949
|
-
assert_equal 'United States',
|
950
|
-
assert_equal 37.4192008972168,
|
951
|
-
assert_equal -122.05740356445312,
|
952
|
-
assert_equal '37.4192008972168,-122.05740356445312',
|
953
|
-
assert_equal [-122.05740356445312, 37.4192008972168],
|
929
|
+
events = d1.events
|
930
|
+
assert_equal 2, events.length
|
931
|
+
|
932
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
933
|
+
assert_equal 'Mountain View', events[0][2]['from_city']
|
934
|
+
assert_equal 'United States', events[0][2]['from_country']
|
935
|
+
assert_equal 37.4192008972168, events[0][2]['latitude']
|
936
|
+
assert_equal -122.05740356445312, events[0][2]['longitude']
|
937
|
+
assert_equal '37.4192008972168,-122.05740356445312', events[0][2]['float_concat']
|
938
|
+
assert_equal [-122.05740356445312, 37.4192008972168], events[0][2]['float_array']
|
954
939
|
float_nest = {"lat" => 37.4192008972168, "lon" => -122.05740356445312 }
|
955
|
-
assert_equal float_nest,
|
956
|
-
assert_equal '37.4192008972168,-122.05740356445312',
|
957
|
-
assert_equal ["Mountain View", "United States"],
|
940
|
+
assert_equal float_nest, events[0][2]['float_nest']
|
941
|
+
assert_equal '37.4192008972168,-122.05740356445312', events[0][2]['string_concat']
|
942
|
+
assert_equal ["Mountain View", "United States"], events[0][2]['string_array']
|
958
943
|
string_nest = {"city" => "Mountain View", "country_name" => "United States"}
|
959
|
-
assert_equal string_nest,
|
960
|
-
assert_equal nil,
|
961
|
-
assert_equal nil,
|
962
|
-
assert_equal [-122.05740356445312, nil],
|
963
|
-
assert_equal [nil, nil],
|
964
|
-
|
965
|
-
assert_equal nil,
|
966
|
-
assert_equal nil,
|
967
|
-
assert_equal nil,
|
968
|
-
assert_equal nil,
|
969
|
-
assert_equal ',',
|
970
|
-
assert_equal [nil, nil],
|
944
|
+
assert_equal string_nest, events[0][2]['string_nest']
|
945
|
+
assert_equal nil, events[0][2]['unknown_city']
|
946
|
+
assert_equal nil, events[0][2]['undefined']
|
947
|
+
assert_equal [-122.05740356445312, nil], events[0][2]['broken_array1']
|
948
|
+
assert_equal [nil, nil], events[0][2]['broken_array2']
|
949
|
+
|
950
|
+
assert_equal nil, events[1][2]['from_city']
|
951
|
+
assert_equal nil, events[1][2]['from_country']
|
952
|
+
assert_equal nil, events[1][2]['latitude']
|
953
|
+
assert_equal nil, events[1][2]['longitude']
|
954
|
+
assert_equal ',', events[1][2]['float_concat']
|
955
|
+
assert_equal [nil, nil], events[1][2]['float_array']
|
971
956
|
float_nest = {"lat" => nil, "lon" => nil}
|
972
|
-
assert_equal float_nest,
|
973
|
-
assert_equal ',',
|
974
|
-
assert_equal [nil, nil],
|
957
|
+
assert_equal float_nest, events[1][2]['float_nest']
|
958
|
+
assert_equal ',', events[1][2]['string_concat']
|
959
|
+
assert_equal [nil, nil], events[1][2]['string_array']
|
975
960
|
string_nest = {"city" => nil, "country_name" => nil}
|
976
|
-
assert_equal string_nest,
|
977
|
-
assert_equal nil,
|
978
|
-
assert_equal nil,
|
979
|
-
assert_equal [nil, nil],
|
980
|
-
assert_equal [nil, nil],
|
961
|
+
assert_equal string_nest, events[1][2]['string_nest']
|
962
|
+
assert_equal nil, events[1][2]['unknown_city']
|
963
|
+
assert_equal nil, events[1][2]['undefined']
|
964
|
+
assert_equal [nil, nil], events[1][2]['broken_array1']
|
965
|
+
assert_equal [nil, nil], events[1][2]['broken_array2']
|
981
966
|
end
|
982
967
|
|
983
968
|
def test_emit_record_directive_multiple_record
|
984
969
|
d1 = create_driver(%[
|
970
|
+
backend_library geoip
|
985
971
|
geoip_lookup_key from.ip, to.ip
|
986
972
|
<record>
|
987
973
|
from_city ${city['from.ip']}
|
@@ -990,32 +976,32 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
990
976
|
to_country ${country_name['to.ip']}
|
991
977
|
string_array [${country_name['from.ip']}, ${country_name['to.ip']}]
|
992
978
|
</record>
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
d1.
|
998
|
-
d1.emit({'message' => 'missing field'})
|
979
|
+
tag geoip.${tag[1]}
|
980
|
+
], syntax: :v0)
|
981
|
+
d1.run(default_tag: 'input.access') do
|
982
|
+
d1.feed({'from' => {'ip' => '66.102.3.80'}, 'to' => {'ip' => '125.54.15.42'}})
|
983
|
+
d1.feed({'message' => 'missing field'})
|
999
984
|
end
|
1000
|
-
|
1001
|
-
assert_equal 2,
|
1002
|
-
|
1003
|
-
assert_equal 'geoip.access',
|
1004
|
-
assert_equal 'Mountain View',
|
1005
|
-
assert_equal 'United States',
|
1006
|
-
assert_equal 'Tokorozawa',
|
1007
|
-
assert_equal 'Japan',
|
1008
|
-
assert_equal ['United States','Japan'],
|
1009
|
-
|
1010
|
-
assert_equal nil,
|
1011
|
-
assert_equal nil,
|
1012
|
-
assert_equal nil,
|
1013
|
-
assert_equal nil,
|
1014
|
-
assert_equal [nil, nil],
|
985
|
+
events = d1.events
|
986
|
+
assert_equal 2, events.length
|
987
|
+
|
988
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
989
|
+
assert_equal 'Mountain View', events[0][2]['from_city']
|
990
|
+
assert_equal 'United States', events[0][2]['from_country']
|
991
|
+
assert_equal 'Tokorozawa', events[0][2]['to_city']
|
992
|
+
assert_equal 'Japan', events[0][2]['to_country']
|
993
|
+
assert_equal ['United States','Japan'], events[0][2]['string_array']
|
994
|
+
|
995
|
+
assert_equal nil, events[1][2]['from_city']
|
996
|
+
assert_equal nil, events[1][2]['to_city']
|
997
|
+
assert_equal nil, events[1][2]['from_country']
|
998
|
+
assert_equal nil, events[1][2]['to_country']
|
999
|
+
assert_equal [nil, nil], events[1][2]['string_array']
|
1015
1000
|
end
|
1016
1001
|
|
1017
1002
|
def config_quoted_record
|
1018
1003
|
%[
|
1004
|
+
backend_library geoip
|
1019
1005
|
geoip_lookup_key host
|
1020
1006
|
<record>
|
1021
1007
|
location_properties '{ "country_code" : "${country_code["host"]}", "lat": ${latitude["host"]}, "lon": ${longitude["host"]} }'
|
@@ -1025,47 +1011,47 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
1025
1011
|
location_array2 '[${longitude["host"]},${latitude["host"]}]'
|
1026
1012
|
peculiar_pattern '[GEOIP] message => {"lat":${latitude["host"]}, "lon":${longitude["host"]}}'
|
1027
1013
|
</record>
|
1028
|
-
|
1029
|
-
tag geoip.${tag}
|
1014
|
+
tag geoip.${tag[1]}
|
1030
1015
|
]
|
1031
1016
|
end
|
1032
1017
|
|
1033
1018
|
def test_emit_quoted_record
|
1034
|
-
d1 = create_driver(config_quoted_record
|
1035
|
-
d1.run do
|
1036
|
-
d1.
|
1019
|
+
d1 = create_driver(config_quoted_record)
|
1020
|
+
d1.run(default_tag: 'input.access') do
|
1021
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
1037
1022
|
end
|
1038
|
-
|
1039
|
-
assert_equal 1,
|
1040
|
-
assert_equal 'geoip.access',
|
1023
|
+
events = d1.events
|
1024
|
+
assert_equal 1, events.length
|
1025
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
1041
1026
|
location_properties = { "country_code" => "US", "lat" => 37.4192008972168, "lon"=> -122.05740356445312 }
|
1042
|
-
assert_equal location_properties,
|
1043
|
-
assert_equal '37.4192008972168,-122.05740356445312',
|
1044
|
-
assert_equal 'US',
|
1045
|
-
assert_equal [-122.05740356445312, 37.4192008972168],
|
1046
|
-
assert_equal [-122.05740356445312, 37.4192008972168],
|
1047
|
-
assert_equal '[GEOIP] message => {"lat":37.4192008972168, "lon":-122.05740356445312}',
|
1027
|
+
assert_equal location_properties, events[0][2]['location_properties']
|
1028
|
+
assert_equal '37.4192008972168,-122.05740356445312', events[0][2]['location_string']
|
1029
|
+
assert_equal 'US', events[0][2]['location_string2']
|
1030
|
+
assert_equal [-122.05740356445312, 37.4192008972168], events[0][2]['location_array']
|
1031
|
+
assert_equal [-122.05740356445312, 37.4192008972168], events[0][2]['location_array2']
|
1032
|
+
assert_equal '[GEOIP] message => {"lat":37.4192008972168, "lon":-122.05740356445312}', events[0][2]['peculiar_pattern']
|
1048
1033
|
end
|
1049
1034
|
|
1050
1035
|
def test_emit_v1_config_compatibility
|
1051
|
-
d1 = create_driver(config_quoted_record
|
1052
|
-
d1.run do
|
1053
|
-
d1.
|
1036
|
+
d1 = create_driver(config_quoted_record)
|
1037
|
+
d1.run(default_tag: 'input.access') do
|
1038
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
1054
1039
|
end
|
1055
|
-
|
1056
|
-
assert_equal 1,
|
1057
|
-
assert_equal 'geoip.access',
|
1040
|
+
events = d1.events
|
1041
|
+
assert_equal 1, events.length
|
1042
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
1058
1043
|
location_properties = { "country_code" => "US", "lat" => 37.4192008972168, "lon"=> -122.05740356445312 }
|
1059
|
-
assert_equal location_properties,
|
1060
|
-
assert_equal '37.4192008972168,-122.05740356445312',
|
1061
|
-
assert_equal 'US',
|
1062
|
-
assert_equal [-122.05740356445312, 37.4192008972168],
|
1063
|
-
assert_equal [-122.05740356445312, 37.4192008972168],
|
1064
|
-
assert_equal '[GEOIP] message => {"lat":37.4192008972168, "lon":-122.05740356445312}',
|
1044
|
+
assert_equal location_properties, events[0][2]['location_properties']
|
1045
|
+
assert_equal '37.4192008972168,-122.05740356445312', events[0][2]['location_string']
|
1046
|
+
assert_equal 'US', events[0][2]['location_string2']
|
1047
|
+
assert_equal [-122.05740356445312, 37.4192008972168], events[0][2]['location_array']
|
1048
|
+
assert_equal [-122.05740356445312, 37.4192008972168], events[0][2]['location_array2']
|
1049
|
+
assert_equal '[GEOIP] message => {"lat":37.4192008972168, "lon":-122.05740356445312}', events[0][2]['peculiar_pattern']
|
1065
1050
|
end
|
1066
1051
|
|
1067
1052
|
def test_emit_multiline_v1_config
|
1068
1053
|
d1 = create_driver(%[
|
1054
|
+
backend_library geoip
|
1069
1055
|
geoip_lookup_key host
|
1070
1056
|
<record>
|
1071
1057
|
location_properties {
|
@@ -1075,17 +1061,16 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
1075
1061
|
"longitude": "${longitude['host']}"
|
1076
1062
|
}
|
1077
1063
|
</record>
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
1064
|
+
tag geoip.${tag[1]}
|
1065
|
+
])
|
1066
|
+
d1.run(default_tag: 'input.access') do
|
1067
|
+
d1.feed({'host' => '66.102.3.80', 'message' => 'valid ip'})
|
1083
1068
|
end
|
1084
|
-
|
1085
|
-
assert_equal 1,
|
1086
|
-
assert_equal 'geoip.access',
|
1069
|
+
events = d1.events
|
1070
|
+
assert_equal 1, events.length
|
1071
|
+
assert_equal 'geoip.access', events[0][0] # tag
|
1087
1072
|
location_properties = { "city"=>"Mountain View", "country_code"=>"US", "latitude"=>37.4192008972168, "longitude"=>-122.05740356445312 }
|
1088
|
-
assert_equal location_properties,
|
1073
|
+
assert_equal location_properties, events[0][2]['location_properties']
|
1089
1074
|
end
|
1090
1075
|
end
|
1091
1076
|
end
|