Class: Fluent::FilterOutput

Inherits:
Output
  • Object
show all
Defined in:
lib/fluent/plugin/out_filter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#allowsObject

Returns the value of attribute allows.



10
11
12
# File 'lib/fluent/plugin/out_filter.rb', line 10

def allows
  @allows
end

#deniesObject

Returns the value of attribute denies.



11
12
13
# File 'lib/fluent/plugin/out_filter.rb', line 11

def denies
  @denies
end

Instance Method Details

#configure(conf) ⇒ Object



13
14
15
16
17
# File 'lib/fluent/plugin/out_filter.rb', line 13

def configure(conf)
  super
  @allows = toMap(@allow)
  @denies = toMap(@deny)
end

#emit(tag, es, chain) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/fluent/plugin/out_filter.rb', line 63

def emit(tag, es, chain)
  if @add_prefix
    tag = @add_prefix + '.' + tag
  end
  es.each do |time, record|
    next unless passRules(record)
    Engine.emit(tag, time, record)
  end
  chain.next
end

#passRules(record) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/fluent/plugin/out_filter.rb', line 35

def passRules (record)
  if @all == 'allow'
    @denies.each do |deny|
      if (deny[1].is_a? Regexp and record[deny[0]].match(deny[1])) or record[deny[0]] == deny[1]
        @allows.each do |allow|
          if (allow[1].is_a? Regexp and record[allow[0]].match(allow[1])) or record[allow[0]] == allow[1]
            return true
          end
        end
        return false
      end
    end
    return true
  else
    @allows.each do |allow|
      if (allow[1].is_a? Regexp and record[allow[0]].match(allow[1])) or record[allow[0]] == allow[1]
        @denies.each do |deny|
          if (deny[1].is_a? Regexp and record[deny[0]].match(deny[1])) or record[deny[0]] == deny[1]
            return false
          end
        end
        return true
      end
    end
    return false
  end
end

#toMap(str) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/fluent/plugin/out_filter.rb', line 19

def toMap (str)
  str.split(/\s*,\s*/).map do|pair|
    k, v = pair.split(/\s*:\s*/, 2)
    if v =~ /^\d+$/
      v = v.to_i
    elsif v =~ /^[\d\.]+(e\d+)?$/
      v = v.to_f
    elsif v =~ /^\/[^\/]+\/$/
      v = Regexp.new(v.gsub(/^\/|\/$/, ''))
    else
      v = v.gsub(/^[\"\']|[\"\']$/, '')
    end
    [k, v]
  end
end