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.
@@ -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
- def create_driver(conf='',tag='test',use_v1=false)
9
- require 'fluent/version'
10
- if Gem::Version.new(Fluent::VERSION) < Gem::Version.new('0.12')
11
- Fluent::Test::OutputTestDriver.new(Fluent::GeoipOutput, tag).configure(conf, use_v1)
12
- else
13
- Fluent::Test::BufferedOutputTestDriver.new(Fluent::GeoipOutput, tag).configure(conf, use_v1)
14
- end
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
- assert_raise(Fluent::ConfigError) {
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
- remove_tag_prefix input.
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
- remove_tag_prefix input.
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
- remove_tag_prefix input.
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::ConfigError) {
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
- remove_tag_prefix input.
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::ConfigError) {
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
- remove_tag_prefix input.
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
- remove_tag_prefix input.
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
- remove_tag_prefix input.
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
- remove_tag_prefix input.
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
- remove_tag_prefix input.
139
- tag geoip.${tag}
140
- ], 'input.access')
141
- d1.run do
142
- d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
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
- emits = d1.emits
146
- assert_equal 2, emits.length
147
- assert_equal 'geoip.access', emits[0][0] # tag
148
- assert_equal 'Mountain View', emits[0][2]['geoip_city']
149
- assert_equal nil, emits[1][2]['geoip_city']
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.${tag_parts[1]}.${tag_parts[2..3]}.${tag_parts[-1]}
160
- ], '0.1.2.3')
161
- d1.run do
162
- d1.emit({'host' => '66.102.3.80'})
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
- emits = d1.emits
165
- assert_equal 1, emits.length
166
- assert_equal 'geoip.1.2.3.3', emits[0][0] # tag
167
- assert_equal 'Mountain View', emits[0][2]['geoip_city']
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
- remove_tag_prefix input.
179
- tag geoip.${tag}
180
- ], 'input.access')
181
- d1.run do
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
- emits = d1.emits
185
- assert_equal 1, emits.length
186
- assert_equal 'geoip.access', emits[0][0] # tag
187
- assert_equal 'US', emits[0][2]['origin_country']
188
- assert_equal 'US', emits[0][2]['dest_country']
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
- remove_tag_prefix input.
201
- tag geoip.${tag}
202
- ], 'input.access')
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.emit({'host' => '203.0.113.1', 'message' => 'invalid ip'})
206
- d1.emit({'host' => '0', 'message' => 'invalid ip'})
203
+ d1.feed({'host' => '203.0.113.1', 'message' => 'invalid ip'})
204
+ d1.feed({'host' => '0', 'message' => 'invalid ip'})
207
205
  end
