Class: Fluent::Auditify::Plugin::ConfPluginParams

Inherits:
Conf
  • Object
show all
Defined in:
lib/fluent/auditify/plugin/conf_plugin_params.rb

Instance Attribute Summary

Attributes inherited from Base

#log

Instance Method Summary collapse

Methods inherited from Conf

#artifact, #conf?, #disabled?, #file_get_contents, #file_readlines_each, #guilty, #plugin_defs, #polish, #read_with_include_directive, #surround_text, #yaml?

Constructor Details

#initializeConfPluginParams



27
28
29
# File 'lib/fluent/auditify/plugin/conf_plugin_params.rb', line 27

def initialize
  super
end

Instance Method Details

#parse(conf_path, options = {}) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/fluent/auditify/plugin/conf_plugin_params.rb', line 31

def parse(conf_path, options={})
  @options.merge!(options) unless options.empty?
  if conf_path.end_with?('.yaml', '.yml')
  else conf_path.end_with?('.conf')
    process_conf(conf_path, options)
  end
end

#process_conf(conf_path, options = {}) ⇒ Object



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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/fluent/auditify/plugin/conf_plugin_params.rb', line 39

def process_conf(conf_path, options={})
  content = file_get_contents(conf_path)
  @parser = Fluent::Auditify::Parser::V1ConfigParser.new
  object = @parser.parse(content)

  root = Fluent::Config::V1Parser.parse(content, conf_path)
  nth_source = 0
  root.elements.collect do |element|
    case element.name
    when 'source'
      # parse
      type = 'input'
      plugin_name = element['@type']
      plugin_spec = plugin_defs(type, plugin_name)
      element.keys.each do |param|
        unless plugin_spec.key?(param)
          if @options[:config_version] == :v1
            next if param == '@type'
            source = @parser.find_nth_element('source', nth: nth_source + 1, elements: object)
            source[:body].each do |pair|
              if pair[:name] == 'type' and pair[:value] == plugin_name
                num = pair[:value].line_and_column.first
                lines = file_get_contents(conf_path, lines: true)
                guilty(:warn, "<#{param}> is deprecated, use @type instead",
                       {path: conf_path, line: num,
                        content: lines[num],
                        suggest: lines[num - 1][:content].sub(/type/, '@type'),
                        category: :params, plugin: :params})
              elsif pair[:name] == param and not pair.key?(:value)
                # only key (use default value)
                guilty(:error, "unknown <#{param}> parameter", {path: conf_path, category: :params, plugin: :params})
              end
            end
            next
          elsif options[:config_version] == :v0
            next if param == 'type'
            guilty(:error, "unknown <#{param}> parameter", {path: conf_path, category: :params, plugin: :params})
            next
          end
        end
      end
      # directive such as <parse>
      if Gem::Version.new(Fluent::VERSION) >= Gem::Version.new('1.7.0')
        # Until Fluentd < 1.7.x, spec does not contain supported section
        element.elements.each do |section|
          unless plugin_spec.key?(section.name)
            guilty(:error, "unknown <#{section.name}> directive", {path: conf_path, category: :params, plugin: :params})
          end
        end
      end
    end
  end
end

#supported_file_extension?Boolean



23
24
25
# File 'lib/fluent/auditify/plugin/conf_plugin_params.rb', line 23

def supported_file_extension?
  [:conf, :yaml, :yml]
end

#supported_platform?Boolean



19
20
21
# File 'lib/fluent/auditify/plugin/conf_plugin_params.rb', line 19

def supported_platform?
  :any
end