Class: Fluent::Plugin::OnekeyparseFilter

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

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



28
29
30
31
# File 'lib/fluent/plugin/filter_onekeyparse.rb', line 28

def configure(conf)
  super
  @reg = Regexp.new(conf['in_format'], Regexp::IGNORECASE)
end

#filter(tag, time, record) ⇒ Object



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

def filter(tag, time, record)
  m = @reg.match(record[@in_key])
  unless m
    nil
    return
  end

  hash = m.named_captures
  record = {}
  @out_record_keys.split(",").each do | key |
    record[key] = hash.has_key?(key) ?  hash[key] : nil
  end
  record
end

#filter_stream(tag, es) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fluent/plugin/filter_onekeyparse.rb', line 48

def filter_stream(tag, es)
  new_es = MultiEventStream.new
  es.each { |time, record|
    begin
      filtered_record = filter(tag, time, record)
      new_es.add(time, filtered_record) if filtered_record
    rescue => e
      router.emit_error_event(tag, time, record, e)
    end
  }
  new_es
end