Class: Fluent::XmlFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/fluent/plugin/filter_xml_simple.rb

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object

Raises:

  • (ConfigError)


12
13
14
15
16
17
18
19
20
# File 'lib/fluent/plugin/filter_xml_simple.rb', line 12

def configure(conf)
  super

  raise ConfigError, "'Fields' is required" if self.fields.nil?

  self.fields = self.fields.split(',')

  raise ConfigError, "'Fields' must contain at least one key" if self.fields.length < 1
end

#filter(tag, time, record) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/fluent/plugin/filter_xml_simple.rb', line 34

def filter(tag, time, record)
  self.fields.each { |field|
    if record.key?(field)
      field_name = field

      if self.field_name_postfix
        field_name = [field, self.field_name_postfix].join '_'
      end

      hash = @parser.parse(record[field])

      if try_convert_times
        hash = convert_times(hash)
      end

      record[field_name] = hash
    end
  }

  record
end

#shutdownObject



28
29
30
31
32
# File 'lib/fluent/plugin/filter_xml_simple.rb', line 28

def shutdown
  super

  @parser = nil
end

#startObject



22
23
24
25
26
# File 'lib/fluent/plugin/filter_xml_simple.rb', line 22

def start
  super

  @parser = Nori.new(:advanced_typecasting => false)
end