Class: Fluent::Plugin::Output::PlaceholderValidator
- Inherits:
-
Object
- Object
- Fluent::Plugin::Output::PlaceholderValidator
- Defined in:
- lib/fluent/plugin/output.rb
Instance Attribute Summary collapse
-
#argument ⇒ Object
readonly
Returns the value of attribute argument.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#string ⇒ Object
readonly
Returns the value of attribute string.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, str, type, arg) ⇒ PlaceholderValidator
constructor
A new instance of PlaceholderValidator.
- #keys? ⇒ Boolean
- #tag? ⇒ Boolean
- #time? ⇒ Boolean
- #validate! ⇒ Object
- #validate_keys! ⇒ Object
- #validate_tag! ⇒ Object
- #validate_time! ⇒ Object
Constructor Details
#initialize(name, str, type, arg) ⇒ PlaceholderValidator
Returns a new instance of PlaceholderValidator.
693 694 695 696 697 698 699 |
# File 'lib/fluent/plugin/output.rb', line 693 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.
691 692 693 |
# File 'lib/fluent/plugin/output.rb', line 691 def argument @argument end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
691 692 693 |
# File 'lib/fluent/plugin/output.rb', line 691 def name @name end |
#string ⇒ Object (readonly)
Returns the value of attribute string.
691 692 693 |
# File 'lib/fluent/plugin/output.rb', line 691 def string @string end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
691 692 693 |
# File 'lib/fluent/plugin/output.rb', line 691 def type @type end |
Instance Method Details
#keys? ⇒ Boolean
709 710 711 |
# File 'lib/fluent/plugin/output.rb', line 709 def keys? @type == :keys end |
#tag? ⇒ Boolean
705 706 707 |
# File 'lib/fluent/plugin/output.rb', line 705 def tag? @type == :tag end |
#time? ⇒ Boolean
701 702 703 |
# File 'lib/fluent/plugin/output.rb', line 701 def time? @type == :time end |
#validate! ⇒ Object
713 714 715 716 717 718 719 |
# File 'lib/fluent/plugin/output.rb', line 713 def validate! case @type when :time then validate_time! when :tag then validate_tag! when :keys then validate_keys! end end |
#validate_keys! ⇒ Object
748 749 750 751 752 753 754 755 756 757 758 759 |
# File 'lib/fluent/plugin/output.rb', line 748 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
737 738 739 740 741 742 743 744 745 746 |
# File 'lib/fluent/plugin/output.rb', line 737 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
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 |
# File 'lib/fluent/plugin/output.rb', line 721 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 |