Class: Fluent::Plugin::TKGIMetadataParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/fluent/plugin/parser_tkgi_metadata.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/fluent/plugin/parser_tkgi_metadata.rb', line 34

def configure(conf)
  super

  if @delimiter.length != 1
    raise ConfigError, "delimiter must be a single character. #{@delimiter} is not."
  end
end

#parse(text) {|nil, record| ... } ⇒ Object

Yields:

  • (nil, record)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fluent/plugin/parser_tkgi_metadata.rb', line 42

def parse(text)
  
    # Delete first and last square bracket
    text.delete_prefix!("[")
    text.delete_suffix!("]")

    # Replace any whitespaces with `_` if exists inside the double quotes
    text.gsub!(/\s+(?=(?:(?:[^"]*"){2})*[^"]*"[^"]*$)/,'_')

    # Delete any double quotes
    text.gsub!(/"/,'')
    
    source, key_values = text.split(' ', 2)
    source, id = source.split('@', 2)
    record = {}
    
    key_values.split(' ').each do |kv|
      k, v = kv.split('=', 2)

      if @es_mode
        k.gsub!(/[\.]/, '_')
      end

      record[k] = v
    end

    record.merge!(source: source, source_id: id)
    
    yield nil, record
end