Module: Fluent::ConditionalFilterRule

Included in:
ConditionalFilterOutput, Plugin::ConditionalFilter
Defined in:
lib/fluent/plugin/conditional_filter_rule.rb

Instance Method Summary collapse

Instance Method Details

#filter_record(tag, time, record, plugin) ⇒ 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
# File 'lib/fluent/plugin/conditional_filter_rule.rb', line 5

def filter_record(tag, time, record, plugin)
  super(tag, time, record) if plugin.is_a?(Fluent::Output)
  case @filter
  when 'numeric_upward'
    filter_record = record.select do |key, value|
      key.match(@key_pattern_regexp) &&
        record[key].to_f >= @condition.to_f
    end
  when 'numeric_downward'
    filter_record = record.select do |key, value|
      key.match(@key_pattern_regexp) &&
        record[key].to_f <= @condition.to_f
    end
  when 'string_match'
    filter_record = record.select do |key, value|
      key.match(@key_pattern_regexp) &&
        record[key].match(Regexp.new(@condition))
    end
  else
    raise ArgumentError.new("[conditional_filter_rule] no such filter: #{filter}")
  end

  filter_record
end