Class: Fluent::OutputFieldMultiRegex
- Inherits:
-
Output
- Object
- Output
- Fluent::OutputFieldMultiRegex
- Defined in:
- lib/fluent/plugin/out_field_multiregex.rb
Instance Method Summary collapse
Instance Method Details
#emit(tag, es, chain) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/fluent/plugin/out_field_multiregex.rb', line 39 def emit(tag, es, chain) tag = update_tag(tag) es.each { |time, record| Engine.emit(tag, time, parse_field(record)) } chain.next end |
#parse_field(record) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/fluent/plugin/out_field_multiregex.rb', line 61 def parse_field(record) source = record[parse_key].to_s source_arr = [] if multiline source_arr = source.split( /\r?\n/ ) else source_arr << source end input_patterns = [pattern1,pattern2,pattern3,pattern4, pattern5,pattern6,pattern7,pattern8, pattern9,pattern10,pattern11,pattern12, pattern13,pattern14,pattern15,pattern16, pattern17,pattern18,pattern19,pattern20 ] matched = false input_patterns.each do |input_pattern| if !(input_pattern.nil?) source_arr.each do |source_elem| matched = false matched_hash = source_elem.match(input_pattern) if !(matched_hash.nil?) matched_hash.names.each do |key| val = matched_hash[key] if val.is_i? record[key] = val.to_i elsif val.nan? record[key] = val else record[key] = val.to_f end end matched = true end end end if matched break end end return record end |
#update_tag(tag) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/fluent/plugin/out_field_multiregex.rb', line 47 def update_tag(tag) if remove_tag_prefix if remove_tag_prefix == tag tag = '' elsif tag.to_s.start_with?(remove_tag_prefix+'.') tag = tag[remove_tag_prefix.length+1 .. -1] end end if add_tag_prefix tag = tag && tag.length > 0 ? "#{add_tag_prefix}.#{tag}" : add_tag_prefix end return tag end |