Class: Fluent::Plugin::ProtocolsFilter

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

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



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

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

#filter(tag, es) ⇒ Object



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

def filter(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[@key_port].nil?
      record[@key_prefix] = getprotocolname(record[@key_port], record[@key_proto]) rescue nil
    end
      new_es.add(time, record)
  end
  return new_es
end

#getprotocolname(port, protocol) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/fluent/plugin/filter_protocols.rb', line 34

def getprotocolname(port, protocol)
  CSV.open(@database_path,"r") do |csv|
    csv.each do |row|
      if row[1] == port
        if row[2] == protocol
          return row[0]
        end
      end
    end
  end
end