Class: Fluent::Auditify::Plugin::YamlConf

Inherits:
Conf
  • Object
show all
Includes:
YamlConfNoErrorParser, YamlConfNoMethodErrorParser, YamlConfSyntaxErrorParser
Defined in:
lib/fluent/auditify/plugin/conf_yaml.rb

Instance Method Summary collapse

Methods included from YamlConfSyntaxErrorParser

#detect_wrong_at_directive_syntax

Methods included from YamlConfNoMethodErrorParser

#detect_broken_config_param_indent_fallback, #detect_wrong_config_element_fallback

Methods included from YamlConfNoErrorParser

#detect_no_match, #detect_no_source, #detect_wrong_directive

Constructor Details

#initializeYamlConf

Returns a new instance of YamlConf.



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

def initialize
  super
end

Instance Method Details

#fallback_detector?(method) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
# File 'lib/fluent/auditify/plugin/conf_yaml.rb', line 68

def fallback_detector?(method)
  method.to_s.start_with?('detect_') and
    method.to_s.end_with?('_fallback')
end

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



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
# File 'lib/fluent/auditify/plugin/conf_yaml.rb', line 31

def parse(conf, options={})
  begin
    root = Fluent::Config::YamlParser.parse(conf)
    self.methods.each do |method|
      if standard_detector?(method)
        log.debug { "#{self.class}\##{method}" }
        send(method, root, conf)
      end
    end
  rescue NoMethodError => e
    # contains something weird indentation, need to handle exception
    log.debug { "failed to parse #{conf} with: #{e.message}" }
    yaml = YAML.load(file_get_contents(conf))
    self.methods.each do |method|
      if fallback_detector?(method)
        log.debug { "#{self.class}\##{method}" }
        send(method, yaml, conf)
      end
    end
  rescue Psych::SyntaxError => e
    # YAML syntax error
    log.debug { "failed to parse #{conf} with: #{e.message}" }
    self.methods.each do |method|
      if syntax_detector?(method)
        log.debug { "#{self.class}\##{method}" }
        send(method, conf)
      end
    end
  end
end

#standard_detector?(method) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
65
66
# File 'lib/fluent/auditify/plugin/conf_yaml.rb', line 62

def standard_detector?(method)
  method.to_s.start_with?('detect_') and
    not method.to_s.end_with?('_fallback') and
    not method.to_s.end_with?('_syntax')
end

#supported_file_extension?Boolean

Returns:

  • (Boolean)


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

def supported_file_extension?
  [:yaml, :yml]
end

#supported_platform?Boolean

Returns:

  • (Boolean)


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

def supported_platform?
  :any
end

#syntax_detector?(method) ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
76
# File 'lib/fluent/auditify/plugin/conf_yaml.rb', line 73

def syntax_detector?(method)
  method.to_s.start_with?('detect_') and
    method.to_s.end_with?('_syntax')
end

#unknown_directive?(root) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/fluent/auditify/plugin/conf_yaml.rb', line 78

def unknown_directive?(root)
  root.elements.empty?
end