fluent-plugin-geoip 0.1.1 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.1.0
4
+ - 2.1
5
5
  - 2.0.0
6
6
  - 1.9.3
7
7
 
data/README.md CHANGED
@@ -44,8 +44,8 @@ $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-geoip
44
44
  # in the case of accessing nested value, delimit keys by dot like 'host.ip'.
45
45
  geoip_lookup_key host
46
46
 
47
- # Specify geoip database (using bundled GeoLiteCity databse by default)
48
- geoip_database 'data/GeoLiteCity.dat'
47
+ # Specify optional geoip database (using bundled GeoLiteCity databse by default)
48
+ geoip_database '/path/to/your/GeoIPCity.dat'
49
49
 
50
50
  # Set adding field with placeholder (more than one settings are required.)
51
51
  <record>
@@ -53,10 +53,10 @@ $ sudo /usr/lib64/fluent/ruby/bin/fluent-gem install fluent-plugin-geoip
53
53
  latitude ${latitude['host']}
54
54
  longitude ${longitude['host']}
55
55
  country_code3 ${country_code3['host']}
56
- country ${country['host']}
56
+ country ${country_code['host']}
57
57
  country_name ${country_name['host']}
58
- dma ${dma['host']}
59
- area ${area['host']}
58
+ dma ${dma_code['host']}
59
+ area ${area_code['host']}
60
60
  region ${region['host']}
61
61
  </record>
62
62
 
@@ -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.1.1"
7
+ spec.version = "0.2.0"
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.}
@@ -63,13 +63,13 @@ class Fluent::GeoipOutput < Fluent::BufferedOutput
63
63
  @map[k] = v
64
64
  validate_json = Proc.new {
65
65
  begin
66
- dummy_text = '12345'
67
- Yajl::Parser.parse(v.gsub(REGEXP_PLACEHOLDER_SCAN, dummy_text)) if v.match(REGEXP_JSON)
66
+ dummy_text = Yajl::Encoder.encode('dummy_text')
67
+ Yajl::Parser.parse(v.gsub(REGEXP_PLACEHOLDER_SCAN, dummy_text))
68
68
  rescue Yajl::ParseError => e
69
69
  raise Fluent::ConfigError, "geoip: failed to parse '#{v}' as json."
70
70
  end
71
71
  }
72
- validate_json.call
72
+ validate_json.call if v.match(REGEXP_JSON)
73
73
  }
74
74
  }
75
75
  @placeholder_keys = @map.values.join.scan(REGEXP_PLACEHOLDER_SCAN).map{ |placeholder| placeholder[0] }.uniq
@@ -135,6 +135,7 @@ class Fluent::GeoipOutput < Fluent::BufferedOutput
135
135
  def get_address(record)
136
136
  address = {}
137
137
  @geoip_lookup_key.each do |field|
138
+ address.store(field, record[field]); next if not record[field].nil?
138
139
  key = field.split('.')
139
140
  obj = record
140
141
  key.each {|k|
@@ -89,7 +89,9 @@ class GeoipOutputTest < Test::Unit::TestCase
89
89
  def test_emit_tag_option
90
90
  d1 = create_driver(%[
91
91
  geoip_lookup_key host
92
- enable_key_city geoip_city
92
+ <record>
93
+ geoip_city ${city['host']}
94
+ </record>
93
95
  remove_tag_prefix input.
94
96
  tag geoip.${tag}
95
97
  ], 'input.access')
@@ -104,6 +106,43 @@ class GeoipOutputTest < Test::Unit::TestCase
104
106
  assert_equal nil, emits[1][2]['geoip_city']
105
107
  end
106
108
 
109
+ def test_emit_tag_parts
110
+ d1 = create_driver(%[
111
+ geoip_lookup_key host
112
+ <record>
113
+ geoip_city ${city['host']}
114
+ </record>
115
+ tag geoip.${tag_parts[1]}.${tag_parts[2..3]}.${tag_parts[-1]}
116
+ ], '0.1.2.3')
117
+ d1.run do
118
+ d1.emit({'host' => '66.102.3.80'})
119
+ end
120
+ emits = d1.emits
121
+ assert_equal 1, emits.length
122
+ assert_equal 'geoip.1.2.3.3', emits[0][0] # tag
123
+ assert_equal 'Mountain View', emits[0][2]['geoip_city']
124
+ end
125
+
126
+ def test_emit_with_dot_key
127
+ d1 = create_driver(%[
128
+ geoip_lookup_key ip.origin, ip.dest
129
+ <record>
130
+ origin_country ${country_code['ip.origin']}
131
+ dest_country ${country_code['ip.dest']}
132
+ </record>
133
+ remove_tag_prefix input.
134
+ tag geoip.${tag}
135
+ ], 'input.access')
136
+ d1.run do
137
+ d1.emit({'ip.origin' => '66.102.3.80', 'ip.dest' => '8.8.8.8'})
138
+ end
139
+ emits = d1.emits
140
+ assert_equal 1, emits.length
141
+ assert_equal 'geoip.access', emits[0][0] # tag
142
+ assert_equal 'US', emits[0][2]['origin_country']
143
+ assert_equal 'US', emits[0][2]['dest_country']
144
+ end
145
+
107
146
  def test_emit_nested_attr
108
147
  d1 = create_driver(%[
109
148
  geoip_lookup_key host.ip
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.1.1
4
+ version: 0.2.0
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: 2014-03-31 00:00:00.000000000 Z
12
+ date: 2014-10-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler