fluent-plugin-geoip 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  Fluentd Output plugin to add information about geographical location of IP addresses with Maxmind GeoIP databases.
4
4
 
5
+ fluent-plugin-geoip has bundled cost-free [GeoLite City database](http://dev.maxmind.com/geoip/legacy/geolite/) by default.
6
+ Also you can use purchased [GeoIP City database](http://www.maxmind.com/en/city) ([lang:ja](http://www.maxmind.com/ja/city)) which costs starting from $50.
7
+
8
+ The accuracy details for GeoLite City (free) and GeoIP City (purchased) has described at the page below.
9
+
10
+ * http://www.maxmind.com/en/geolite_city_accuracy ([lang:ja](http://www.maxmind.com/ja/geolite_city_accuracy))
11
+ * http://www.maxmind.com/en/city_accuracy ([lang:ja](http://www.maxmind.com/ja/city_accuracy))
12
+
5
13
  ## Installation
6
14
 
7
15
  install with `gem` or `fluent-gem` command as:
@@ -20,7 +28,7 @@ $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-geoip
20
28
  <match access.apache>
21
29
  type geoip
22
30
 
23
- # buffering time
31
+ # buffering time (default: 60s)
24
32
  flush_interval 1s
25
33
 
26
34
  # tag settings
@@ -28,10 +36,13 @@ $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-geoip
28
36
  add_tag_prefix geoip.
29
37
  include_tag_key false
30
38
 
31
- # geoip settings
39
+ # specify geoip lookup field (default: host)
32
40
  geoip_lookup_key host
33
41
 
34
- # record settings
42
+ # specify geoip database (using bundled GeoLiteCity databse by default)
43
+ geoip_database 'data/GeoLiteCity.dat'
44
+
45
+ # record settings (enable more than one keys required.)
35
46
  enable_key_city geoip_city
36
47
  enable_key_latitude geoip_lat
37
48
  enable_key_longitude geoip_lon
@@ -87,6 +98,11 @@ $ tail /var/log/td-agent/td-agent.log
87
98
  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}
88
99
  ```
89
100
 
101
+ ## Articles
102
+
103
+ * [IPアドレスを元に位置情報をリアルタイムに付与する fluent-plugin-geoip v0.0.1をリリースしました #fluentd - Y-Ken Studio](http://y-ken.hatenablog.com/entry/fluent-plugin-geoip-has-released)
104
+ http://y-ken.hatenablog.com/entry/fluent-plugin-geoip-has-released
105
+
90
106
  ## TODO
91
107
 
92
108
  Pull requests are very welcome!!
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-geoip"
7
- spec.version = "0.0.2"
7
+ spec.version = "0.0.3"
8
8
  spec.authors = ["Kentaro Yoshida"]
9
9
  spec.email = ["y.ken.studio@gmail.com"]
10
10
  spec.summary = %q{Fluentd Output plugin to add information about geographical location of IP addresses with Maxmind GeoIP databases.}
@@ -45,12 +45,21 @@ class Fluent::GeoipOutput < Fluent::BufferedOutput
45
45
 
46
46
  def write(chunk)
47
47
  chunk.msgpack_each do |tag, time, record|
48
- result = @geoip.look_up(record[@geoip_lookup_key])
48
+ Fluent::Engine.emit(tag, time, add_geoip_field(record))
49
+ end
50
+ end
51
+
52
+ def add_geoip_field(record)
53
+ address = record[@geoip_lookup_key]
54
+ return record if address.nil?
55
+ result = @geoip.look_up(address)
56
+ if result.nil?
57
+ $log.info "geoip: lookup failed.", :address => address
58
+ else
49
59
  @geoip_keys_map.each do |geoip_key,record_key|
50
60
  record.store(record_key, result[geoip_key.to_sym])
51
61
  end
52
- $log.info "geoip: record:#{record}, result:#{result}"
53
- Fluent::Engine.emit(tag, time, record)
54
62
  end
63
+ return record
55
64
  end
56
65
  end
@@ -35,13 +35,33 @@ class GeoipOutputTest < Test::Unit::TestCase
35
35
  def test_emit
36
36
  d1 = create_driver(CONFIG, 'input.access')
37
37
  d1.run do
38
- d1.emit({'host' => '66.102.3.80', 'message' => 'action foo'})
38
+ d1.emit({'host' => '66.102.3.80', 'message' => 'valid ip'})
39
+ d1.emit({'message' => 'missing field'})
39
40
  end
40
41
  emits = d1.emits
41
- assert_equal 1, emits.length
42
+ assert_equal 2, emits.length
42
43
  p emits[0]
43
44
  assert_equal 'geoip.access', emits[0][0] # tag
44
45
  assert_equal 'Mountain View', emits[0][2]['geoip_city']
46
+ p emits[1]
47
+ assert_equal nil, emits[1][2]['geoip_city']
48
+ end
49
+
50
+ def test_emit_with_unknown_address
51
+ d1 = create_driver(CONFIG, 'input.access')
52
+ d1.run do
53
+ # 203.0.113.1 is a test address described in RFC5737
54
+ d1.emit({'host' => '203.0.113.1', 'message' => 'invalid ip'})
55
+ d1.emit({'host' => '0', 'message' => 'invalid ip'})
56
+ end
57
+ emits = d1.emits
58
+ assert_equal 2, emits.length
59
+ p emits[0]
60
+ assert_equal 'geoip.access', emits[0][0] # tag
61
+ assert_equal nil, emits[0][2]['geoip_city']
62
+ p emits[1]
63
+ assert_equal 'geoip.access', emits[1][0] # tag
64
+ assert_equal nil, emits[1][2]['geoip_city']
45
65
  end
46
66
 
47
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-geoip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-16 00:00:00.000000000 Z
12
+ date: 2013-09-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler