Class: Fluent::NorikraPlugin::ConfigSection

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/norikra/config_section.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(section, enable_auto_query = true) ⇒ ConfigSection

Returns a new instance of ConfigSection.



7
8
9
10
11
12
13
14
15
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
43
44
45
46
47
# File 'lib/fluent/plugin/norikra/config_section.rb', line 7

def initialize(section, enable_auto_query=true)
  @target = nil
  @target_matcher = nil
  if section.name == 'default'
    # nil
  elsif section.name == 'target'
    # unescaped target name (tag style with dots)
    @target = section.arg
    @target_matcher = Fluent::GlobMatchPattern.new(section.arg)
  else
    raise ArgumentError, "invalid section for this class, #{section.name}: ConfigSection"
  end

  @auto_field = Fluent::Config.bool_value(section['auto_field'])
  @time_key = section['time_key']
  @escape_fieldname = Fluent::Config.bool_value(section['escape_fieldname'])

  @filter_params = {
    :include => section['include'],
    :include_regexp => section['include_regexp'],
    :exclude => section['exclude'],
    :exclude_regexp => section['exclude_regexp']
  }
  @field_definitions = {
    :string => (section['field_string'] || '').split(','),
    :boolean => (section['field_boolean'] || '').split(','),
    :integer => (section['field_integer'] || '').split(','),
    :float => (section['field_float'] || '').split(','),
  }

  @query_generators = []
  section.elements.each do |element|
    if element.name == 'query' && enable_auto_query
      opt = {}
      if element.has_key?('fetch_interval')
        opt['fetch_interval'] = Fluent::Config.time_value(element['fetch_interval'])
      end
      @query_generators.push(QueryGenerator.new(element['name'], element['group'], element['expression'], element['tag'], opt))
    end
  end
end

Instance Attribute Details

#auto_fieldObject

Returns the value of attribute auto_field.



4
5
6
# File 'lib/fluent/plugin/norikra/config_section.rb', line 4

def auto_field
  @auto_field
end

#escape_fieldnameObject

Returns the value of attribute escape_fieldname.



4
5
6
# File 'lib/fluent/plugin/norikra/config_section.rb', line 4

def escape_fieldname
  @escape_fieldname
end

#field_definitionsObject

Returns the value of attribute field_definitions.



5
6
7
# File 'lib/fluent/plugin/norikra/config_section.rb', line 5

def field_definitions
  @field_definitions
end

#filter_paramsObject

Returns the value of attribute filter_params.



5
6
7
# File 'lib/fluent/plugin/norikra/config_section.rb', line 5

def filter_params
  @filter_params
end

#query_generatorsObject

Returns the value of attribute query_generators.



5
6
7
# File 'lib/fluent/plugin/norikra/config_section.rb', line 5

def query_generators
  @query_generators
end

#targetObject

Returns the value of attribute target.



3
4
5
# File 'lib/fluent/plugin/norikra/config_section.rb', line 3

def target
  @target
end

#target_matcherObject

Returns the value of attribute target_matcher.



3
4
5
# File 'lib/fluent/plugin/norikra/config_section.rb', line 3

def target_matcher
  @target_matcher
end

#time_keyObject

Returns the value of attribute time_key.



4
5
6
# File 'lib/fluent/plugin/norikra/config_section.rb', line 4

def time_key
  @time_key
end

Instance Method Details

#+(other) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/fluent/plugin/norikra/config_section.rb', line 49

def +(other)
  if other.nil?
    other = self.class.new(Fluent::Config::Element.new('target', 'dummy', {}, []))
  end
  r = self.class.new(Fluent::Config::Element.new('target', (other.target ? other.target : self.target), {}, []))
  r.auto_field = (other.auto_field.nil? ? self.auto_field : other.auto_field)
  r.time_key = other.time_key || self.time_key

  others_filter = {}
  other.filter_params.keys.each do |k|
    others_filter[k] = other.filter_params[k] if other.filter_params[k]
  end
  r.filter_params = self.filter_params.merge(others_filter)
  r.field_definitions = {
    :string => self.field_definitions[:string] + other.field_definitions[:string],
    :boolean => self.field_definitions[:boolean] + other.field_definitions[:boolean],
    :integer => self.field_definitions[:integer] + other.field_definitions[:integer],
    :float => self.field_definitions[:float] + other.field_definitions[:float],
  }
  r.query_generators = self.query_generators + other.query_generators
  r
end