netdisco 0.0.3 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f248866c4d078dcd262c82797f0e223bae293298f70227c3a31dda566f2a599
4
- data.tar.gz: acd07c7a195df2cd699ec4a1d5b9a09758e8f76d36281326e82ac72d0ac07cbc
3
+ metadata.gz: 4c91ccb28a783f01a278330f992be27b4140dcf51e33641ce5c816dad23bf1ec
4
+ data.tar.gz: 8213e835413e5c911d6e0517f3fe1ae280213106ca6f731286af2d2fb88288ef
5
5
  SHA512:
6
- metadata.gz: 5858604f9f9ba1cae49b8b5ff306745454f0380bcee6356e1ca4f1a92a91ae616bc54ee960c8bd35fc0e15e5e335296fbf05bba5d3101e5b74bf5b380226ac3c
7
- data.tar.gz: 10456d87f6a2e838e555f5fa1e9fb024ff67566694fb3dbaff993d6b1bb686934b443075db38ef8fbd64e498b8c09dddcf9031f0c4510041a9e89cb9ca46cd66
6
+ metadata.gz: c880e02f87cc3e7865ed0d7cc7b40bafc3ddcb210c14b032cf45e4e95b254eb8cc3caaa61b4e2c4b1d0406c5aa81b211efdaec359c2b2aefe1121fc8dc7cc3b4
7
+ data.tar.gz: 929893de09c7024f630978ddf669d2b4f05cf5614e27de68226d7c8fa64ffdcb40bfa86e16210061625f2171c6b57f314925de535805572bba715106780c59fa
@@ -1,6 +1,6 @@
1
- The MIT License (MIT)
1
+ MIT License
2
2
 
3
- Copyright (c) 2022 WENWU.YAN
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
- all copies or substantial portions of the Software.
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
- THE SOFTWARE.
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/lib/netdisco/cli.rb CHANGED
@@ -11,6 +11,7 @@ class Netdisco
11
11
 
12
12
  # 网络邻居发现入口函数
13
13
  def run
14
+ Log.debug "Running Netdisco.new.discover ..."
14
15
  output = Netdisco.new.discover @host
15
16
 
16
17
  # 邻居关系发现后修正处理逻辑钩子函数
@@ -9,14 +9,14 @@ class Netdisco
9
9
 
10
10
  # 设置默认参数
11
11
  CONFIG.default.use = %w(LLDP CDP)
12
- CONFIG.default.poll = %w[192.168.8.0/24]
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 = CFG.log
37
- log = STDERR if log == "STDERR"
38
- log = STDOUT if log == "STDOUT"
39
- Log = Logger.new 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 => error
30
- Log.debug "DNS resolution for '#{name}' raised error '#{error.class}' with message '#{error.message}'"
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 => error
46
- Log.debug "DNS resolution for '#{ip}' raised error '#{error.class}' with message '#{error.message}'"
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
@@ -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 ||= "192.0.2.255" # sometimes we can't fnd any IP (EX2200 talking Arista found)
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
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "../snmp"
4
+ # require "logger"
4
5
 
5
6
  class Netdisco
6
7
  class XDP
@@ -75,20 +75,22 @@ class Netdisco
75
75
  def to_hash
76
76
  require "pp"
77
77
  out = ""
78
- PP.pp to_h, out
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
- YAML.dump to_h
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.pretty_generate to_h
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 => error
78
- msg = "host '#{@host}' raised '#{error.class}' with message '#{error.message}' for method '#{method}' with args '#{args}'"
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Netdisco
4
- VERSION = "0.0.3"
4
+ VERSION = "0.0.6"
5
5
  end
data/lib/netdisco.rb CHANGED
@@ -59,7 +59,6 @@ class Netdisco
59
59
  # 第一步获取设备的邻居关系,同时将邻居关系缓存下来
60
60
  @hosts[host] = peers = neighbors(host)
61
61
  # 第二步遍历邻居的邻居关系
62
- require "pp"; PP.pp @hosts[host]
63
62
  peers.each do |peer|
64
63
  next if @hosts.has_key? peer.ip
65
64
  next unless @poll.include? peer.ip
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.3
4
+ version: 0.0.6
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-16 00:00:00.000000000 Z
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.2
47
+ version: 0.0.5
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.2
54
+ version: 0.0.5
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.txt
65
+ - LICENSE
66
66
  - README.md
67
67
  - Rakefile
68
68
  - bin/netdisco