fluent-plugin-geoip 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8fdb172feeffd90a77f0a83f3f44b58b88ddb138
4
+ data.tar.gz: 3abc009ded4a7ced18e046c27d9f50094f11b865
5
+ SHA512:
6
+ metadata.gz: c5ef5143cdd8f2ea9fe372d5a2e0ee5bbe5981a4a1c2cd84b34364fe7f6679a897b5a40732d8b97ad9dfdf5f36b3dc257ec529357c2411e817cfdb34822e05f0
7
+ data.tar.gz: 70d27191a5cc8f7f4ee5153845149f7d0881c5bf08ed7554ab5424a65f7806b78f36909fa8319d1850d49c13d2247fa41f466cf954777e85d80d45065948eedb
@@ -18,3 +18,9 @@ gemfile:
18
18
  - gemfiles/fluentd_v0.10.gemfile
19
19
  - gemfiles/fluentd_v0.12.gemfile
20
20
 
21
+ matrix:
22
+ fast_finish: true
23
+ allow_failures:
24
+ - gemfile: gemfiles/fluentd_v0.10.gemfile
25
+ - rvm: 1.9.3
26
+ - rvm: 2.0.0
data/README.md CHANGED
@@ -22,6 +22,9 @@ $ sudo yum install geoip-devel --enablerepo=epel
22
22
  # for Ubuntu/Debian
23
23
  $ sudo apt-get install build-essential
24
24
  $ sudo apt-get install libgeoip-dev
25
+
26
+ # for OS X
27
+ $ brew install geoip
25
28
  ```
26
29
 
27
30
  ## Installation
@@ -41,6 +44,8 @@ $ sudo td-agent-gem install fluent-plugin-geoip
41
44
 
42
45
  ## Usage
43
46
 
47
+ ### For GeoipOutput
48
+
44
49
  ```xml
45
50
  <match access.apache>
46
51
  type geoip
@@ -54,7 +59,6 @@ $ sudo td-agent-gem install fluent-plugin-geoip
54
59
 
55
60
  # Set adding field with placeholder (more than one settings are required.)
56
61
  <record>
57
- city ${city["host"]}
58
62
  latitude ${latitude["host"]}
59
63
  longitude ${longitude["host"]}
60
64
  country_code3 ${country_code3["host"]}
@@ -63,6 +67,7 @@ $ sudo td-agent-gem install fluent-plugin-geoip
63
67
  dma ${dma_code["host"]}
64
68
  area ${area_code["host"]}
65
69
  region ${region["host"]}
70
+ city ${city["host"]}
66
71
  </record>
67
72
 
68
73
  # Settings for tag
@@ -142,8 +147,49 @@ On the case of using td-agent2 (v1-config), it have to quote `{ ... }` or `[ ...
142
147
  </match>
143
148
  ```
144
149
 
150
+ ### For GeoipFilter
151
+
152
+ Note that filter version of geoip plugin does not have handling tag feature.
153
+
154
+ ```xml
155
+ <filter access.apache>
156
+ @type geoip
157
+
158
+ # Specify one or more geoip lookup field which has ip address (default: host)
159
+ # in the case of accessing nested value, delimit keys by dot like 'host.ip'.
160
+ geoip_lookup_key host
161
+
162
+ # Specify optional geoip database (using bundled GeoLiteCity databse by default)
163
+ geoip_database "/path/to/your/GeoIPCity.dat"
164
+
165
+ # Set adding field with placeholder (more than one settings are required.)
166
+ <record>
167
+ city ${city["host"]}
168
+ latitude ${latitude["host"]}
169
+ longitude ${longitude["host"]}
170
+ country_code3 ${country_code3["host"]}
171
+ country ${country_code["host"]}
172
+ country_name ${country_name["host"]}
173
+ dma ${dma_code["host"]}
174
+ area ${area_code["host"]}
175
+ region ${region["host"]}
176
+ </record>
177
+
178
+ # To avoid get stacktrace error with `[null, null]` array for elasticsearch.
179
+ skip_adding_null_record true
180
+
181
+ # Set log_level for fluentd-v0.10.43 or earlier (default: warn)
182
+ log_level info
183
+
184
+ # Set buffering time (default: 0s)
185
+ flush_interval 1s
186
+ </filter>
187
+ ```
188
+
145
189
  ## Tutorial
146
190
 
191
+ ### For GeoipOutput
192
+
147
193
  #### configuration
148
194
 
