Class: Fluent::Plugin::OuiFilter
- Inherits:
-
Filter
- Object
- Filter
- Fluent::Plugin::OuiFilter
- Defined in:
- lib/fluent/plugin/filter_oui.rb
Instance Method Summary collapse
Instance Method Details
#configure(conf) ⇒ Object
13 14 15 16 17 |
# File 'lib/fluent/plugin/filter_oui.rb', line 13 def configure(conf) super @remove_prefix = Regexp.new("^#{Regexp.escape(remove_prefix)}\.?") unless conf['remove_prefix'].nil? @key_prefix = @mac_address + "_" + @key_prefix end |
#filter_stream(tag, es) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/fluent/plugin/filter_oui.rb', line 19 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] = getouiname(record[@mac_address]) rescue nil end new_es.add(time, record) end return new_es end |
#getouiname(macaddress) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/fluent/plugin/filter_oui.rb', line 33 def getouiname(macaddress) macaddress = macaddress.gsub(/[0-9a-fA-F:]{1,8}$/, '') macaddress = macaddress.gsub(/:/, '') macaddress = macaddress.upcase CSV.open(@database_path,"r") do |csv| csv.each do |row| if row[0] == macaddress return row[1] end end end end |