Module: Fluent::Auditify::Plugin::YamlConfNoMethodErrorParser

Included in:
YamlConf
Defined in:
lib/fluent/auditify/plugin/parse_nomethod.rb

Instance Method Summary collapse

Instance Method Details

#detect_broken_config_param_indent_fallback(yaml, conf) ⇒ Object

config:

- source:
  $type: stdout


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/fluent/auditify/plugin/parse_nomethod.rb', line 16

def detect_broken_config_param_indent_fallback(yaml, conf)
  # source unless ((yaml.keys == ["config"]) or (yaml.keys == ["system", "config"]))
  return unless yaml['config']

  nth = 0
  yaml['config'].each do |element|
    # check source => nil case
    if element.has_key?('source')
      nth += 1
      next if element['source']
    else
      next
    end
    
    # source: and the following parameter must have intent
    count = 0
    file_readlines_each(conf) do |line, i|
      if line.include?('source:')
        count += 1
        if nth == count
          guilty(:error, "source must not be empty. parameter for <source:> indent might be broken",
                 { path: conf, line: i + 1, content: line})
        end
      end
    end
  end
end

#detect_wrong_config_element_fallback(yaml, conf) ⇒ Object

config:

- unknown:
    $type: stdout


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/fluent/auditify/plugin/parse_nomethod.rb', line 49

def detect_wrong_config_element_fallback(yaml, conf)
  yaml['config'].each_with_index do |element, index|
    # Even though indent is correct, unknown element raise exception
    # skip if source exists, and let process to broken config param detector.
    next if element.has_key?('source')
    element.keys.each do |key|
      unless %w(source match filter label).include?(key)
        file_readlines_each(conf) do |line, i|
          if line.include?("#{key}:")
            guilty(:error, "config element must be either source, match, filter and label, not <#{key}>",
                   { path: conf, line: i + 1, content: line})
          end
        end
      end
    end
  end
end