Sha256: c839080d8c2f94bed504c2b56d512d68d2dfb36cc2bb68cc731e44241f2763bc

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

class SNMPwalk

  attr_accessor :switchport
  def initialize(switchips)
    print "Getting switch interface names "
    @switchport = {}
      switchips.each do |switchip|
        switch = Resolv.new.getname(switchip).split(/\./)[0]
        ports = {}

        snmpoutput = `snmpwalk -v2c -c public #{switchip} 1.3.6.1.2.1.2.2.1.2`
        snmpoutput.each_line do |line|
           split = line.split(/\s/)
           port = split[0].split(/\./).last
           if split[3] =~ /GigabitEthernet/
             portname = split[3].scan(/\d+/).join('/')
           else
             portname = split[3]
           end
           hashp = { port => portname }
           ports.merge!(hashp)
        end

        hashs = { switch => ports }
        @switchport.merge!(hashs)
        print "."
      end 
    puts " done."
    @switchport
  end

  def self.mapswitchportname(agent_address,iface)
    if $switchportnames.switchport["#{agent_address}"]["#{iface}"]
      $switchportnames.switchport["#{agent_address}"]["#{iface}"]
    else
      agent_address
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-sflow-0.1.0 lib/sflow/lib/sflow/snmp/iface_names.rb