Class: Fluent::Plugin::StringScrubFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::Plugin::StringScrubFilter
- Defined in:
- lib/fluent/plugin/filter_string_scrub.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #filter_stream(tag, es) ⇒ Object
-
#initialize ⇒ StringScrubFilter
constructor
A new instance of StringScrubFilter.
- #recv_record(record) ⇒ Object
- #with_scrub(string) ⇒ Object
Constructor Details
#initialize ⇒ StringScrubFilter
Returns a new instance of StringScrubFilter.
8 9 10 |
# File 'lib/fluent/plugin/filter_string_scrub.rb', line 8 def initialize super end |
Instance Method Details
#configure(conf) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/fluent/plugin/filter_string_scrub.rb', line 12 def configure(conf) super if @replace_char =~ /\\u\{*[A-F0-9]{4}\}*/ @replace_char = eval("\"#{@replace_char}\"") end end |
#filter_stream(tag, es) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/fluent/plugin/filter_string_scrub.rb', line 20 def filter_stream(tag, es) new_es = Fluent::MultiEventStream.new es.each do |time,record| begin scrubbed = recv_record(record) next if scrubbed.nil? new_es.add(time, scrubbed) rescue => e router.emit_error_event(tag, time, record, e) end end new_es end |
#recv_record(record) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/fluent/plugin/filter_string_scrub.rb', line 35 def recv_record(record) scrubbed = {} record.each do |k,v| if v.instance_of? Hash scrubbed[with_scrub(k)] = recv_record(v) elsif v.instance_of? Integer scrubbed[k] = v else scrubbed[with_scrub(k)] = with_scrub(v) end end scrubbed end |
#with_scrub(string) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fluent/plugin/filter_string_scrub.rb', line 49 def with_scrub(string) begin string =~ // return string rescue ArgumentError => e raise e unless e..index("invalid byte sequence in") == 0 if string.frozen? string = string.dup.scrub!(@replace_char) else string.scrub!(@replace_char) end retry end end |