208
- emits = d1.emits
209
- assert_equal 2, emits.length
210
- assert_equal 'geoip.access', emits[0][0] # tag
211
- assert_equal nil, emits[0][2]['geoip_city']
212
- assert_equal 'geoip.access', emits[1][0] # tag
213
- assert_equal nil, emits[1][2]['geoip_city']
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
- remove_tag_prefix input.
226
- tag geoip.${tag}
227
- ], 'input.access')
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.emit({'host' => '203.0.113.1', 'message' => 'invalid ip'})
231
- d1.emit({'host' => '0', 'message' => 'invalid ip'})
232
- d1.emit({'host' => '66.102.3.80', 'message' => 'google bot'})
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
- emits = d1.emits
235
- assert_equal 3, emits.length
236
- assert_equal 'geoip.access', emits[0][0] # tag
237
- assert_equal nil, emits[0][2]['geoip_city']
238
- assert_equal nil, emits[0][2]['geopoint']
239
- assert_equal 'geoip.access', emits[1][0] # tag
240
- assert_equal nil, emits[1][2]['geoip_city']
241
- assert_equal nil, emits[1][2]['geopoint']
242
- assert_equal 'Mountain View', emits[2][2]['geoip_city']
243
- assert_equal [-122.0574, 37.419200000000004], emits[2][2]['geopoint']
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
- remove_tag_prefix input.
267
- tag geoip.${tag}
268
- ], 'input.access')
269
- d1.run do
270
- d1.emit({'from' => {'ip' => '66.102.3.80'}})
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
- emits = d1.emits
274
- assert_equal 2, emits.length
275
-
276
- assert_equal 'geoip.access', emits[0][0] # tag
277
- assert_equal 'Mountain View', emits[0][2]['from_city']
278
- assert_equal 'United States', emits[0][2]['from_country']
279
- assert_equal 37.419200000000004, emits[0][2]['latitude']
280
- assert_equal -122.0574, emits[0][2]['longitude']
281
- assert_equal '37.419200000000004,-122.0574', emits[0][2]['float_concat']
282
- assert_equal [-122.0574, 37.419200000000004], emits[0][2]['float_array']
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, emits[0][2]['float_nest']
285
- assert_equal '37.419200000000004,-122.0574', emits[0][2]['string_concat']
286
- assert_equal ["Mountain View", "United States"], emits[0][2]['string_array']
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, emits[0][2]['string_nest']
289
- assert_equal nil, emits[0][2]['unknown_city']
290
- assert_equal nil, emits[0][2]['undefined']
291
- assert_equal [-122.0574, nil], emits[0][2]['broken_array1']
292
- assert_equal [nil, nil], emits[0][2]['broken_array2']
293
-
294
- assert_equal nil, emits[1][2]['from_city']
295
- assert_equal nil, emits[1][2]['from_country']
296
- assert_equal nil, emits[1][2]['latitude']
297
- assert_equal nil, emits[1][2]['longitude']
298
- assert_equal ',', emits[1][2]['float_concat']
299
- assert_equal [nil, nil], emits[1][2]['float_array']
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, emits[1][2]['float_nest']
302
- assert_equal ',', emits[1][2]['string_concat']
303
- assert_equal [nil, nil], emits[1][2]['string_array']
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, emits[1][2]['string_nest']
306
- assert_equal nil, emits[1][2]['unknown_city']
307
- assert_equal nil, emits[1][2]['undefined']
308
- assert_equal [nil, nil], emits[1][2]['broken_array1']
309
- assert_equal [nil, nil], emits[1][2]['broken_array2']
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
- remove_tag_prefix input.
324
- tag geoip.${tag}
325
- ], 'input.access')
326
- d1.run do
327
- d1.emit({'from' => {'ip' => '66.102.3.80'}, 'to' => {'ip' => '125.54.15.42'}})
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
- emits = d1.emits
331
- assert_equal 2, emits.length
332
-
333
- assert_equal 'geoip.access', emits[0][0] # tag
334
- assert_equal 'Mountain View', emits[0][2]['from_city']
335
- assert_equal 'United States', emits[0][2]['from_country']
336
- assert_equal 'Tokorozawa', emits[0][2]['to_city']
337
- assert_equal 'Japan', emits[0][2]['to_country']
338
- assert_equal ['United States','Japan'], emits[0][2]['string_array']
339
-
340
- assert_equal nil, emits[1][2]['from_city']
341
- assert_equal nil, emits[1][2]['to_city']
342
- assert_equal nil, emits[1][2]['from_country']
343
- assert_equal nil, emits[1][2]['to_country']
344
- assert_equal [nil, nil], emits[1][2]['string_array']
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
- remove_tag_prefix input.
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, 'input.access')
366
- d1.run do
367
- d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
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
- emits = d1.emits
370
- assert_equal 1, emits.length
371
- assert_equal 'geoip.access', emits[0][0] # tag
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, emits[0][2]['location_properties']
374
- assert_equal '37.419200000000004,-122.0574', emits[0][2]['location_string']
375
- assert_equal 'US', emits[0][2]['location_string2']
376
- assert_equal [-122.0574, 37.419200000000004], emits[0][2]['location_array']
377
- assert_equal [-122.0574, 37.419200000000004], emits[0][2]['location_array2']
378
- assert_equal '[GEOIP] message => {"lat":37.419200000000004, "lon":-122.0574}', emits[0][2]['peculiar_pattern']
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, 'input.access', true)
383
- d1.run do
384
- d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
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
- emits = d1.emits
387
- assert_equal 1, emits.length
388
- assert_equal 'geoip.access', emits[0][0] # tag
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, emits[0][2]['location_properties']
391
- assert_equal '37.419200000000004,-122.0574', emits[0][2]['location_string']
392
- assert_equal 'US', emits[0][2]['location_string2']
393
- assert_equal [-122.0574, 37.419200000000004], emits[0][2]['location_array']
394
- assert_equal [-122.0574, 37.419200000000004], emits[0][2]['location_array2']
395
- assert_equal '[GEOIP] message => {"lat":37.419200000000004, "lon":-122.0574}', emits[0][2]['peculiar_pattern']
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
- remove_tag_prefix input.
411
- tag geoip.${tag}
412
- ], 'input.access', true)
413
- d1.run do
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
- emits = d1.emits
417
- assert_equal 1, emits.length
418
- assert_equal 'geoip.access', emits[0][0] # tag
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, emits[0][2]['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
- remove_tag_prefix input.
433
- tag geoip.${tag}
434
- ], 'input.access')
435
- d1.run do
436
- d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
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
- emits = d1.emits
440
- assert_equal 2, emits.length
441
- assert_equal 'geoip.access', emits[0][0] # tag
442
- assert_equal 'Mountain View', emits[0][2]['geoip_city']
443
- assert_equal nil, emits[1][2]['geoip_city']
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.${tag_parts[1]}.${tag_parts[2..3]}.${tag_parts[-1]}
454
- ], '0.1.2.3')
455
- d1.run do
456
- d1.emit({'host' => '66.102.3.80'})
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
- emits = d1.emits
459
- assert_equal 1, emits.length
460
- assert_equal 'geoip.1.2.3.3', emits[0][0] # tag
461
- assert_equal 'Mountain View', emits[0][2]['geoip_city']
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
- remove_tag_prefix input.
473
- tag geoip.${tag}
474
- ], 'input.access')
475
- d1.run do
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
- emits = d1.emits
479
- assert_equal 1, emits.length
480
- assert_equal 'geoip.access', emits[0][0] # tag
481
- assert_equal 'US', emits[0][2]['origin_country']
482
- assert_equal 'US', emits[0][2]['dest_country']
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
- remove_tag_prefix input.
495
- tag geoip.${tag}
496
- ], 'input.access')
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.emit({'host' => '203.0.113.1', 'message' => 'invalid ip'})
500
- d1.emit({'host' => '0', 'message' => 'invalid ip'})
489
+ d1.feed({'host' => '203.0.113.1', 'message' => 'invalid ip'})
490
+ d1.feed({'host' => '0', 'message' => 'invalid ip'})
501
491
  end