149
195
  ```xml
@@ -160,9 +206,9 @@ On the case of using td-agent2 (v1-config), it have to quote `{ ... }` or `[ ...
160
206
  type geoip
161
207
  geoip_lookup_key host
162
208
  <record>
163
- city ${city["host"]}
164
- lat ${latitude["host"]}
165
- lon ${longitude["host"]}
209
+ lat ${latitude["host"]}
210
+ lon ${longitude["host"]}
211
+ country ${country_code["host"]}
166
212
  </record>
167
213
  remove_tag_prefix test.
168
214
  tag debug.${tag}
@@ -183,7 +229,45 @@ $ echo '{"host":"66.102.9.80","message":"test"}' | fluent-cat test.geoip
183
229
  # check the result at stdout
184
230
  $ tail /var/log/td-agent/td-agent.log
185
231
  2013-08-04 16:21:32 +0900 test.geoip: {"host":"66.102.9.80","message":"test"}
186
- 2013-08-04 16:21:32 +0900 debug.geoip: {"host":"66.102.9.80","message":"test","city":"Mountain View","lat":37.4192008972168,"lon":-122.05740356445312}
232
+ 2013-08-04 16:21:32 +0900 debug.geoip: {"host":"66.102.9.80","message":"test","lat":37.4192008972168,"lon":-122.05740356445312,"country":"US"}
233
+ ```
234
+
235
+ For more details of geoip data format is described at the page below in section `GeoIP City Edition CSV Database Fields`.<br />
236
+ http://dev.maxmind.com/geoip/legacy/csv/
237
+
238
+ ### For GeoipFilter
239
+
240
+ #### configuration
241
+
242
+ ```xml
243
+ <source>
244
+ @type forward
245
+ </source>
246
+
247
+ <filter test.geoip>
248
+ @type geoip
249
+ geoip_lookup_key host
250
+ <record>
251
+ city ${city["host"]}
252
+ lat ${latitude["host"]}
253
+ lon ${longitude["host"]}
254
+ </record>
255
+ </filter>
256
+
257
+ <match test.**>
258
+ @type stdout
259
+ </match>
260
+ ```
261
+
262
+ #### result
263
+
264
+ ```bash
265
+ # forward record with Google's ip address.
266
+ $ echo '{"host":"66.102.9.80","message":"test"}' | fluent-cat test.geoip
267
+
268
+ # check the result at stdout
269
+ $ tail /var/log/td-agent/td-agent.log
270
+ 2016-02-01 12:04:37 +0900 test.geoip: {"host":"66.102.9.80","message":"test","city":"Mountain View","lat":37.4192008972168,"lon":-122.05740356445312}
187
271
  ```
188
272
 
189
273
  For more details of geoip data format is described at the page below in section `GeoIP City Edition CSV Database Fields`.<br />
@@ -210,6 +294,8 @@ Further more specification available at http://dev.maxmind.com/geoip/legacy/csv/
210
294
 
211
295
  ## Parameters
212
296
 
297
+ ### GeoipOutput
298
+
213
299
  * `include_tag_key` (default: false)
214
300
  * `tag_key`
215
301
 
@@ -236,6 +322,24 @@ On using this option with tag placeholder like `tag geoip.${tag}` (test code is
236
322
 
237
323
  Set buffering time to execute bulk lookup geoip.
238
324
 
325
+ ### GeoipFilter
326
+
327
+ Note that filter version of `geoip` plugin does not have handling `tag` feature.
328
+
329
+ * `include_tag_key` (default: false)
330
+
331
+ Add original tag name into filtered record using SetTagKeyMixin.<br />
332
+ Further details are written at http://docs.fluentd.org/articles/in_exec
333
+
334
+ * `skip_adding_null_record` (default: false)
335
+
336
+ Skip adding geoip fields when this valaues to `true`.
337
+ On the case of getting nothing of GeoIP info (such as local IP), it will output the original record without changing anything.
338
+
339
+ * `flush_interval` (default: 0 sec)
340
+
341
+ Set buffering time to execute bulk lookup geoip.
342
+
239
343
  ## Articles
240
344
 
241
345
  * [IPアドレスを元に位置情報をリアルタイムに付与する fluent-plugin-geoip v0.0.1をリリースしました #fluentd - Y-Ken Studio](http://y-ken.hatenablog.com/entry/fluent-plugin-geoip-has-released)<br />
@@ -4,10 +4,10 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-geoip"
7
- spec.version = "0.6.0"
7
+ spec.version = "0.6.1"
8
8
  spec.authors = ["Kentaro Yoshida"]
9
9
  spec.email = ["y.ken.studio@gmail.com"]
10
- spec.summary = %q{Fluentd Output plugin to add information about geographical location of IP addresses with Maxmind GeoIP databases.}
10
+ spec.summary = %q{Fluentd Filter plugin to add information about geographical location of IP addresses with Maxmind GeoIP databases.}
11
11
  spec.homepage = "https://github.com/y-ken/fluent-plugin-geoip"
12
12
  spec.license = "Apache-2.0"
13
13
 
@@ -25,8 +25,17 @@ module Fluent
25
25
  @geoip = Fluent::GeoIP.new(self, conf)
26
26
  end
27
27
 
28
- def filter(tag, time, record)
29
- @geoip.add_geoip_field(record)
28
+ def filter_stream(tag, es)
29
+ new_es = MultiEventStream.new
30
+ es.each do |time, record|
31
+ begin
32
+ filtered_record = @geoip.add_geoip_field(record)
33
+ new_es.add(time, filtered_record) if filtered_record
34
+ rescue => e
35
+ router.emit_error_event(tag, time, record, e)
36
+ end
37
+ end
38
+ new_es
30
39
  end
31
40
  end
32
41
  end
@@ -56,7 +56,7 @@ module Fluent
56
56
  raise Fluent::ConfigError, "geoip: unsupported key #{geoip_key}" unless GEOIP_KEYS.include?(geoip_key)
57
57
  end
58
58
 
59
- if plugin.is_a?(Fluent::Output)
59
+ if plugin.is_a?(Fluent::BufferedOutput)
60
60
  @placeholder_expander = PlaceholderExpander.new
61
61
  unless have_tag_option?(plugin)
62
62
  raise Fluent::ConfigError, "geoip: required at least one option of 'tag', 'remove_tag_prefix', 'remove_tag_suffix', 'add_tag_prefix', 'add_tag_suffix'."
@@ -55,8 +55,12 @@ class Fluent::GeoipOutput < Fluent::BufferedOutput
55
55
  end
56
56
 
57
57
  def write(chunk)
58
- chunk.msgpack_each do |tag, time, record|
59
- router.emit(tag, time, @geoip.add_geoip_field(record))
58
+ es = Fluent::MultiEventStream.new
59
+ tag = ""
60
+ chunk.msgpack_each do |_tag, time, record|
61
+ tag = _tag
62
+ es.add(time, @geoip.add_geoip_field(record))
60
63
  end
64
+ router.emit_stream(tag, es)
61
65
  end
62
66
  end
@@ -13,7 +13,7 @@ class GeoipOutputTest < Test::Unit::TestCase
13
13
  ]
14
14
 
15
15
  def create_driver(conf=CONFIG,tag='test',use_v1=false)
16
- Fluent::Test::OutputTestDriver.new(Fluent::GeoipOutput, tag).configure(conf, use_v1)
16
+ Fluent::Test::BufferedOutputTestDriver.new(Fluent::GeoipOutput, tag).configure(conf, use_v1)
17
17
  end
18
18
 
19
19
  def test_configure
metadata CHANGED
@@ -1,126 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-geoip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
5
- prerelease:
4
+ version: 0.6.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Kentaro Yoshida
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2016-01-29 00:00:00.000000000 Z
11
+ date: 2016-05-31 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: bundler
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rake
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: appraisal
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: test-unit
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
61
  version: 3.1.0
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
68
  version: 3.1.0
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: fluentd
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
75
  version: '0'
86
76
  type: :runtime
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: fluent-mixin-rewrite-tag-name
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :runtime
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
98
  name: geoip-c
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - ">="
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :runtime
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - ">="
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  description:
@@ -130,8 +115,8 @@ executables: []
130
115
  extensions: []
131
116
  extra_rdoc_files: []
132
117
  files:
133
- - .gitignore
134
- - .travis.yml
118
+ - ".gitignore"
119
+ - ".travis.yml"
135
120
  - Appraisals
136
121
  - Gemfile
137
122
  - LICENSE
@@ -150,28 +135,27 @@ files:
150
135
  homepage: https://github.com/y-ken/fluent-plugin-geoip
151
136
  licenses:
152
137
  - Apache-2.0
138
+ metadata: {}
153
139
  post_install_message:
154
140
  rdoc_options: []
155
141
  require_paths:
156
142
  - lib
157
143
  required_ruby_version: !ruby/object:Gem::Requirement
158
- none: false
159
144
  requirements:
160
- - - ! '>='
145
+ - - ">="
161
146
  - !ruby/object:Gem::Version
162
147
  version: '0'
163
148
  required_rubygems_version: !ruby/object:Gem::Requirement
164
- none: false
165
149
  requirements:
166
- - - ! '>='
150
+ - - ">="
167
151
  - !ruby/object:Gem::Version
168
152
  version: '0'
169
153
  requirements: []
170
154
  rubyforge_project:
171
- rubygems_version: 1.8.23
155
+ rubygems_version: 2.4.5
172
156
  signing_key:
173
- specification_version: 3
174
- summary: Fluentd Output plugin to add information about geographical location of IP
157
+ specification_version: 4
158
+ summary: Fluentd Filter plugin to add information about geographical location of IP
175
159
  addresses with Maxmind GeoIP databases.
176
160
  test_files:
177
161
  - test/helper.rb