Class: Netdisco::Peer

Inherits:
Object
  • Object
show all
Defined in:
lib/netdisco/peer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePeer

初始化函数



9
10
11
12
13
14
15
16
17
# File 'lib/netdisco/peer.rb', line 9

def initialize
  @ip       = nil # Best guess of system IP
  @name     = nil # Reverse of said IP
  @raw_ip   = nil # IP as seen in polling
  @raw_name = nil # Name as seen in polling
  @src      = nil # SRC/local interface
  @dst      = nil # DST/remote interface
  @oid      = {} # Hash of oids collected
end

Instance Attribute Details

#dstObject

类对象方法属性



6
7
8
# File 'lib/netdisco/peer.rb', line 6

def dst
  @dst
end

#ipObject

类对象方法属性



6
7
8
# File 'lib/netdisco/peer.rb', line 6

def ip
  @ip
end

#oidObject

类对象方法属性



6
7
8
# File 'lib/netdisco/peer.rb', line 6

def oid
  @oid
end

#raw_ipObject

类对象方法属性



6
7
8
# File 'lib/netdisco/peer.rb', line 6

def raw_ip
  @raw_ip
end

#raw_nameObject

类对象方法属性



6
7
8
# File 'lib/netdisco/peer.rb', line 6

def raw_name
  @raw_name
end

#srcObject

类对象方法属性



6
7
8
# File 'lib/netdisco/peer.rb', line 6

def src
  @src
end

Instance Method Details

#nameObject

设置邻居名称



20
21
22
# File 'lib/netdisco/peer.rb', line 20

def name
  @name ||= DNS.getname @ip
end

#to_hObject

将邻居对象转换为 HASH



25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/netdisco/peer.rb', line 25

def to_h
  {
    "ip"        => ip.to_s,
    "name"      => name.to_s,
    "interface" => {
      "source"      => src.to_s,
      "destination" => dst.to_s
    },
    "raw" => {
      "ip"   => raw_ip.to_s,
      "name" => raw_name.to_s
    }
  }
end