class Fluent::MackerelHostidTagOutput

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_mackerel_hostid_tag.rb, line 22
def initialize
  super
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_mackerel_hostid_tag.rb, line 26
def configure(conf)
  super
  @hostid = File.open(@hostid_path).read
  if @add_to == 'record' and @key_name.nil?
    raise Fluent::ConfigError, "'key_name' must be specified"
  end
  if @remove_prefix
    @removed_prefix_string = @remove_prefix + '.'
    @removed_length = @removed_prefix_string.length
  end
  @added_prefix_string = @add_prefix + '.' unless @add_prefix.nil?
end
emit(tag, es, chain) click to toggle source
# File lib/fluent/plugin/out_mackerel_hostid_tag.rb, line 39
def emit(tag, es, chain)
  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 tag.length > 0
    tag = @added_prefix_string + tag if @added_prefix_string
  else
    tag = @add_prefix
  end
  if @add_to == 'tag'
    tag = [tag, @hostid].join('.')
  end

  es.each do |time, record|
    if @add_to == 'record'
      record[@key_name] = @hostid
    end
    router.emit(tag, time, record)
  end

  chain.next
end