Class: Fluent::Plugin::JsonFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_json.rb

Overview

JSON Filter class to override filter method

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fluent/plugin/filter_json.rb', line 35

def configure(conf)
  super

  @check.each do |chk|
    begin
      Hana::Pointer.parse(chk.pointer)
    rescue Hana::Pointer::FormatError => e
      raise Fluent::ConfigError, e
    end
  end
end

#filter(_tag, _time, record) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/fluent/plugin/filter_json.rb', line 47

def filter(_tag, _time, record)
  @check.each do |chk|
    pointer = Hana::Pointer.new(chk.pointer)
    pointee = pointer.eval(record).to_s
    matched = chk.pattern.match(pointee).nil? ? false : true
    log.debug("check: #{matched ? 'pass' : 'fail'} [#{chk.pointer} -> '#{pointee}'] (/#{chk.pattern.source}/)")
    return nil unless matched
  end
  record
end