Class: SNMPInterfaceResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/codecs/snmp/interface_resolver.rb

Instance Method Summary collapse

Constructor Details

#initialize(community, cache_size, cache_ttl) ⇒ SNMPInterfaceResolver

Returns a new instance of SNMPInterfaceResolver.



5
6
7
8
# File 'lib/logstash/codecs/snmp/interface_resolver.rb', line 5

def initialize(community, cache_size, cache_ttl)
  @community = community
  @cacheSnmpInterface = LruRedux::TTL::Cache.new(cache_size, cache_ttl)
end

Instance Method Details

#get_interface(host, ifIndex) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/logstash/codecs/snmp/interface_resolver.rb', line 10

def get_interface(host, ifIndex)
  unless @cacheSnmpInterface.key?("#{host}-#{ifIndex}")
    SNMP::Manager.open(:host => host, :community => @community, :version => :SNMPv2c) do |manager|
      response = manager.get("ifDescr.#{ifIndex}")
      response.each_varbind do |vb|
        @cacheSnmpInterface["#{host}-#{ifIndex}"] = vb.value.to_s
      end
    end
  end
  return @cacheSnmpInterface["#{host}-#{ifIndex}"]
end