Class: Fluent::Plugin::Output::PlaceholderValidator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, str, type, arg) ⇒ PlaceholderValidator

Returns a new instance of PlaceholderValidator.

Raises:

  • (ArgumentError)


648
649
650
651
652
653
654
# File 'lib/fluent/plugin/output.rb', line 648

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

Instance Attribute Details

#argumentObject (readonly)

Returns the value of attribute argument.



646
647
648
# File 'lib/fluent/plugin/output.rb', line 646

def argument
  @argument
end

#nameObject (readonly)

Returns the value of attribute name.



646
647
648
# File 'lib/fluent/plugin/output.rb', line 646

def name
  @name
end

#stringObject (readonly)

Returns the value of attribute string.



646
647
648
# File 'lib/fluent/plugin/output.rb', line 646

def string
  @string
end

#typeObject (readonly)

Returns the value of attribute type.



646
647
648
# File 'lib/fluent/plugin/output.rb', line 646

def type
  @type
end

Instance Method Details

#keys?Boolean

Returns:

  • (Boolean)


664
665
666
# File 'lib/fluent/plugin/output.rb', line 664

def keys?
  @type == :keys
end

#tag?Boolean

Returns:

  • (Boolean)


660
661
662
# File 'lib/fluent/plugin/output.rb', line 660

def tag?
  @type == :tag
end

#time?Boolean

Returns:

  • (Boolean)


656
657
658
# File 'lib/fluent/plugin/output.rb', line 656

def time?
  @type == :time
end

#validate!Object



668
669
670
671
672
673
674
# File 'lib/fluent/plugin/output.rb', line 668

def validate!
  case @type
  when :time then validate_time!
  when :tag  then validate_tag!
  when :keys then validate_keys!
  end
end

#validate_keys!Object



703
704
705
706
707
708
709
710
711
712
713
714
# File 'lib/fluent/plugin/output.rb', line 703

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!Object



692
693
694
695
696
697
698
699
700
701
# File 'lib/fluent/plugin/output.rb', line 692

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!Object



676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
# File 'lib/fluent/plugin/output.rb', line 676

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