Class: Fluent::Plugin::OuiFilter

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

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



14
15
16
17
18
19
# File 'lib/fluent/plugin/filter_oui.rb', line 14

def configure(conf)
  super
    @remove_prefix = Regexp.new("^#{Regexp.escape(remove_prefix)}\.?") unless conf['remove_prefix'].nil?
    @key_prefix_vendor    = @mac_address + "_" + @key_prefix_vendor
    @key_prefix_oui       = @mac_address + "_" + @key_prefix_oui
end

#filter_stream(tag, es) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/fluent/plugin/filter_oui.rb', line 21

def filter_stream(tag, es)
  new_es = Fluent::MultiEventStream.new
  tag = tag.sub(@remove_prefix, '') if @remove_prefix
  tag = (@add_prefix + '.' + tag) if @add_prefix

    es.each do |time, record|
      unless record[@mac_address].nil?
        record[@key_prefix_oui]    = getoui(record[@mac_address]) rescue nil
        record[@key_prefix_vendor] = getouiname(getoui(record[@mac_address])) rescue nil
      end
        new_es.add(time, record)
    end
    return new_es
end

#getoui(macaddress) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/fluent/plugin/filter_oui.rb', line 36

def getoui(macaddress)
  macaddress = macaddress.gsub(/[0-9a-fA-F:]{1,8}$/, '')
  macaddress = macaddress.gsub(/:/, '')
  macaddress = macaddress.upcase

  return macaddress
end

#getouiname(ouiaddress) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/fluent/plugin/filter_oui.rb', line 44

def getouiname(ouiaddress)
  CSV.open(@database_path,"r") do |csv|
    csv.each do |row|
      if row[0] == macaddress
        return row[1]
      end
    end
  end
end