Class: Fluent::EvalFilterOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::EvalFilterOutput
- Defined in:
- lib/fluent/plugin/out_eval_filter.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #create_result(tag, time, record, result) ⇒ Object
- #emit(tag, es, chain) ⇒ Object
- #filter_record(tag, time, record) ⇒ Object
- #handle_tag(tag) ⇒ Object
Instance Method Details
#configure(conf) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/fluent/plugin/out_eval_filter.rb', line 5 def configure(conf) super if remove_tag_prefix = conf['remove_tag_prefix'] @remove_tag_prefix = /^#{Regexp.escape(remove_tag_prefix)}\.*/ end if remove_tag_suffix = conf['remove_tag_suffix'] @remove_tag_suffix = /\.*#{Regexp.escape(remove_tag_suffix)}$/ end @add_tag_prefix = conf['add_tag_prefix'] @add_tag_suffix = conf['add_tag_suffix'] conf.keys.select { |key| key =~ /^config\d+$/ }.sort_by { |key| key.sub('config', '').to_i }.each do |key| begin instance_eval("#{conf[key]}") rescue Exception => e raise Fluent::ConfigError, "#{key} #{conf[key]}\n" + e.to_s end end @filters = [] conf.keys.select { |key| key =~ /^filter\d+$/ }.sort_by { |key| key.sub('filter', '').to_i }.each do |key| begin @filters << instance_eval("lambda do |tag, time, record| #{conf[key]} end") rescue Exception => e raise Fluent::ConfigError, "#{key} #{conf[key]}\n" + e.to_s end end if @filters.empty? raise Fluent::ConfigError, "missing filters" end end |
#create_result(tag, time, record, result) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/fluent/plugin/out_eval_filter.rb', line 65 def create_result(tag, time, record, result) result = [result] unless result.is_a?(Array) result.each do |value| tag = value if value.is_a?(String) time = value if value.is_a?(Integer) record = value if value.is_a?(Hash) end [tag, time, record] end |
#emit(tag, es, chain) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/fluent/plugin/out_eval_filter.rb', line 39 def emit(tag, es, chain) tag = handle_tag(tag) es.each do |time, record| result = filter_record(tag, time, record) Fluent::Engine.emit(*result) if result end chain.next end |
#filter_record(tag, time, record) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/fluent/plugin/out_eval_filter.rb', line 56 def filter_record(tag, time, record) @filters.each do |filter| filter_result = filter.call(tag, time, record) result = create_result(tag, time, record, filter_result) if filter_result return result if result end nil end |
#handle_tag(tag) ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/fluent/plugin/out_eval_filter.rb', line 48 def handle_tag(tag) tag = tag.sub(@remove_tag_prefix, '') if @remove_tag_prefix tag = tag.sub(@remove_tag_suffix, '') if @remove_tag_suffix tag = tag.sub(/^\.*/, "#{@add_tag_prefix}.") if @add_tag_prefix tag = tag.sub(/\.*$/, ".#{@add_tag_suffix}") if @add_tag_suffix tag end |