Class: Fluent::DecodeLocationOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::DecodeLocationOutput
- Defined in:
- lib/fluent/plugin/out_decode_location.rb
Constant Summary collapse
- SEPARATOR =
'a'- SEPARATOR_DOT =
'b'- SEPARATOR_DASH =
'c'
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #decode_location(record) ⇒ Object
- #emit(tag, es, chain) ⇒ Object
-
#initialize ⇒ DecodeLocationOutput
constructor
A new instance of DecodeLocationOutput.
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ DecodeLocationOutput
Returns a new instance of DecodeLocationOutput.
12 13 14 15 16 |
# File 'lib/fluent/plugin/out_decode_location.rb', line 12 def initialize super require 'base62' require 'base64' end |
Instance Method Details
#configure(conf) ⇒ Object
23 24 25 |
# File 'lib/fluent/plugin/out_decode_location.rb', line 23 def configure(conf) super end |
#decode_location(record) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/fluent/plugin/out_decode_location.rb', line 49 def decode_location(record) source = record key.split('.').each do |v| if source[v] || source[v.to_sym] source = source[v] ? source[v] : source[v.to_sym] else record['break'] = true source = nil break end end if source hash = {} city = '' if source.include? ":|" exploded = source.split(":|") source = exploded[0] city = exploded[1] if city.is_a?(String) city = Base64.decode64(city) city.force_encoding('utf-8') end end array = source.to_i.base62_encode.gsub(SEPARATOR_DASH, '-').gsub(SEPARATOR_DOT, '.').split(SEPARATOR) hash['lat'] = array[0] ? array[0] : '' hash['lng'] = array[1] ? array[1] : '' hash['continent'] = array[2] ? array[2] : '' hash['countryCode'] = array[3] ? array[3] : '' hash['province'] = array[4] ? array[4] : '' hash['city'] = city target = sub_key ? (record[sub_key] ||= {}) : record target.merge!(hash) end return record rescue => e log.warn("out_decode_location: error_class:#{e.class} error_message:#{e.message} tag:#{tag} record:#{record} bactrace:#{e.backtrace.first}") end |
#emit(tag, es, chain) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fluent/plugin/out_decode_location.rb', line 35 def emit(tag, es, chain) es.each {|time, record| t = tag.dup new_record = decode_location(record) t = @tag_prefix + t unless @tag_prefix.nil? Engine.emit(t, time, new_record) } chain.next rescue => e log.warn("out_decode_location: error_class:#{e.class} error_message:#{e.message} tag:#{tag} es:#{es} bactrace:#{e.backtrace.first}") end |
#shutdown ⇒ Object
31 32 33 |
# File 'lib/fluent/plugin/out_decode_location.rb', line 31 def shutdown super end |
#start ⇒ Object
27 28 29 |
# File 'lib/fluent/plugin/out_decode_location.rb', line 27 def start super end |