Class: Fluent::JsonLookupFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::JsonLookupFilter
- Defined in:
- lib/fluent/plugin/filter_json_lookup.rb
Constant Summary collapse
- BUILTIN_CONFIGURATIONS =
%w( type @type log_level @log_level id @id lookup_key json_key use_lookup_key_value remove_json_key ).freeze
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #deserialize_and_lookup(content, lookup) ⇒ Object
- #filter_stream(_tag, es) ⇒ Object
Instance Method Details
#configure(conf) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fluent/plugin/filter_json_lookup.rb', line 39 def configure(conf) super conf.each_pair do |k, v| unless BUILTIN_CONFIGURATIONS.include?(k) conf.key(k) log.warn "Extra key provided! Ignoring '#{k} #{v}'" end end # GC.start end |
#deserialize_and_lookup(content, lookup) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/fluent/plugin/filter_json_lookup.rb', line 52 def deserialize_and_lookup(content, lookup) values = {} begin deserialized = Yajl.load(content) if deserialized.is_a?(Hash) && deserialized.key?(lookup) && deserialized[lookup].is_a?(Hash) values = deserialized[lookup] end rescue Yajl::ParseError log.error "Error in plugin json_lookup, error parsing json_key's value #{content}'" end values end |
#filter_stream(_tag, es) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fluent/plugin/filter_json_lookup.rb', line 65 def filter_stream(_tag, es) new_es = MultiEventStream.new es.each do |time, record| values = {} if record.key?(@json_key) lookup = @use_lookup_key_value ? record[@lookup_key] : @lookup_key if record[@json_key][0] == '{' values = deserialize_and_lookup(record[@json_key], lookup) end end record.merge!(values) record.delete(@json_key) if @remove_json_key && record.key?(@json_key) new_es.add(time, record) end new_es end |