Sha256: 445b495b2d0b830d630154946e18137ea0d659aa65b7177107b100043ec79ec0
Contents?: true
Size: 1.88 KB
Versions: 1
Compression:
Stored size: 1.88 KB
Contents
class Fluent::URIDecoder < Fluent::Output Fluent::Plugin.register_output('uri_decode', self) config_param :tag, :string, :default => nil config_param :remove_prefix, :string, :default => nil config_param :add_prefix, :string, :default => nil config_param :key_name, :string, :default => nil config_param :key_names, :string, :default => '' def initialize super require 'uri' end def configure(conf) super if !@remove_prefix && !@add_prefix && !@tag raise Fluent::ConfigError, "missing both of remove_prefix and add_prefix" end if @tag && @remove_prefix && @add_prefix raise Fluent::ConfigError, "either remove_prefix/add_prefix must not be specified" end if @remove_prefix @removed_prefix_string = @remove_prefix + '.' @removed_length = @removed_prefix_string.length end if @add_prefix @added_prefix_string = @add_prefix + '.' end end def tag_mangle(tag) if @tag @tag else if @remove_prefix and (tag == @remove_prefix || tag.start_with?(@removed_prefix_string) && tag.length > @removed_length) tag = tag[@removed_length..-1] end if @add_prefix tag = if tag and tag.length > 0 @added_prefix_string + tag else @add_prefix end end tag end end def emit(tag, es, chain) tag = tag_mangle(tag) # After first emit, @key_names will be array of given key names. # Escape [].split, ensure @key_names to be an instance of String. if @key_names.kind_of?(String) @key_names = @key_names.split(/,\s*/) end @key_names << @key_name if @key_name es.each do |time, record| @key_names.each do |key_name| record[key_name] = URI.decode(record[key_name] || '').gsub(/"/, "'") end Fluent::Engine.emit(tag, time, record) end chain.next end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
fluent-plugin-uri_decoder-0.1.1 | lib/fluent/plugin/out_uri_decode.rb |