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)


563
564
565
566
567
568
569
# File 'lib/fluent/plugin/output.rb', line 563

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.



561
562
563
# File 'lib/fluent/plugin/output.rb', line 561

def argument
  @argument
end

#nameObject (readonly)

Returns the value of attribute name.



561
562
563
# File 'lib/fluent/plugin/output.rb', line 561

def name
  @name
end

#stringObject (readonly)

Returns the value of attribute string.



561
562
563
# File 'lib/fluent/plugin/output.rb', line 561

def string
  @string
end

#typeObject (readonly)

Returns the value of attribute type.



561
562
563
# File 'lib/fluent/plugin/output.rb', line 561

def type
  @type
end

Instance Method Details

#keys?Boolean

Returns:

  • (Boolean)


579
580
581
# File 'lib/fluent/plugin/output.rb', line 579

def keys?
  @type == :keys
end

#tag?Boolean

Returns:

  • (Boolean)


575
576
577
# File 'lib/fluent/plugin/output.rb', line 575

def tag?
  @type == :tag
end

#time?Boolean

Returns:

  • (Boolean)


571
572
573
# File 'lib/fluent/plugin/output.rb', line 571

def time?
  @type == :time
end

#validate!Object



583
584
585
586
587
588
589
# File 'lib/fluent/plugin/output.rb', line 583

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

#validate_keys!Object



618
619
620
621
622
623
624
625
626
627
628
629
# File 'lib/fluent/plugin/output.rb', line 618

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



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

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



591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
# File 'lib/fluent/plugin/output.rb', line 591

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