# 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 # require "pp"; PP.pp @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"