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, logger) ⇒ SNMPInterfaceResolver

Returns a new instance of SNMPInterfaceResolver.



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

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

Instance Method Details

#get_interface(host, ifIndex) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/logstash/codecs/snmp/interface_resolver.rb', line 11

def get_interface(host, ifIndex)
  unless @cacheSnmpInterface.key?("#{host}-#{ifIndex}")
    begin
      SNMP::Manager.open(:host => host, :community => @community, :version => :SNMPv2c) do |manager|
        @cacheSnmpInterface["#{host}-#{ifIndex}"] = manager.get_value("ifDescr.#{ifIndex}").to_s
      end
    rescue SNMP::RequestTimeout => e
      # This is not the best but it avoids loosing lots of events when facing
      # request timeout exception with input thread restarting.
      # Then we can easily detect this on the log or on elasticsearch
      # searching for SnmpRequestTimeout descr fields
      @logger.error("Timeout requesting description on #{host} of index #{ifIndex}: #{e.message}")
      return "SnmpRequestTimeout"
    end
  end
  return @cacheSnmpInterface["#{host}-#{ifIndex}"]
end