netcrawl 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/netcrawl +0 -0
- data/lib/netcrawl/method/cdp.rb +4 -4
- data/lib/netcrawl/method/lldp.rb +16 -4
- data/lib/netcrawl/snmp.rb +18 -0
- data/netcrawl.gemspec +1 -1
- metadata +4 -5
- data/lib/netcrawl/.cli.rb.swp +0 -0
data/bin/netcrawl
CHANGED
File without changes
|
data/lib/netcrawl/method/cdp.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative '../snmp'
|
2
2
|
class NetCrawl
|
3
3
|
class CDP
|
4
|
+
include NameMap
|
4
5
|
OID = {
|
5
6
|
# http://tools.cisco.com/Support/SNMP/do/BrowseOID.do?local=en&translate=Translate&objectInput=1.3.6.1.4.1.9.9.23.1.2.1.1
|
6
7
|
:cdpCacheAddress => '1.3.6.1.4.1.9.9.23.1.2.1.1.4',
|
@@ -15,9 +16,9 @@ class NetCrawl
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def peers
|
18
|
-
@snmp.
|
19
|
-
|
20
|
-
|
19
|
+
addrs = @snmp.walk2hash(OID[:cdpCacheAddress]) { |vb| vb.as_ip }
|
20
|
+
names = @snmp.walk2hash(OID[:cdpCacheDeviceId]) { |vb| DNS.getip namemap(vb.value) }
|
21
|
+
names.keys.map { |id| names[id] or addrs[id] }.compact
|
21
22
|
rescue SNMP::NoResponse
|
22
23
|
[]
|
23
24
|
end
|
@@ -28,6 +29,5 @@ class NetCrawl
|
|
28
29
|
@snmp = SNMP.new host
|
29
30
|
end
|
30
31
|
|
31
|
-
|
32
32
|
end
|
33
33
|
end
|
data/lib/netcrawl/method/lldp.rb
CHANGED
@@ -4,9 +4,19 @@ class NetCrawl
|
|
4
4
|
include NameMap
|
5
5
|
OID = {
|
6
6
|
# http://standards.ieee.org/getieee802/download/802.1AB-2009.pdf
|
7
|
+
# finding IP address for LLDP neighbour as of JunOS 13.3R1 and IOS 15.0(2)SG8 is not practical
|
8
|
+
# ifsubtype is ifindex but value 0 for JunOS neighbours
|
9
|
+
# ifsubtype is systemportnumber for IOS neighbours (what ever that is)
|
10
|
+
# luckily some IP address is in the OID key itself, while dodgy, better than nothing
|
11
|
+
# in JunOS it was some random RFC1918 address in VRF interface, not something I could poll
|
12
|
+
# .1.0.8802.1.1.2.1.4.2.1.3.0.134.10.1.4.10.0.0.4
|
13
|
+
# in IOS it was usable address
|
14
|
+
# .1.0.8802.1.1.2.1.4.2.1.3.0.257.1.1.4.62.243.146.245
|
15
|
+
# (1.4 is IPv4)
|
7
16
|
:lldpRemChassisIdSubtype => '1.0.8802.1.1.2.1.4.1.1.4', # CSCO and JNPR use 4 (MAC address) rendering ChassisID useless
|
8
17
|
:lldpRemChassisId => '1.0.8802.1.1.2.1.4.1.1.5',
|
9
18
|
:lldpRemSysName => '1.0.8802.1.1.2.1.4.1.1.9',
|
19
|
+
:lldpRemManAddrIfSubtype => '1.0.8802.1.1.2.1.4.2.1.3',
|
10
20
|
}
|
11
21
|
|
12
22
|
# @param [String] host host to query
|
@@ -17,9 +27,12 @@ class NetCrawl
|
|
17
27
|
end
|
18
28
|
|
19
29
|
def peers
|
20
|
-
@snmp.
|
21
|
-
|
22
|
-
|
30
|
+
addrs = @snmp.walk2hash(OID[:lldpRemManAddrIfSubtype]) do |vb|
|
31
|
+
key = vb.oid[OID[:lldpRemManAddrIfSubtype].split('.').size .. -7]
|
32
|
+
[vb.oid.last(4).join('.'), key]
|
33
|
+
end # FIXME: I am IPv4 specific and generally dodgy
|
34
|
+
names = @snmp.walk2hash(OID[:lldpRemSysName]) { |vb| DNS.getip namemap(vb.value) }
|
35
|
+
names.keys.map { |id| names[id] or addrs[id] }.compact
|
23
36
|
rescue SNMP::NoResponse
|
24
37
|
[]
|
25
38
|
end
|
@@ -30,6 +43,5 @@ class NetCrawl
|
|
30
43
|
@snmp = SNMP.new host
|
31
44
|
end
|
32
45
|
|
33
|
-
|
34
46
|
end
|
35
47
|
end
|
data/lib/netcrawl/snmp.rb
CHANGED
@@ -39,6 +39,24 @@ class NetCrawl
|
|
39
39
|
results
|
40
40
|
end
|
41
41
|
|
42
|
+
# bulkwalks oid returning hash based on block block gets SNMP::VarBind and
|
43
|
+
# shold rturn either hash_value or [hash_value, hash_key]
|
44
|
+
# if block does not return hash_key, hash_key is oid-root, e.g. if root is
|
45
|
+
# 1.2 and oid is 1.2.3.4.5 then key is 3.4.5
|
46
|
+
# @param [String] oid root oid to walk
|
47
|
+
# @yield [SNMP::VarBind] gives vb to block, expect back hash_value or [hash_value, hash_key]
|
48
|
+
# @return [Hash] resulting hash
|
49
|
+
def walk2hash oid, &block
|
50
|
+
index = oid.split('.').size
|
51
|
+
hash = {}
|
52
|
+
bulkwalk(oid).each do |vb|
|
53
|
+
value, key = block.call(vb)
|
54
|
+
key ||= vb.oid[index..-1]
|
55
|
+
hash[key] = value
|
56
|
+
end
|
57
|
+
hash
|
58
|
+
end
|
59
|
+
|
42
60
|
private
|
43
61
|
|
44
62
|
def initialize host, community=CFG.snmp.community, timeout=CFG.snmp.timeout, retries=CFG.snmp.retries
|
data/netcrawl.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netcrawl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-31 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: snmp
|
@@ -74,7 +74,6 @@ files:
|
|
74
74
|
- Rakefile
|
75
75
|
- bin/netcrawl
|
76
76
|
- lib/netcrawl.rb
|
77
|
-
- lib/netcrawl/.cli.rb.swp
|
78
77
|
- lib/netcrawl/cli.rb
|
79
78
|
- lib/netcrawl/config.rb
|
80
79
|
- lib/netcrawl/dns.rb
|
@@ -100,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
100
99
|
version: '0'
|
101
100
|
segments:
|
102
101
|
- 0
|
103
|
-
hash:
|
102
|
+
hash: 2137776821860602171
|
104
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
104
|
none: false
|
106
105
|
requirements:
|
@@ -109,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
108
|
version: '0'
|
110
109
|
segments:
|
111
110
|
- 0
|
112
|
-
hash:
|
111
|
+
hash: 2137776821860602171
|
113
112
|
requirements: []
|
114
113
|
rubyforge_project: netcrawl
|
115
114
|
rubygems_version: 1.8.25
|
data/lib/netcrawl/.cli.rb.swp
DELETED
Binary file
|