Class: Fluent::Plugin::RedactionFilter

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

Instance Method Summary collapse

Constructor Details

#initializeRedactionFilter

Returns a new instance of RedactionFilter.



17
18
19
20
21
# File 'lib/fluent/plugin/filter_redaction.rb', line 17

def initialize
    @pattern_rules_map = {}
    @accessors = {}
    super
end

Instance Method Details

#configure(conf) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fluent/plugin/filter_redaction.rb', line 23

def configure(conf)
    super

    @rule_config_list.each do |c|
        unless c.key
            key_missing = true
        end
        if key_missing
            raise Fluent::ConfigError, "Field 'key' is missing from rule section. #{c}"
        end
        unless c.value || c.pattern
            value_missing = true
        end
        if value_missing
            raise Fluent::ConfigError, "Field 'value' or 'pattern' is missing from rule section for key: #{c.key}."
        end
        record_accessor = record_accessor_create(c.key)
        @accessors["#{c.key}"] = record_accessor
        list = []
        if @pattern_rules_map.key?(c.key)
            list = @pattern_rules_map[c.key]
        end
        list << [c.value, c.pattern, c.replace]
        @pattern_rules_map[c.key] = list
    end
end

#filter(tag, time, record) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fluent/plugin/filter_redaction.rb', line 50

def filter(tag, time, record)
    @pattern_rules_map.each do |key, rules|
        record_value = @accessors[key].call(record)
        if record_value
            rules.each do | rule |
                if rule[0]
                    record_value = record_value.gsub(rule[0], rule[2])
                else
                    record_value = record_value.gsub(rule[1], rule[2])
                end
            end
            @accessors[key].set(record, record_value)
        end
    end
    record
end