netdisco 0.0.2 → 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/{LICENSE.txt → LICENSE} +6 -6
- data/README.md +1 -1
- 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 +9 -9
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/{LICENSE.txt → LICENSE}
RENAMED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
1
|
+
MIT License
|
2
2
|
|
3
|
-
Copyright (c) 2022 WENWU
|
3
|
+
Copyright (c) 2022 WENWU YAN
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
9
|
copies of the Software, and to permit persons to whom the Software is
|
10
10
|
furnished to do so, subject to the following conditions:
|
11
11
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
14
|
|
15
15
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
16
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
17
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
18
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -103,7 +103,7 @@ push git commits and the created tag, and push the `.gem` file to [rubygems.org]
|
|
103
103
|
|
104
104
|
## Contributing
|
105
105
|
|
106
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
106
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ciscolive/netdisco-ruby. This project is intended
|
107
107
|
to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
|
108
108
|
the [code of conduct](https://github.com/ciscolive/netdisco-ruby/blob/main/CODE_OF_CONDUCT.md).
|
109
109
|
|
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,14 +1,14 @@
|
|
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
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: snmp
|
@@ -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
|
@@ -62,7 +62,7 @@ extra_rdoc_files: []
|
|
62
62
|
files:
|
63
63
|
- CHANGELOG.md
|
64
64
|
- CODE_OF_CONDUCT.md
|
65
|
-
- LICENSE
|
65
|
+
- LICENSE
|
66
66
|
- README.md
|
67
67
|
- Rakefile
|
68
68
|
- bin/netdisco
|
@@ -85,8 +85,8 @@ licenses:
|
|
85
85
|
- MIT
|
86
86
|
metadata:
|
87
87
|
homepage_uri: https://github.com/ciscolive/netdisco-ruby
|
88
|
-
source_code_uri: https://github.com/ciscolive/
|
89
|
-
changelog_uri: https://github.com/ciscolive/
|
88
|
+
source_code_uri: https://github.com/ciscolive/netdisco-ruby
|
89
|
+
changelog_uri: https://github.com/ciscolive/netdisco-ruby/blob/main/README.md
|
90
90
|
post_install_message:
|
91
91
|
rdoc_options: []
|
92
92
|
require_paths:
|