fluent-plugin-geoip 0.0.4 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +1 -1
- data/README.md +33 -2
- data/fluent-plugin-geoip.gemspec +1 -1
- data/lib/fluent/plugin/out_geoip.rb +17 -5
- data/test/plugin/test_out_geoip.rb +22 -2
- metadata +2 -2
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -10,11 +10,23 @@ The accuracy details for GeoLite City (free) and GeoIP City (purchased) has desc
|
|
10
10
|
* http://www.maxmind.com/en/geolite_city_accuracy ([lang:ja](http://www.maxmind.com/ja/geolite_city_accuracy))
|
11
11
|
* http://www.maxmind.com/en/city_accuracy ([lang:ja](http://www.maxmind.com/ja/city_accuracy))
|
12
12
|
|
13
|
+
## Dependency
|
14
|
+
|
15
|
+
before use, install dependent library as:
|
16
|
+
|
17
|
+
```bash
|
18
|
+
# for RHEL/CentOS
|
19
|
+
$ sudo yum install geoip-devel --enablerepo=epel
|
20
|
+
|
21
|
+
# for Ubuntu/Debian
|
22
|
+
$ sudo apt-get install libgeoip-dev
|
23
|
+
```
|
24
|
+
|
13
25
|
## Installation
|
14
26
|
|
15
27
|
install with `gem` or `fluent-gem` command as:
|
16
28
|
|
17
|
-
```
|
29
|
+
```bash
|
18
30
|
# for fluentd
|
19
31
|
$ gem install fluent-plugin-geoip
|
20
32
|
|
@@ -31,18 +43,22 @@ $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-geoip
|
|
31
43
|
# buffering time (default: 60s)
|
32
44
|
flush_interval 1s
|
33
45
|
|
46
|
+
# Queued chunks are flushed at shutdown process.
|
47
|
+
flush_at_shutdown yes
|
48
|
+
|
34
49
|
# tag settings
|
35
50
|
remove_tag_prefix access.
|
36
51
|
add_tag_prefix geoip.
|
37
52
|
include_tag_key false
|
38
53
|
|
39
54
|
# specify geoip lookup field (default: host)
|
55
|
+
# in the case of accessing nested value, delimit keys by dot like 'host.ip'.
|
40
56
|
geoip_lookup_key host
|
41
57
|
|
42
58
|
# specify geoip database (using bundled GeoLiteCity databse by default)
|
43
59
|
geoip_database 'data/GeoLiteCity.dat'
|
44
60
|
|
45
|
-
# record settings (enable more than one keys required.)
|
61
|
+
# record settings (enable more than one keys are required.)
|
46
62
|
enable_key_city geoip_city
|
47
63
|
enable_key_latitude geoip_lat
|
48
64
|
enable_key_longitude geoip_lon
|
@@ -98,11 +114,26 @@ $ tail /var/log/td-agent/td-agent.log
|
|
98
114
|
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}
|
99
115
|
```
|
100
116
|
|
117
|
+
For more details of geoip data format is described at the page below in section `GeoIP City Edition CSV Database Fields`.
|
118
|
+
http://dev.maxmind.com/geoip/legacy/csv/
|
119
|
+
|
101
120
|
## Articles
|
102
121
|
|
103
122
|
* [IPアドレスを元に位置情報をリアルタイムに付与する fluent-plugin-geoip v0.0.1をリリースしました #fluentd - Y-Ken Studio](http://y-ken.hatenablog.com/entry/fluent-plugin-geoip-has-released)
|
104
123
|
http://y-ken.hatenablog.com/entry/fluent-plugin-geoip-has-released
|
105
124
|
|
125
|
+
* [初の安定版 fluent-plugin-geoip v0.0.3 をリリースしました #fluentd- Y-Ken Studio](http://y-ken.hatenablog.com/entry/fluent-plugin-geoip-v0.0.3)
|
126
|
+
http://y-ken.hatenablog.com/entry/fluent-plugin-geoip-v0.0.3
|
127
|
+
|
128
|
+
* [fluent-plugin-geoip v0.0.4 をリリースしました。ElasticSearch+Kibanaの世界地図に位置情報をプロットするために必要なFluentdの設定サンプルも紹介します- Y-Ken Studio](http://y-ken.hatenablog.com/entry/fluent-plugin-geoip-v0.0.4)
|
129
|
+
http://y-ken.hatenablog.com/entry/fluent-plugin-geoip-v0.0.4
|
130
|
+
|
131
|
+
* [Released GeoIP plugin to work together with ElasticSearch + Kibana v3](https://groups.google.com/d/topic/fluentd/OVIcH_SKBwM/discussion)
|
132
|
+
https://groups.google.com/d/topic/fluentd/OVIcH_SKBwM/discussion
|
133
|
+
|
134
|
+
* [Fluentd、Amazon RedshiftとTableauを用いたカジュアルなデータ可視化 | SmartNews開発者ブログ](http://developer.smartnews.be/blog/2013/10/03/easy-data-analysis-using-fluentd-redshift-and-tableau/)
|
135
|
+
http://developer.smartnews.be/blog/2013/10/03/easy-data-analysis-using-fluentd-redshift-and-tableau/
|
136
|
+
|
106
137
|
## TODO
|
107
138
|
|
108
139
|
Pull requests are very welcome!!
|
data/fluent-plugin-geoip.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = "fluent-plugin-geoip"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.5"
|
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.}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Fluent::GeoipOutput < Fluent::BufferedOutput
|
2
2
|
Fluent::Plugin.register_output('geoip', self)
|
3
|
-
|
3
|
+
|
4
4
|
GEOIP_KEYS = %w(city latitude longitude country_code3 country_code country_name dma_code area_code region)
|
5
5
|
config_param :geoip_database, :string, :default => File.dirname(__FILE__) + '/../../../data/GeoLiteCity.dat'
|
6
6
|
config_param :geoip_lookup_key, :string, :default => 'host'
|
@@ -13,7 +13,7 @@ class Fluent::GeoipOutput < Fluent::BufferedOutput
|
|
13
13
|
require 'geoip'
|
14
14
|
super
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def configure(conf)
|
18
18
|
super
|
19
19
|
|
@@ -24,6 +24,9 @@ class Fluent::GeoipOutput < Fluent::BufferedOutput
|
|
24
24
|
@geoip_keys_map.store(geoip_key_name, conf[key])
|
25
25
|
end
|
26
26
|
|
27
|
+
@geoip_lookup_key = @geoip_lookup_key.split(".")
|
28
|
+
|
29
|
+
|
27
30
|
if ( !@remove_tag_prefix && !@remove_tag_suffix && !@add_tag_prefix && !@add_tag_suffix )
|
28
31
|
raise Fluent::ConfigError, "geoip: missing remove_tag_prefix, remove_tag_suffix, add_tag_prefix or add_tag_suffix."
|
29
32
|
end
|
@@ -34,11 +37,11 @@ class Fluent::GeoipOutput < Fluent::BufferedOutput
|
|
34
37
|
def start
|
35
38
|
super
|
36
39
|
end
|
37
|
-
|
40
|
+
|
38
41
|
def format(tag, time, record)
|
39
42
|
[tag, time, record].to_msgpack
|
40
43
|
end
|
41
|
-
|
44
|
+
|
42
45
|
def shutdown
|
43
46
|
super
|
44
47
|
end
|
@@ -49,8 +52,17 @@ class Fluent::GeoipOutput < Fluent::BufferedOutput
|
|
49
52
|
end
|
50
53
|
end
|
51
54
|
|
55
|
+
def get_address(record)
|
56
|
+
obj = record
|
57
|
+
@geoip_lookup_key.each do |key|
|
58
|
+
return nil if not obj.has_key?(key)
|
59
|
+
obj = obj[key]
|
60
|
+
end
|
61
|
+
obj
|
62
|
+
end
|
63
|
+
|
52
64
|
def add_geoip_field(record)
|
53
|
-
address = record
|
65
|
+
address = get_address(record)
|
54
66
|
return record if address.nil?
|
55
67
|
result = @geoip.look_up(address)
|
56
68
|
return record if result.nil?
|
@@ -40,6 +40,26 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
40
40
|
end
|
41
41
|
emits = d1.emits
|
42
42
|
assert_equal 2, emits.length
|
43
|
+
# p emits[0]
|
44
|
+
assert_equal 'geoip.access', emits[0][0] # tag
|
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_nested_attr
|
51
|
+
d1 = create_driver(%[
|
52
|
+
geoip_lookup_key host.ip
|
53
|
+
enable_key_city geoip_city
|
54
|
+
remove_tag_prefix input.
|
55
|
+
add_tag_prefix geoip.
|
56
|
+
], 'input.access')
|
57
|
+
d1.run do
|
58
|
+
d1.emit({'host' => {'ip' => '66.102.3.80'}, 'message' => 'valid ip'})
|
59
|
+
d1.emit({'message' => 'missing field'})
|
60
|
+
end
|
61
|
+
emits = d1.emits
|
62
|
+
assert_equal 2, emits.length
|
43
63
|
p emits[0]
|
44
64
|
assert_equal 'geoip.access', emits[0][0] # tag
|
45
65
|
assert_equal 'Mountain View', emits[0][2]['geoip_city']
|
@@ -56,10 +76,10 @@ class GeoipOutputTest < Test::Unit::TestCase
|
|
56
76
|
end
|
57
77
|
emits = d1.emits
|
58
78
|
assert_equal 2, emits.length
|
59
|
-
p emits[0]
|
79
|
+
# p emits[0]
|
60
80
|
assert_equal 'geoip.access', emits[0][0] # tag
|
61
81
|
assert_equal nil, emits[0][2]['geoip_city']
|
62
|
-
p emits[1]
|
82
|
+
# p emits[1]
|
63
83
|
assert_equal 'geoip.access', emits[1][0] # tag
|
64
84
|
assert_equal nil, emits[1][2]['geoip_city']
|
65
85
|
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.
|
4
|
+
version: 0.0.5
|
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:
|
12
|
+
date: 2014-01-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|