netdisco 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/netdisco/cli.rb +1 -0
- data/lib/netdisco/config.rb +9 -7
- data/lib/netdisco/dns.rb +4 -4
- data/lib/netdisco/method/lldp.rb +1 -1
- data/lib/netdisco/method/xdp.rb +1 -0
- data/lib/netdisco/output.rb +6 -4
- data/lib/netdisco/snmp.rb +4 -2
- data/lib/netdisco/version.rb +1 -1
- data/lib/netdisco.rb +0 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 717c023a9db51e3af00801112bbeaf47ab48159b98db46932bfd03243fcd5965
|
4
|
+
data.tar.gz: 5c871ee533134fd8e9e6e840c2cb6b598b031b013979247ef529d1565d2cc7ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f2bdf61addfe71f2bdcdeb6b0728ae36fc9453f9edcce7e74c0c158bcf8bdcb4223ca8df25967c9ebfbfaaf65b2aebe7b7ba0f4a55e27bb1e946d95e49670e7
|
7
|
+
data.tar.gz: bfdabe4b30c8e3e5867b42ab9f6af9efa1748df080ed09cae4c37deef316086e72808a3bffc420152031fa0238dcc23fac133f864b0061e8e6b3cd5b706d63ee
|
data/lib/netdisco/cli.rb
CHANGED
data/lib/netdisco/config.rb
CHANGED
@@ -9,14 +9,14 @@ class Netdisco
|
|
9
9
|
|
10
10
|
# 设置默认参数
|
11
11
|
CONFIG.default.use = %w(LLDP CDP)
|
12
|
-
CONFIG.default.poll = %w
|
12
|
+
CONFIG.default.poll = %w(192.168.8.0/24 10.250.8.0/24)
|
13
13
|
CONFIG.default.snmp.community = "cisco"
|
14
14
|
CONFIG.default.snmp.timeout = 15
|
15
15
|
CONFIG.default.snmp.retries = 1
|
16
16
|
CONFIG.default.snmp.bulkrows = 30 # 1500B packet should fit about 50 :cdpCacheAddress rows
|
17
17
|
CONFIG.default.dot.bothlinks = false # keep both a-b and b-a links
|
18
18
|
CONFIG.default.dot.linklabels = true # label link with interface names
|
19
|
-
CONFIG.default.dot.color = [# regexp of host => color
|
19
|
+
CONFIG.default.dot.color = [ # regexp of host => color
|
20
20
|
%w[cpe gold],
|
21
21
|
%w[-sw blue],
|
22
22
|
%w[-pe red],
|
@@ -25,18 +25,20 @@ class Netdisco
|
|
25
25
|
CONFIG.default.dns.afi = nil # could be 'ipv4' or 'ipv6'
|
26
26
|
CONFIG.default.log = "STDERR"
|
27
27
|
CONFIG.default.debug = true
|
28
|
-
CONFIG.default.name_map = [# regexp match+sub of hostname (needed for LLDP)
|
28
|
+
CONFIG.default.name_map = [ # regexp match+sub of hostname (needed for LLDP)
|
29
29
|
['-re\d+', ""],
|
30
30
|
["^KILLME(.*(?<!mojo.local)$)", '\1.mojo.local'], # adds missing domain name
|
31
31
|
]
|
32
32
|
# 加载配置并设置对应常量
|
33
33
|
CONFIG.load
|
34
34
|
CFG = CONFIG.cfg
|
35
|
+
|
35
36
|
# 设置项目日志参数
|
36
|
-
log
|
37
|
-
log
|
38
|
-
log
|
39
|
-
Log
|
37
|
+
log = CFG.log
|
38
|
+
log = STDERR if log == "STDERR"
|
39
|
+
log = STDOUT if log == "STDOUT"
|
40
|
+
Log = Logger.new log
|
41
|
+
|
40
42
|
Log.level = Logger::INFO
|
41
43
|
Log.level = Logger::DEBUG if CFG.debug
|
42
44
|
end
|
data/lib/netdisco/dns.rb
CHANGED
@@ -26,8 +26,8 @@ class Netdisco
|
|
26
26
|
else
|
27
27
|
@cache_ip[name] = Resolv.getaddress name
|
28
28
|
end
|
29
|
-
rescue =>
|
30
|
-
Log.debug "DNS resolution for '#{name}' raised error '#{
|
29
|
+
rescue StandardError => e
|
30
|
+
Log.debug "DNS resolution for '#{name}' raised error '#{e.class}' with message '#{e.message}'"
|
31
31
|
nil
|
32
32
|
end
|
33
33
|
end
|
@@ -42,8 +42,8 @@ class Netdisco
|
|
42
42
|
else
|
43
43
|
begin
|
44
44
|
@cache_name[ip] = Resolv.getname ip
|
45
|
-
rescue =>
|
46
|
-
Log.debug "DNS resolution for '#{ip}' raised error '#{
|
45
|
+
rescue StoreError => e
|
46
|
+
Log.debug "DNS resolution for '#{ip}' raised error '#{e.class}' with message '#{e.message}'"
|
47
47
|
@cache_name[ip] = ip
|
48
48
|
end
|
49
49
|
end
|
data/lib/netdisco/method/lldp.rb
CHANGED
@@ -37,7 +37,7 @@ class Netdisco
|
|
37
37
|
peer.oid = get_oid_hash peer_id
|
38
38
|
ip = @mib.by_partial(OID[:lldpRemManAddrIfSubtype], peer_id)
|
39
39
|
peer.raw_ip = ip.oid[-4..-1].join(".") if ip # FIXME: IPv4 specific
|
40
|
-
peer.raw_ip
|
40
|
+
peer.raw_ip ||= "192.0.2.255" # sometimes we can't fnd any IP (EX2200 talking Arista found)
|
41
41
|
peer.raw_name = @mib[OID[:lldpRemSysName], peer_id].value
|
42
42
|
peer.ip = get_ip(peer.raw_ip, peer.raw_name)
|
43
43
|
peer.dst = @mib[OID[:lldpRemPortId], peer_id].value
|
data/lib/netdisco/method/xdp.rb
CHANGED
data/lib/netdisco/output.rb
CHANGED
@@ -75,20 +75,22 @@ class Netdisco
|
|
75
75
|
def to_hash
|
76
76
|
require "pp"
|
77
77
|
out = ""
|
78
|
-
PP.pp
|
78
|
+
PP.pp(to_h, out)
|
79
79
|
out
|
80
80
|
end
|
81
81
|
|
82
|
-
# @return [String] yaml of hosts and peers found
|
82
|
+
# @return [String, Instance] yaml of hosts and peers found
|
83
83
|
def to_yaml
|
84
84
|
require "yaml"
|
85
|
-
|
85
|
+
File.open("./neighbors.yml", "w") { |file| file.write to_h.to_yaml }
|
86
|
+
YAML.dump(to_h)
|
86
87
|
end
|
87
88
|
|
88
89
|
# @return [String] json of hosts and peers found
|
89
90
|
def to_json
|
90
91
|
require "json"
|
91
|
-
JSON.
|
92
|
+
JSON.generate(to_h)
|
93
|
+
# JSON.pretty_generate to_h
|
92
94
|
end
|
93
95
|
end
|
94
96
|
end
|
data/lib/netdisco/snmp.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "snmp"
|
2
4
|
|
3
5
|
class Netdisco
|
@@ -74,8 +76,8 @@ class Netdisco
|
|
74
76
|
private
|
75
77
|
def snmp(method, *args)
|
76
78
|
@snmp.send method, *args
|
77
|
-
rescue ::SNMP::RequestTimeout, Errno::EACCES =>
|
78
|
-
msg = "host '#{@host}' raised '#{
|
79
|
+
rescue ::SNMP::RequestTimeout, Errno::EACCES => e
|
80
|
+
msg = "host '#{@host}' raised '#{e.class}' with message '#{e.message}' for method '#{method}' with args '#{args}'"
|
79
81
|
Log.warn msg
|
80
82
|
raise NoResponse, msg
|
81
83
|
end
|
data/lib/netdisco/version.rb
CHANGED
data/lib/netdisco.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netdisco
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- WENWU.YAN
|
@@ -42,16 +42,16 @@ dependencies:
|
|
42
42
|
name: strada
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.0.
|
47
|
+
version: 0.0.3
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.0.
|
54
|
+
version: 0.0.3
|
55
55
|
description: Netdisco is working for network snmp discovery
|
56
56
|
email:
|
57
57
|
- careline@foxmail.com
|