Class: Fluent::Plugin::NetflowParser

Inherits:
Parser
  • Object
show all
Defined in:
lib/fluent/plugin/parser_netflow.rb,
lib/fluent/plugin/vash.rb,
lib/fluent/plugin/netflow_records.rb

Overview

port from logstash’s netflow parser

Defined Under Namespace

Classes: Header, IP4Addr, IP6Addr, MacAddr, MplsLabel, Netflow5PDU, Netflow9PDU, OptionFlowset, TemplateFlowset, Vash

Instance Method Summary collapse

Instance Method Details

#call(payload, host = nil, &block) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/fluent/plugin/parser_netflow.rb', line 59

def call(payload, host=nil, &block)
  version,_ = payload[0,2].unpack('n')
  case version
  when 5
    forV5(payload, block)
  when 9
    # TODO: implement forV9
    pdu = Netflow9PDU.read(payload)
    handle_v9(host, pdu, block)
  else
    $log.warn "Unsupported Netflow version v#{version}: #{version.class}"
  end
end

#configure(conf) ⇒ Object



25
26
27
28
29
30
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
# File 'lib/fluent/plugin/parser_netflow.rb', line 25

def configure(conf)
  super

  @templates = Vash.new()
  @samplers_v9 = Vash.new()
  # Path to default Netflow v9 field definitions
  filename = File.expand_path('../netflow_fields.yaml', __FILE__)

  begin
    @template_fields = YAML.load_file(filename)
  rescue => e
    raise Fluent::ConfigError, "Bad syntax in definitions file #{filename}, error_class = #{e.class.name}, error = #{e.message}"
  end

  # Allow the user to augment/override/rename the supported Netflow fields
  if @definitions
    raise Fluent::ConfigError, "definitions file #{@definitions} doesn't exist" unless File.exist?(@definitions)
    begin
      template_fields_custom = YAML.load_file(@definitions)
      if template_fields_custom.first.last.is_a?(Array) # compatibility for older definition files
        @template_fields['option'].merge!(template_fields_custom)
      else
        @template_fields.each do |key, _|
          if template_fields_custom.key?(key)
            @template_fields[key].merge!(template_fields_custom[key])
          end
        end
      end
    rescue => e
      raise Fluent::ConfigError, "Bad syntax in definitions file #{@definitions}, error_class = #{e.class.name}, error = #{e.message}"
    end
  end
end