Sha256: 922efaa651ed37588bc44f8b2756d118dd93312a920973062d732c32a96ab082

Contents?: true

Size: 968 Bytes

Versions: 1

Compression:

Stored size: 968 Bytes

Contents

# frozen_string_literal: true

require_relative "../snmp"
# require "logger"

class Netdisco
  class XDP
    # 类对象方法属性
    attr_reader :mib

    # 加载模块方法到类对象
    include NameMap

    # 对象实例化入口函数
    def initialize(host)
      @snmp = SNMP.new host
    end

    # 类属性方法
    # @param [String] host host to query
    # @return [Array(Netdisco::Peer)] neighbor information
    def self.peers(host)
      new(host).poll
    end

    # 轮询设备邻居关系
    def poll
      @mib = @snmp.hashwalk self.class::MIB
      make_peers
    rescue SNMP::NoResponse
      []
    end

    private
      def get_ip(ip, name)
        DNS.getip(name_map(name)) || ip
      end

      def get_oid_hash(peer_id)
        oid_hash = {}
        self.class::OID.each do |name, oid|
          oid_hash[name] = @mib[oid, peer_id]
        end
        oid_hash
      end
  end
end

require_relative "cdp"
require_relative "lldp"

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
netdisco-0.0.8 lib/netdisco/method/xdp.rb