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
114 115 116 |
# File 'app/models/concerns/fluentd/setting/plugin_config.rb', line 114 def config_element(name = 'test', argument = '', params = {}, elements = []) Fluent::Config::Element.new(name, argument, params, elements) end |
#parse_attributes(attributes) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/models/concerns/fluentd/setting/plugin_config.rb', line 73 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 elements.concat(_elements) end params = params.to_h if plugin_type == "filter" && plugin_name == "record_transformer" record_params = {} params.delete("record").lines.each do |line| k, v = line.split(" ", 2) record_params[k] = v end elements << config_element("record", "", record_params, []) end attrs = params.reject do |key, value| skip?(key.to_sym, value) end return attrs, elements end |
#skip?(key, value) ⇒ Boolean
118 119 120 121 122 123 124 125 |
# File 'app/models/concerns/fluentd/setting/plugin_config.rb', line 118 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
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/concerns/fluentd/setting/plugin_config.rb', line 26 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") label = _attributes.delete("label") if plugin_type == "input" _attributes["@label"] = label end argument = case plugin_type when "output", "filter", "buffer" _attributes.delete(self._argument_name.to_s) || "" else "" end attrs, elements = parse_attributes(_attributes) case plugin_type when "output", "filter" # e is <match> or <filter> e = config_element(name, argument, attrs, elements) if label.blank? e else config_element("label", label, {}, [e]) end else config_element(name, argument, attrs, elements) end end |
#validate_configuration ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/concerns/fluentd/setting/plugin_config.rb', line 10 def validate_configuration original_log = $log $log = DummyLogger.logger full_config = to_config.to_s config = if full_config.start_with?("<label ") full_config.lines[2..-3].join else full_config.lines[1..-2].join end self.class.create_driver(config) rescue Fluent::ConfigError => ex errors.add(:base, :invalid, message: ex.) ensure $log = original_log end |