Module: Fluentd::Setting::PluginConfig
- Extended by:
- ActiveSupport::Concern
- Included in:
- Plugin
- Defined in:
- app/models/concerns/fluentd/setting/plugin_config.rb
Instance Method Summary collapse
-
#config_element(name = 'test', argument = '', params = {}, elements = []) ⇒ Object
copy from Fluent::Test::Helpers#config_element.
- #parse_attributes(attributes) ⇒ Object
- #skip?(key, value) ⇒ Boolean
- #to_config ⇒ Object
- #validate_configuration ⇒ Object
Instance Method Details
#config_element(name = 'test', argument = '', params = {}, elements = []) ⇒ Object
copy from Fluent::Test::Helpers#config_element
84 85 86 |
# File 'app/models/concerns/fluentd/setting/plugin_config.rb', line 84 def config_element(name = 'test', argument = '', params = {}, elements = []) Fluent::Config::Element.new(name, argument, params, elements) end |
#parse_attributes(attributes) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'app/models/concerns/fluentd/setting/plugin_config.rb', line 53 def parse_attributes(attributes) base_klasses = config_definition.keys sections, params = attributes.partition do |key, _section_attributes| base_klasses.any? do |base_klass| config_definition.dig(base_klass, key.to_sym, :section) || config_definition.dig(key.to_sym, :section) end end elements = [] sections.to_h.each do |key, section_params| next if section_params.blank? section_class = self._sections[key.to_sym] if %w(parse format buffer storage).include?(key) if section_params && section_params.key?("0") section_params["0"] = { "type" => self.attributes["#{key}_type"] }.merge(section_params["0"]) else section_params = { "0" => { "type" => self.attributes["#{key}_type"] } } end end elements = section_params.map do |index, _section_params| section_class.new(_section_params).to_config end.compact end attrs = params.to_h.reject do |key, value| skip?(key.to_sym, value) end return attrs, elements end |
#skip?(key, value) ⇒ Boolean
88 89 90 91 92 93 94 95 |
# File 'app/models/concerns/fluentd/setting/plugin_config.rb', line 88 def skip?(key, value) return true if value.blank? if self._defaults.key?(key) self.class.reformat_value(key, self._defaults[key]) == self.class.reformat_value(key, value) else false end end |
#to_config ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/models/concerns/fluentd/setting/plugin_config.rb', line 21 def to_config name = case plugin_type when "input" "source" when "output" "match" when "filter" "filter" when "parser" "parse" when "formatter" "format" when "buffer" "buffer" when "storage" "storage" end _attributes = attributes.reject do |key, value| %w(parse_type format_type buffer_type storage_type).include?(key.to_s) end _attributes = { "@type" => self.plugin_name }.merge(_attributes) _attributes["@log_level"] = _attributes.delete("log_level") argument = case plugin_type when "output", "filter", "buffer" _attributes.delete(self._argument_name.to_s) || "" else "" end attrs, elements = parse_attributes(_attributes) config_element(name, argument, attrs, elements) end |
#validate_configuration ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'app/models/concerns/fluentd/setting/plugin_config.rb', line 10 def validate_configuration original_log = $log $log = DummyLogger.logger config = to_config.to_s.lines[1..-2].join self.class.create_driver(config) rescue Fluent::ConfigError => ex errors.add(:base, :invalid, message: ex.) ensure $log = original_log end |