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)


610
611
612
613
614
615
616
# File 'lib/fluent/plugin/output.rb', line 610

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.



608
609
610
# File 'lib/fluent/plugin/output.rb', line 608

def argument
  @argument
end

#nameObject (readonly)

Returns the value of attribute name.



608
609
610
# File 'lib/fluent/plugin/output.rb', line 608

def name
  @name
end

#stringObject (readonly)

Returns the value of attribute string.



608
609
610
# File 'lib/fluent/plugin/output.rb', line 608

def string
  @string
end

#typeObject (readonly)

Returns the value of attribute type.



608
609
610
# File 'lib/fluent/plugin/output.rb', line 608

def type
  @type
end

Instance Method Details

#keys?Boolean

Returns:

  • (Boolean)


626
627
628
# File 'lib/fluent/plugin/output.rb', line 626

def keys?
  @type == :keys
end

#tag?Boolean

Returns:

  • (Boolean)


622
623
624
# File 'lib/fluent/plugin/output.rb', line 622

def tag?
  @type == :tag
end

#time?Boolean

Returns:

  • (Boolean)


618
619
620
# File 'lib/fluent/plugin/output.rb', line 618

def time?
  @type == :time
end

#validate!Object



630
631
632
633
634
635
636
# File 'lib/fluent/plugin/output.rb', line 630

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

#validate_keys!Object



665
666
667
668
669
670
671
672
673
674
675
676
# File 'lib/fluent/plugin/output.rb', line 665

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



654
655
656
657
658
659
660
661
662
663
# File 'lib/fluent/plugin/output.rb', line 654

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



638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
# File 'lib/fluent/plugin/output.rb', line 638

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