class Fluent::MuleFilter

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_mule.rb, line 17
def configure(conf)
  super
  # TimeParser class is already given. It takes a single argument as the time format
  # to parse the time string with.
  @time_parser = Fluent::TextParser::TimeParser.new(@time_format)
end
filter(tag, time, record) click to toggle source
# File lib/fluent/plugin/filter_mule.rb, line 36
def filter(tag, time, record)
  # This method implements the filtering logic for individual filters
  # It is internal to this class and called by filter_stream unless
  # the user overrides filter_stream.
  #
  # If returns nil, that records are ignored.
  text = record[@key_name]

  messageRegex = /
    ^
    (?<log_level>[\w]+)\s+
    (?<log_time>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2},\d{3})\s+
    \[(?<thread>.+)\]\s+
    (?<position>[^:]+):\s+
    (?<kv_pairs>.*?)\s*
    (?<payload>payload=.*)?
    $
  /x
  
  match = text.match(messageRegex)      

  # If message doesn't match regex we return the record as is
  if match.nil?
    return record
  end

  ['log_level', 'log_time', 'thread', 'position', 'kv_pairs'].each { |group|
    updateRecord(record, match, group, group == 'kv_pairs')
  }

  if (match.names.include? 'payload') && !match['payload'].nil?
    k, v = match['payload'].split('=', 2)
    record[@prefix + k] = v
  end
    
  if @time_parse && !record['log_time'].nil? 
    new_time = @time_parser.parse(record['mule_log_time'])
    record.delete('time')
    record['time'] = current_time
  end
  record.delete(@key_name)
  record
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_mule.rb, line 30
def shutdown
  super
  # This method is called when Fluentd is shutting down.
  # Use it to free up resources, etc.
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/filter_mule.rb, line 24
def start
  super
  # This is the first method to be called when it starts running
  # Use it to allocate resources, etc.
end
updateRecord(record, match, group, kv_flag) click to toggle source
# File lib/fluent/plugin/filter_mule.rb, line 80
def updateRecord(record, match, group, kv_flag)
  if (match.names.include? group) && !match[group].nil?
    if kv_flag
      kv_match = match[group].match(/(\w+)=([\w|-]+)\s/)
      if kv_match.nil?
        return 
      end

      match[group].split(@kv_delimiter).each { |kv|
        k, v = kv.split(@kv_char, 2)
        record[@prefix + k] = v
      }
    else
      record[@prefix + group] = match[group]
    end
  end
end