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)


538
539
540
541
542
543
544
# File 'lib/fluent/plugin/output.rb', line 538

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.



536
537
538
# File 'lib/fluent/plugin/output.rb', line 536

def argument
  @argument
end

#nameObject (readonly)

Returns the value of attribute name.



536
537
538
# File 'lib/fluent/plugin/output.rb', line 536

def name
  @name
end

#stringObject (readonly)

Returns the value of attribute string.



536
537
538
# File 'lib/fluent/plugin/output.rb', line 536

def string
  @string
end

#typeObject (readonly)

Returns the value of attribute type.



536
537
538
# File 'lib/fluent/plugin/output.rb', line 536

def type
  @type
end

Instance Method Details

#keys?Boolean

Returns:

  • (Boolean)


554
555
556
# File 'lib/fluent/plugin/output.rb', line 554

def keys?
  @type == :keys
end

#tag?Boolean

Returns:

  • (Boolean)


550
551
552
# File 'lib/fluent/plugin/output.rb', line 550

def tag?
  @type == :tag
end

#time?Boolean

Returns:

  • (Boolean)


546
547
548
# File 'lib/fluent/plugin/output.rb', line 546

def time?
  @type == :time
end

#validate!Object



558
559
560
561
562
563
564
# File 'lib/fluent/plugin/output.rb', line 558

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

#validate_keys!Object



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

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}' 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}' has placeholders, but chunk keys doesn't have keys #{not_satisfied.join(',')}"
  end
end

#validate_tag!Object



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

def validate_tag!
  parts = @argument[:parts]
  tagkey = @argument[:tagkey]
  if tagkey && parts.empty?
    raise Fluent::ConfigError, "Parameter '#{@name}' doesn't have tag placeholder"
  end
  if !tagkey && !parts.empty?
    raise Fluent::ConfigError, "Parameter '#{@name}' has tag placeholders, but chunk key 'tag' is not configured"
  end
end

#validate_time!Object



566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
# File 'lib/fluent/plugin/output.rb', line 566

def validate_time!
  sec = @argument[:sec]
  title = @argument[:title]
  example = @argument[:example]
  timekey = @argument[:timekey]
  if !sec && timekey
    raise Fluent::ConfigError, "Parameter '#{name}' doesn't have timestamp placeholders for timekey #{timekey.to_i}"
  end
  if sec && !timekey
    raise Fluent::ConfigError, "Parameter '#{name}' has timestamp placeholders, but chunk key 'time' is not configured"
  end
  if sec && timekey && timekey < sec
    raise Fluent::ConfigError, "Parameter '#{@name}' doesn't have timestamp placeholder for #{title}('#{example}') for timekey #{timekey.to_i}"
  end
end