class Fluent::BurrowPlugin

Public Instance Methods

configure(conf) click to toggle source

Parse config hash

Calls superclass method
# File lib/fluent/plugin/out_burrow.rb, line 35
def configure(conf)
  super

  # One of 'tag', 'remove_prefix' or 'add_prefix' must be specified
  if not @tag and not @remove_prefix and not @add_prefix
    raise Fluent::ConfigError, "One of 'tag', 'remove_prefix' or 'add_prefix' must be specified"
  end
  if @tag and (@remove_prefix or @add_prefix)
    raise Fluent::ConfigError, "Specifying both 'tag' and either 'remove_prefix' or 'add_prefix' is not supported"
  end

  # Prepare for tag modification if required
  if @remove_prefix
    @removed_prefix_string = @remove_prefix.chomp('.') + '.'
    @removed_length = @removed_prefix_string.length
  end
  if @add_prefix
    @added_prefix_string = @add_prefix.chomp('.') + '.'
  end

  # Validate action
  actions = ['replace','overlay','inplace','prefix']
  if not actions.include? @action
    raise Fluent::ConfigError, "Invalid 'action', must be one of #{actions.join(',')}"
  end

  # Validate action-based restrictions
  if @action == 'inplace' and @keep_key
    raise Fluent::ConfigError, "Specifying 'keep_key' with action 'inplace' is not supported"
  end
  if @action == 'prefix' and not @data_prefix
    raise Fluent::ConfigError, "You must specify 'data_prefix' with action 'prefix'"
  end

  # Prepare fluent's built-in parser
  @parser = Fluent::TextParser.new()
  @parser.configure(conf)
end
emit(tag, es, chain) click to toggle source

This method is called when an event reaches Fluentd.

# File lib/fluent/plugin/out_burrow.rb, line 84
def emit(tag, es, chain)

  # Figure out new event tag (either manually specified, or modified with add_prefix|remove_prefix)
  if @tag
    tag = @tag
  else
    if @remove_prefix and
        ( (tag.start_with?(@removed_prefix_string) and tag.length > @removed_length) or tag == @remove_prefix)
      tag = tag[@removed_length..-1]
    end
    if @add_prefix
      if tag and tag.length > 0
        tag = @added_prefix_string + tag
      else
        tag = @add_prefix
      end
    end
  end

  # Handle all currently available events in stream
  es.each do |time,record|
    # Extract raw key value
    raw_value = record[@key_name]

    # Remember original time key, or raw event time
    raw_time = record[@record_time_key]

    # Try to parse it according to 'format'
    t,values = raw_value ? @parser.parse(raw_value) : [nil, nil]

    # Set new event's time to current time unless new time key was found in the sub-event
    t ||= raw_time

    r = values;

    # Overlay new record on top of original record?
    case @action
    when 'inplace'
      r = record.merge({@key_name => r})
    when 'overlay'
      r = record.merge(r)
    when 'replace'
      # noop
    when 'prefix'
      r = record.merge({@data_prefix => r})
    end

    # Keep the key?
    if ['overlay','replace','prefix'].include? @action
      if not @keep_key and not r.nil? and r.has_key?(@key_name)
        r.delete(@key_name)
      end
    end

    # Preserve 'time' key?
    if @keep_time
      r[@record_time_key] = raw_time
    end

    # Emit event back to Fluent
    if r
      router.emit(tag, t, r)
    end
  end

  chain.next
end
shutdown() click to toggle source

This method is called when shutting down.

# File lib/fluent/plugin/out_burrow.rb, line 80
def shutdown
end
start() click to toggle source

This method is called when starting.

Calls superclass method
# File lib/fluent/plugin/out_burrow.rb, line 75
def start
  super
end