Class: Fluent::OutputFieldsAutotype

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

Instance Method Summary collapse

Instance Method Details

#compiled_patternObject



22
23
24
# File 'lib/fluent/plugin/out_fields_autotype.rb', line 22

def compiled_pattern
  @compiled_pattern ||= Regexp.new(pattern)
end

#emit(tag, es, chain) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/fluent/plugin/out_fields_autotype.rb', line 26

def emit(tag, es, chain)
  tag = update_tag(tag)
  es.each { |time, record|
    Engine.emit(tag, time, parse_fields(record))
  }
  chain.next
end

#parse_fields(record) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fluent/plugin/out_fields_autotype.rb', line 48

def parse_fields(record)
  source = record[parse_key].to_s
  target = fields_key ? (record[fields_key] ||= {}) : record

  reduced_source = source.dup
  until reduced_source.length == 0 do
    match1 = reduced_source.match pattern
    if !(match1.nil?)
      key = match1[1].to_s
      val = match1[2].to_s
      if !(target.has_key?(key))
        if val.is_i?
          target[key] = val.to_i
        elsif val.nan?
          target[key] = val
        else
          target[key] = val.to_f
        end
      end
      reduced_source = reduced_source[match1.offset(2)[1]..-1]
    else
      reduced_source = ""
    end
  end
  return record
end

#update_tag(tag) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fluent/plugin/out_fields_autotype.rb', line 34

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