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)


712
713
714
715
716
717
718
# File 'lib/fluent/plugin/output.rb', line 712

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

#argument ⇒ Object (readonly)

Returns the value of attribute argument.



710
711
712
# File 'lib/fluent/plugin/output.rb', line 710

def argument
  @argument
end

#name ⇒ Object (readonly)

Returns the value of attribute name.



710
711
712
# File 'lib/fluent/plugin/output.rb', line 710

def name
  @name
end

#string ⇒ Object (readonly)

Returns the value of attribute string.



710
711
712
# File 'lib/fluent/plugin/output.rb', line 710

def string
  @string
end

#type ⇒ Object (readonly)

Returns the value of attribute type.



710
711
712
# File 'lib/fluent/plugin/output.rb', line 710

def type
  @type
end

Instance Method Details

#keys? ⇒ Boolean

Returns:

  • (Boolean)


728
729
730
# File 'lib/fluent/plugin/output.rb', line 728

def keys?
  @type == :keys
end

#tag? ⇒ Boolean

Returns:

  • (Boolean)


724
725
726
# File 'lib/fluent/plugin/output.rb', line 724

def tag?
  @type == :tag
end

#time? ⇒ Boolean

Returns:

  • (Boolean)


720
721
722
# File 'lib/fluent/plugin/output.rb', line 720

def time?
  @type == :time
end

#validate! ⇒ Object



732
733
734
735
736
737
738
# File 'lib/fluent/plugin/output.rb', line 732

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

#validate_keys! ⇒ Object



767
768
769
770
771
772
773
774
775
776
777
778
# File 'lib/fluent/plugin/output.rb', line 767

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



756
757
758
759
760
761
762
763
764
765
# File 'lib/fluent/plugin/output.rb', line 756

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



740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# File 'lib/fluent/plugin/output.rb', line 740

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