class Fluent::Plugin::Output::PlaceholderValidator

Attributes

argument[R]
name[R]
string[R]
type[R]

Public Class Methods

new(name, str, type, arg) click to toggle source
# File lib/fluent/plugin/output.rb, line 558
def initialize(name, str, type, arg)
  @name = name
  @string = str
  @type = type
  raise ArgumentError, "invalid type:#{type}" if @type != :time && @type != :tag && @type != :keys
  @argument = arg
end

Public Instance Methods

keys?() click to toggle source
# File lib/fluent/plugin/output.rb, line 574
def keys?
  @type == :keys
end
tag?() click to toggle source
# File lib/fluent/plugin/output.rb, line 570
def tag?
  @type == :tag
end
time?() click to toggle source
# File lib/fluent/plugin/output.rb, line 566
def time?
  @type == :time
end
validate!() click to toggle source
# File lib/fluent/plugin/output.rb, line 578
def validate!
  case @type
  when :time then validate_time!
  when :tag  then validate_tag!
  when :keys then validate_keys!
  end
end
validate_keys!() click to toggle source
# File lib/fluent/plugin/output.rb, line 613
def validate_keys!
  keys = @argument[:keys]
  chunk_keys = @argument[:chunkkeys]
  if (chunk_keys - keys).size > 0
    not_specified = (chunk_keys - keys).sort
    raise Fluent::ConfigError, "Parameter '#{name}: #{string}' doesn't have enough placeholders for keys #{not_specified.join(',')}"
  end
  if (keys - chunk_keys).size > 0
    not_satisfied = (keys - chunk_keys).sort
    raise Fluent::ConfigError, "Parameter '#{name}: #{string}' has placeholders, but chunk keys doesn't have keys #{not_satisfied.join(',')}"
  end
end
validate_tag!() click to toggle source
# File lib/fluent/plugin/output.rb, line 602
def validate_tag!
  parts = @argument[:parts]
  tagkey = @argument[:tagkey]
  if tagkey && parts.empty?
    raise Fluent::ConfigError, "Parameter '#{name}: #{string}' doesn't have tag placeholder"
  end
  if !tagkey && !parts.empty?
    raise Fluent::ConfigError, "Parameter '#{name}: #{string}' has tag placeholders, but chunk key 'tag' is not configured"
  end
end
validate_time!() click to toggle source
# File lib/fluent/plugin/output.rb, line 586
def validate_time!
  sec = @argument[:sec]
  title = @argument[:title]
  example = @argument[:example]
  timekey = @argument[:timekey]
  if !sec && timekey
    raise Fluent::ConfigError, "Parameter '#{name}: #{string}' doesn't have timestamp placeholders for timekey #{timekey.to_i}"
  end
  if sec && !timekey
    raise Fluent::ConfigError, "Parameter '#{name}: #{string}' has timestamp placeholders, but chunk key 'time' is not configured"
  end
  if sec && timekey && timekey < sec
    raise Fluent::ConfigError, "Parameter '#{name}: #{string}' doesn't have timestamp placeholder for #{title}('#{example}') for timekey #{timekey.to_i}"
  end
end