502
- emits = d1.emits
503
- assert_equal 2, emits.length
504
- assert_equal 'geoip.access', emits[0][0] # tag
505
- assert_equal nil, emits[0][2]['geoip_city']
506
- assert_equal 'geoip.access', emits[1][0] # tag
507
- assert_equal nil, emits[1][2]['geoip_city']
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
- remove_tag_prefix input.
520
- tag geoip.${tag}
521
- ], 'input.access')
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.emit({'host' => '203.0.113.1', 'message' => 'invalid ip'})
525
- d1.emit({'host' => '0', 'message' => 'invalid ip'})
526
- d1.emit({'host' => '66.102.3.80', 'message' => 'google bot'})
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
- emits = d1.emits
529
- assert_equal 3, emits.length
530
- assert_equal 'geoip.access', emits[0][0] # tag
531
- assert_equal nil, emits[0][2]['geoip_city']
532
- assert_equal nil, emits[0][2]['geopoint']
533
- assert_equal 'geoip.access', emits[1][0] # tag
534
- assert_equal nil, emits[1][2]['geoip_city']
535
- assert_equal nil, emits[1][2]['geopoint']
536
- assert_equal 'Mountain View', emits[2][2]['geoip_city']
537
- assert_equal [-122.0574, 37.419200000000004], emits[2][2]['geopoint']
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
- remove_tag_prefix input.
561
- tag geoip.${tag}
562
- ], 'input.access')
563
- d1.run do
564
- d1.emit({'from' => {'ip' => '66.102.3.80'}})
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
- emits = d1.emits
568
- assert_equal 2, emits.length
569
-
570
- assert_equal 'geoip.access', emits[0][0] # tag
571
- assert_equal 'Mountain View', emits[0][2]['from_city']
572
- assert_equal 'United States', emits[0][2]['from_country']
573
- assert_equal 37.419200000000004, emits[0][2]['latitude']
574
- assert_equal -122.0574, emits[0][2]['longitude']
575
- assert_equal '37.419200000000004,-122.0574', emits[0][2]['float_concat']
576
- assert_equal [-122.0574, 37.419200000000004], emits[0][2]['float_array']
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, emits[0][2]['float_nest']
579
- assert_equal '37.419200000000004,-122.0574', emits[0][2]['string_concat']
580
- assert_equal ["Mountain View", "United States"], emits[0][2]['string_array']
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, emits[0][2]['string_nest']
583
- assert_equal nil, emits[0][2]['unknown_city']
584
- assert_equal nil, emits[0][2]['undefined']
585
- assert_equal [-122.0574, nil], emits[0][2]['broken_array1']
586
- assert_equal [nil, nil], emits[0][2]['broken_array2']
587
-
588
- assert_equal nil, emits[1][2]['from_city']
589
- assert_equal nil, emits[1][2]['from_country']
590
- assert_equal nil, emits[1][2]['latitude']
591
- assert_equal nil, emits[1][2]['longitude']
592
- assert_equal ',', emits[1][2]['float_concat']
593
- assert_equal [nil, nil], emits[1][2]['float_array']
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, emits[1][2]['float_nest']
596
- assert_equal ',', emits[1][2]['string_concat']
597
- assert_equal [nil, nil], emits[1][2]['string_array']
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, emits[1][2]['string_nest']
600
- assert_equal nil, emits[1][2]['unknown_city']
601
- assert_equal nil, emits[1][2]['undefined']
602
- assert_equal [nil, nil], emits[1][2]['broken_array1']
603
- assert_equal [nil, nil], emits[1][2]['broken_array2']
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
- remove_tag_prefix input.
618
- tag geoip.${tag}
619
- ], 'input.access')
620
- d1.run do
621
- d1.emit({'from' => {'ip' => '66.102.3.80'}, 'to' => {'ip' => '125.54.15.42'}})
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
- emits = d1.emits
625
- assert_equal 2, emits.length
626
-
627
- assert_equal 'geoip.access', emits[0][0] # tag
628
- assert_equal 'Mountain View', emits[0][2]['from_city']
629
- assert_equal 'United States', emits[0][2]['from_country']
630
- assert_equal 'Tokorozawa', emits[0][2]['to_city']
631
- assert_equal 'Japan', emits[0][2]['to_country']
632
- assert_equal ['United States','Japan'], emits[0][2]['string_array']
633
-
634
- assert_equal nil, emits[1][2]['from_city']
635
- assert_equal nil, emits[1][2]['to_city']
636
- assert_equal nil, emits[1][2]['from_country']
637
- assert_equal nil, emits[1][2]['to_country']
638
- assert_equal [nil, nil], emits[1][2]['string_array']
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
- remove_tag_prefix input.
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, 'input.access')
660
- d1.run do
661
- d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
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
- emits = d1.emits
664
- assert_equal 1, emits.length
665
- assert_equal 'geoip.access', emits[0][0] # tag
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, emits[0][2]['location_properties']
668
- assert_equal '37.419200000000004,-122.0574', emits[0][2]['location_string']
669
- assert_equal 'US', emits[0][2]['location_string2']
670
- assert_equal [-122.0574, 37.419200000000004], emits[0][2]['location_array']
671
- assert_equal [-122.0574, 37.419200000000004], emits[0][2]['location_array2']
672
- assert_equal '[GEOIP] message => {"lat":37.419200000000004, "lon":-122.0574}', emits[0][2]['peculiar_pattern']
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, 'input.access', true)
677
- d1.run do
678
- d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
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
- emits = d1.emits
681
- assert_equal 1, emits.length
682
- assert_equal 'geoip.access', emits[0][0] # tag
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, emits[0][2]['location_properties']
685
- assert_equal '37.419200000000004,-122.0574', emits[0][2]['location_string']
686
- assert_equal 'US', emits[0][2]['location_string2']
687
- assert_equal [-122.0574, 37.419200000000004], emits[0][2]['location_array']
688
- assert_equal [-122.0574, 37.419200000000004], emits[0][2]['location_array2']
689
- assert_equal '[GEOIP] message => {"lat":37.419200000000004, "lon":-122.0574}', emits[0][2]['peculiar_pattern']
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
- remove_tag_prefix input.
705
- tag geoip.${tag}
706
- ], 'input.access', true)
707
- d1.run do
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
- emits = d1.emits
711
- assert_equal 1, emits.length
712
- assert_equal 'geoip.access', emits[0][0] # tag
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, emits[0][2]['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
- remove_tag_prefix input.
724
- tag geoip.${tag}
725
- ], 'input.access')
726
- d1.run do
727
- d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
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
- emits = d1.emits
731
- assert_equal 2, emits.length
732
- assert_equal 'geoip.access', emits[0][0] # tag
733
- assert_equal 'Mountain View', emits[0][2]['geoip_city']
734
- assert_equal nil, emits[1][2]['geoip_city']
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
- remove_tag_prefix input.
744
- tag geoip.${tag}
745
- ], 'input.access')
746
- d1.run do
747
- d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
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
- emits = d1.emits
751
- assert_equal 2, emits.length
752
- assert_equal 'geoip.access', emits[0][0] # tag
753
- assert_equal 'Mountain View', emits[0][2]['geoip_city']
754
- assert_equal nil, emits[1][2]['geoip_city']
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.${tag_parts[1]}.${tag_parts[2..3]}.${tag_parts[-1]}
764
- ], '0.1.2.3')
765
- d1.run do
766
- d1.emit({'host' => '66.102.3.80'})
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
- emits = d1.emits
769
- assert_equal 1, emits.length
770
- assert_equal 'geoip.1.2.3.3', emits[0][0] # tag
771
- assert_equal 'Mountain View', emits[0][2]['geoip_city']
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
- remove_tag_prefix input.
782
- tag geoip.${tag}
783
- ], 'input.access')
784
- d1.run do
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
- emits = d1.emits
788
- assert_equal 1, emits.length
789
- assert_equal 'geoip.access', emits[0][0] # tag
790
- assert_equal 'US', emits[0][2]['origin_country']
791
- assert_equal 'US', emits[0][2]['dest_country']
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
- remove_tag_prefix input.
799
- add_tag_prefix geoip.
800
- ], 'input.access')
801
- d1.run do
802
- d1.emit({'host' => {'ip' => '66.102.3.80'}, 'message' => 'valid ip'})
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
- emits = d1.emits
806
- assert_equal 2, emits.length
807
- assert_equal 'geoip.access', emits[0][0] # tag
808
- assert_equal 'Mountain View', emits[0][2]['geoip_city']
809
- assert_equal nil, emits[1][2]['geoip_city']
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
- remove_tag_prefix input.
821
- tag geoip.${tag}
822
- ], 'input.access')
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.emit({'host' => '203.0.113.1', 'message' => 'invalid ip'})
826
- d1.emit({'host' => '0', 'message' => 'invalid ip'})
811
+ d1.feed({'host' => '203.0.113.1', 'message' => 'invalid ip'})
812
+ d1.feed({'host' => '0', 'message' => 'invalid ip'})
827
813
  end
828
- emits = d1.emits
829
- assert_equal 2, emits.length
830
- assert_equal 'geoip.access', emits[0][0] # tag
831
- assert_equal nil, emits[0][2]['geoip_city']
832
- assert_equal 'geoip.access', emits[1][0] # tag
833
- assert_equal nil, emits[1][2]['geoip_city']
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
- remove_tag_prefix input.
845
- tag geoip.${tag}
846
- ], 'input.access')
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.emit({'host' => '203.0.113.1', 'message' => 'invalid ip'})
850
- d1.emit({'host' => '0', 'message' => 'invalid ip'})
851
- d1.emit({'host' => '66.102.3.80', 'message' => 'google bot'})
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
- emits = d1.emits
854
- assert_equal 3, emits.length
855
- assert_equal 'geoip.access', emits[0][0] # tag
856
- assert_equal nil, emits[0][2]['geoip_city']
857
- assert_equal nil, emits[0][2]['geopoint']
858
- assert_equal 'geoip.access', emits[1][0] # tag
859
- assert_equal nil, emits[1][2]['geoip_city']
860
- assert_equal nil, emits[1][2]['geopoint']
861
- assert_equal 'Mountain View', emits[2][2]['geoip_city']
862
- assert_equal [-122.05740356445312, 37.4192008972168], emits[2][2]['geopoint']
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
- remove_tag_prefix input.
871
- add_tag_prefix geoip.
872
- ], 'input.access')
873
- d1.run do
874
- d1.emit({'from' => {'ip' => '66.102.3.80'}, 'to' => {'ip' => '125.54.15.42'}})
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
- emits = d1.emits
878
- assert_equal 2, emits.length
879
- assert_equal 'geoip.access', emits[0][0] # tag
880
- assert_equal 'Mountain View', emits[0][2]['from_city']
881
- assert_equal 'Tokorozawa', emits[0][2]['to_city']
882
- assert_equal nil, emits[1][2]['from_city']
883
- assert_equal nil, emits[1][2]['to_city']
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
- remove_tag_prefix input.
892
- add_tag_prefix geoip.
893
- ], 'input.access')
894
- d1.run do
895
- d1.emit({'from' => {'ip' => '66.102.3.80'}, 'to' => {'ip' => '125.54.15.42'}})
896
- d1.emit({'from' => {'ip' => '66.102.3.80'}})
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
- emits = d1.emits
900
- assert_equal 3, emits.length
901
- assert_equal 'geoip.access', emits[0][0] # tag
902
- assert_equal 'Mountain View', emits[0][2]['from_city']
903
- assert_equal 'United States', emits[0][2]['from_country']
904
- assert_equal 'Tokorozawa', emits[0][2]['to_city']
905
- assert_equal 'Japan', emits[0][2]['to_country']
906
-
907
- assert_equal 'Mountain View', emits[1][2]['from_city']
908
- assert_equal 'United States', emits[1][2]['from_country']
909
- assert_equal nil, emits[1][2]['to_city']
910
- assert_equal nil, emits[1][2]['to_country']
911
-
912
- assert_equal nil, emits[2][2]['from_city']
913
- assert_equal nil, emits[2][2]['from_country']
914
- assert_equal nil, emits[2][2]['to_city']
915
- assert_equal nil, emits[2][2]['to_country']
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
- remove_tag_prefix input.
938
- tag geoip.${tag}
939
- ], 'input.access')
940
- d1.run do
941
- d1.emit({'from' => {'ip' => '66.102.3.80'}})
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
- emits = d1.emits
945
- assert_equal 2, emits.length
946
-
947
- assert_equal 'geoip.access', emits[0][0] # tag
948
- assert_equal 'Mountain View', emits[0][2]['from_city']
949
- assert_equal 'United States', emits[0][2]['from_country']
950
- assert_equal 37.4192008972168, emits[0][2]['latitude']
951
- assert_equal -122.05740356445312, emits[0][2]['longitude']
952
- assert_equal '37.4192008972168,-122.05740356445312', emits[0][2]['float_concat']
953
- assert_equal [-122.05740356445312, 37.4192008972168], emits[0][2]['float_array']
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, emits[0][2]['float_nest']
956
- assert_equal '37.4192008972168,-122.05740356445312', emits[0][2]['string_concat']
957
- assert_equal ["Mountain View", "United States"], emits[0][2]['string_array']
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, emits[0][2]['string_nest']
960
- assert_equal nil, emits[0][2]['unknown_city']
961
- assert_equal nil, emits[0][2]['undefined']
962
- assert_equal [-122.05740356445312, nil], emits[0][2]['broken_array1']
963
- assert_equal [nil, nil], emits[0][2]['broken_array2']
964
-
965
- assert_equal nil, emits[1][2]['from_city']
966
- assert_equal nil, emits[1][2]['from_country']
967
- assert_equal nil, emits[1][2]['latitude']
968
- assert_equal nil, emits[1][2]['longitude']
969
- assert_equal ',', emits[1][2]['float_concat']
970
- assert_equal [nil, nil], emits[1][2]['float_array']
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, emits[1][2]['float_nest']
973
- assert_equal ',', emits[1][2]['string_concat']
974
- assert_equal [nil, nil], emits[1][2]['string_array']
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, emits[1][2]['string_nest']
977
- assert_equal nil, emits[1][2]['unknown_city']
978
- assert_equal nil, emits[1][2]['undefined']
979
- assert_equal [nil, nil], emits[1][2]['broken_array1']
980
- assert_equal [nil, nil], emits[1][2]['broken_array2']
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
- remove_tag_prefix input.
994
- tag geoip.${tag}
995
- ], 'input.access')
996
- d1.run do
997
- d1.emit({'from' => {'ip' => '66.102.3.80'}, 'to' => {'ip' => '125.54.15.42'}})
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
- emits = d1.emits
1001
- assert_equal 2, emits.length
1002
-
1003
- assert_equal 'geoip.access', emits[0][0] # tag
1004
- assert_equal 'Mountain View', emits[0][2]['from_city']
1005
- assert_equal 'United States', emits[0][2]['from_country']
1006
- assert_equal 'Tokorozawa', emits[0][2]['to_city']
1007
- assert_equal 'Japan', emits[0][2]['to_country']
1008
- assert_equal ['United States','Japan'], emits[0][2]['string_array']
1009
-
1010
- assert_equal nil, emits[1][2]['from_city']
1011
- assert_equal nil, emits[1][2]['to_city']
1012
- assert_equal nil, emits[1][2]['from_country']
1013
- assert_equal nil, emits[1][2]['to_country']
1014
- assert_equal [nil, nil], emits[1][2]['string_array']
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
- remove_tag_prefix input.
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, 'input.access')
1035
- d1.run do
1036
- d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
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
- emits = d1.emits
1039
- assert_equal 1, emits.length
1040
- assert_equal 'geoip.access', emits[0][0] # tag
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, emits[0][2]['location_properties']
1043
- assert_equal '37.4192008972168,-122.05740356445312', emits[0][2]['location_string']
1044
- assert_equal 'US', emits[0][2]['location_string2']
1045
- assert_equal [-122.05740356445312, 37.4192008972168], emits[0][2]['location_array']
1046
- assert_equal [-122.05740356445312, 37.4192008972168], emits[0][2]['location_array2']
1047
- assert_equal '[GEOIP] message => {"lat":37.4192008972168, "lon":-122.05740356445312}', emits[0][2]['peculiar_pattern']
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, 'input.access', true)
1052
- d1.run do
1053
- d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
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
- emits = d1.emits
1056
- assert_equal 1, emits.length
1057
- assert_equal 'geoip.access', emits[0][0] # tag
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, emits[0][2]['location_properties']
1060
- assert_equal '37.4192008972168,-122.05740356445312', emits[0][2]['location_string']
1061
- assert_equal 'US', emits[0][2]['location_string2']
1062
- assert_equal [-122.05740356445312, 37.4192008972168], emits[0][2]['location_array']
1063
- assert_equal [-122.05740356445312, 37.4192008972168], emits[0][2]['location_array2']
1064
- assert_equal '[GEOIP] message => {"lat":37.4192008972168, "lon":-122.05740356445312}', emits[0][2]['peculiar_pattern']
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
- remove_tag_prefix input.
1079
- tag geoip.${tag}
1080
- ], 'input.access', true)
1081
- d1.run do
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
- emits = d1.emits
1085
- assert_equal 1, emits.length
1086
- assert_equal 'geoip.access', emits[0][0] # tag
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, emits[0][2]['location_properties']
1073
+ assert_equal location_properties, events[0][2]['location_properties']
1089
1074
  end
1090
1075
  end
1091
1076
  end