copian 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ pkg
5
+ rdoc
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Geoff Garside
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,83 @@
1
+ = Copian
2
+
3
+ Copian is a suite of SNMP network device collectors. It provides an easy way of gathering information from SNMP enabled network devices. As of the current version it supports the following
4
+
5
+ - Network Interface Stats
6
+ - MTU size
7
+ - Connection speed (in bits)
8
+ - Admin and Oper status indicating UP/DOWN
9
+ - Network Interface Bandwidth, including 64 bit counter support.
10
+ - Switch port to IP Address mapping
11
+ - Switch port to MAC Addresses
12
+ - VLAN listings
13
+
14
+ == Examples
15
+ Collecting the status of all the network interfaces on a Cisco Router
16
+
17
+ require 'copian'
18
+ collector = Copian::Collector::Cisco.new('192.168.1.1', 'public')
19
+ collector.port_stats do |ifindex, ifname, mtu, speed, admin_status, oper_status|
20
+ puts "Port #{ifname} is #{oper_status} @ #{speed} bps. mtu (#{mtu})"
21
+ end
22
+ # Port 1/e1 is 1 @ 100000000. mtu(1500)
23
+ # ...
24
+
25
+ presently the admin_status and oper_status are not interpreted, but equate to
26
+
27
+ 1. up
28
+ 2. down
29
+ 3. testing
30
+
31
+ == History
32
+
33
+ === 1.3.2 - 2009/10/06
34
+
35
+ - 1 major correction
36
+ - BandwidthCollector fixed, it was incredibly buggy
37
+
38
+ === 1.3.1 - 2009/10/06
39
+
40
+ - 1 patch
41
+ - Fix symbol reference for the bandwidth collector from :64bit -> :b64
42
+
43
+ === 1.3.0 - 2009/10/05
44
+
45
+ - 1 major enhancement
46
+ - Added generic Bandwidth collector with support for 32 and 64bit counters
47
+ to use the 64 bit counters {:64bit => true} needs to be passed to the
48
+ bandwidth method on the collector.
49
+
50
+ === 1.2.0 - 2009/02/04
51
+
52
+ - 2 major enhancements
53
+ - Added VLAN collector to Dell collector
54
+ - Added VLAN collector to HP collector
55
+
56
+ === 1.1.1 - 2009/02/04
57
+
58
+ - 1 bug fix
59
+ - Fixed HP ports collector incorrectly stripping information from
60
+ returned ObjectID resulting in invalid MAC addresses
61
+
62
+ === 1.1.0 - 2009/02/04
63
+
64
+ - 3 major enhancement
65
+ - Dell collector with ports support
66
+ - HP collector with ports support
67
+ - Port stats, ifMtu, ifSpeed, ifAdminStatus and ifOperStatus
68
+ - 1 extensibility enhancement
69
+ - Introduced Generic Collector from which the others descend
70
+
71
+ === 1.0.0 - 2009/02/03
72
+
73
+ - 1 major enhancement
74
+ - Cisco collector supports Ports, VLANs and Addresses
75
+
76
+ === 0.0.1 - 2009/02/02
77
+
78
+ - 1 major enhancement
79
+ - initial creation
80
+
81
+ == COPYRIGHT
82
+
83
+ Copyright (c) 2009 Geoff Garside. See LICENSE[link:files/LICENSE.html] for details.
data/Rakefile ADDED
@@ -0,0 +1,45 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |s|
8
+ s.name = "copian"
9
+ s.summary = %Q{Suite of SNMP collectors for different types of network devices}
10
+ s.email = "geoff@geoffgarside.co.uk"
11
+ s.homepage = "http://github.com/geoffgarside/copian"
12
+ s.description = "Suite of SNMP collectors for different types of network devices"
13
+ s.authors = ["Geoff Garside"]
14
+ s.add_dependency('snmp', '>= 1.0.2')
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
+ end
19
+
20
+ Rake::TestTask.new do |t|
21
+ t.libs << 'lib'
22
+ t.pattern = 'test/**/*_test.rb'
23
+ t.verbose = false
24
+ end
25
+
26
+ Rake::RDocTask.new do |rdoc|
27
+ rdoc.rdoc_dir = 'rdoc'
28
+ rdoc.title = 'copian'
29
+ rdoc.options << '--line-numbers' << '--inline-source'
30
+ rdoc.rdoc_files.include('README*')
31
+ rdoc.rdoc_files.include('LICENSE')
32
+ rdoc.rdoc_files.include('lib/**/*.rb')
33
+ end
34
+
35
+ begin
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |t|
38
+ t.libs << 'test'
39
+ t.test_files = FileList['test/**/*_test.rb']
40
+ t.verbose = true
41
+ end
42
+ rescue LoadError
43
+ end
44
+
45
+ task :default => :test
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 1
3
+ :minor: 3
4
+ :patch: 2
data/lib/copian.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'copian/collector/abstract_collector'
2
+ require 'copian/collector/addresses_collector'
3
+ require 'copian/collector/bandwidth_collector'
4
+ require 'copian/collector/description_collector'
5
+ require 'copian/collector/ports_collector'
6
+ require 'copian/collector/port_stats_collector'
7
+ require 'copian/collector/generic'
8
+ require 'copian/collector/cisco'
9
+ require 'copian/collector/dell'
10
+ require 'copian/collector/hp'
11
+
12
+ require 'snmp'
13
+
14
+ # :stopdoc:
15
+ class SNMP::Manager
16
+ attr_reader :host, :community, :version
17
+ end
18
+ # :startdoc:
19
+
20
+ module Copian # :nodoc:
21
+ module Collector # :nodoc:
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ module Copian
2
+ module Collector
3
+ class AbstractCollector # :nodoc:
4
+ def initialize(manager)
5
+ @manager = manager
6
+ end
7
+ def collect
8
+ raise NoMethodError, "You must implement a collect method"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,18 @@
1
+ module Copian
2
+ module Collector
3
+ class AddressesCollector < AbstractCollector # :nodoc:
4
+ protected
5
+ def append_mac_and_ip(mac, ip)
6
+ @map ||= Hash.new
7
+ @map[mac] ||= Array.new
8
+ @map[mac] << ip
9
+ end
10
+ def value_to_mac_address(value)
11
+ value.unpack('H2' * 6).join(':')
12
+ end
13
+ def name_to_ip_address(name, oid)
14
+ name.index(oid).to_s.gsub(/^[0-9]+\./, '')
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,52 @@
1
+ module Copian
2
+ module Collector
3
+ class BandwidthCollector < AbstractCollector # :nodoc:
4
+ def initialize(manager)
5
+ super(manager)
6
+ @interfaces = Hash.new
7
+ end
8
+ def collect
9
+ load_inoctets
10
+ load_outoctets
11
+
12
+ @interfaces.each do |ifindex, stats|
13
+ yield ifindex, stats[:inoctets], stats[:outoctets]
14
+ end
15
+ end
16
+ def collect64
17
+ load_inoctets64
18
+ load_outoctets64
19
+
20
+ @interfaces.each do |ifindex, stats|
21
+ yield ifindex, stats[:inoctets64], stats[:outoctets64]
22
+ end
23
+ end
24
+ protected
25
+ def load_inoctets
26
+ load_property(:inoctets, SNMP::ObjectId.new('1.3.6.1.2.1.2.2.1.10'))
27
+ end
28
+ def load_outoctets
29
+ load_property(:outoctets, SNMP::ObjectId.new('1.3.6.1.2.1.2.2.1.16'))
30
+ end
31
+ def load_inoctets64
32
+ load_property(:inoctets64, SNMP::ObjectId.new('1.3.6.1.2.1.31.1.1.1.6'))
33
+ end
34
+ def load_outoctets64
35
+ load_property(:outoctets64, SNMP::ObjectId.new('1.3.6.1.2.1.31.1.1.1.10'))
36
+ end
37
+ def load_property(property, oid)
38
+ @manager.walk(oid) do |r|
39
+ r.each do |varbind|
40
+ append_property(varbind.name.index(oid), property,
41
+ varbind.value.to_i)
42
+ end
43
+ end
44
+ end
45
+ def append_property(index, property, value)
46
+ @interfaces[index.to_s.to_i] ||= Hash.new
47
+ @interfaces[index.to_s.to_i][property] = value
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,40 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/cisco/addresses')
2
+ require File.expand_path(File.dirname(__FILE__) + '/cisco/ports')
3
+ require File.expand_path(File.dirname(__FILE__) + '/cisco/vlans')
4
+
5
+ module Copian
6
+ module Collector
7
+ class Cisco < Generic
8
+ def vlans # :yields: id, ifindex, name
9
+ load_ifnames
10
+
11
+ vlans_collector.collect do |vlan_id, vlan_index|
12
+ yield vlan_id, vlan_index, @ifnames[vlan_index]
13
+ end
14
+ end
15
+ def addresses # :yields: mac_address, ip_addresses_array
16
+ addresses_collector.collect do |mac, ips|
17
+ yield mac, ips
18
+ end
19
+ end
20
+ def ports # :yields: ifindex, ifname, addresses_array
21
+ load_ifnames
22
+
23
+ ports_collector.collect do |port_ifindex, port_addresses|
24
+ yield port_ifindex, @ifnames[port_ifindex], port_addresses
25
+ end
26
+ end
27
+ private
28
+ def vlans_collector
29
+ @vlans_collector ||= CiscoVlansCollector.new(@manager)
30
+ end
31
+ def addresses_collector
32
+ @addresses_collector ||= CiscoAddressesCollector.new(@manager)
33
+ end
34
+ def ports_collector
35
+ @ports_collector ||=
36
+ CiscoPortsCollector.new(@manager, vlans_collector)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ module Copian
2
+ module Collector
3
+ class CiscoAddressesCollector < AddressesCollector # :nodoc:
4
+ def collect
5
+ oid = SNMP::ObjectId.new('1.3.6.1.2.1.4.22.1.2')
6
+ @manager.walk(oid) do |r|
7
+ r.each do |varbind|
8
+ mac_addr = value_to_mac_address(varbind.value)
9
+ ip_addr = name_to_ip_address(varbind.name, oid)
10
+ append_mac_and_ip(mac_addr, ip_addr)
11
+ end
12
+ end
13
+
14
+ @map.each do |mac, ips|
15
+ yield mac.dup, ips if block_given?
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,56 @@
1
+ module Copian
2
+ module Collector
3
+ class CiscoPortsCollector < PortsCollector # :nodoc:
4
+ def initialize(manager, vlans_collector)
5
+ super(manager)
6
+ @vlans_collector = vlans_collector
7
+ end
8
+ def collect
9
+ each_vlan do |manager|
10
+ mac_bridge_ports = gather_mac_bridge_ports(manager)
11
+ bridge_port_iface = gather_bridge_port_ifaces(manager)
12
+
13
+ # Now we stitch the two lists together
14
+ mac_bridge_ports.each do |bridge_port, addresses|
15
+ yield bridge_port_iface[bridge_port], addresses
16
+ end
17
+ end
18
+ end
19
+ private
20
+ def each_vlan
21
+ @vlans_collector.collect do |vlan_id, vlan_index|
22
+ yield SNMP::Manager.new(:Host => @manager.host,
23
+ :Version => @manager.version,
24
+ :Community => "#{@manager.community}@#{vlan_id}")
25
+ end
26
+ end
27
+ def gather_mac_bridge_ports(manager)
28
+ oid = SNMP::ObjectId.new('1.3.6.1.2.1.17.4.3.1.2')
29
+ mac_bridge_ports = Hash.new
30
+
31
+ manager.walk(oid) do |r|
32
+ r.each do |varbind|
33
+ mac_bridge_ports[varbind.value.to_i] ||= Array.new
34
+ mac_bridge_ports[varbind.value.to_i] <<
35
+ suboid_to_mac(varbind.name.index(oid))
36
+ end
37
+ end
38
+
39
+ mac_bridge_ports
40
+ end
41
+ def gather_bridge_port_ifaces(manager)
42
+ oid = SNMP::ObjectId.new('1.3.6.1.2.1.17.1.4.1.2')
43
+ bridge_port_ifaces = Hash.new
44
+
45
+ manager.walk(oid) do |r|
46
+ r.each do |varbind|
47
+ bridge_port_ifaces[varbind.name.index(oid).to_s.to_i] =
48
+ varbind.value.to_i
49
+ end
50
+ end
51
+
52
+ bridge_port_ifaces
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,19 @@
1
+ module Copian
2
+ module Collector
3
+ class CiscoVlansCollector < AbstractCollector # :nodoc:
4
+ def collect
5
+ oid = SNMP::ObjectId.new('1.3.6.1.4.1.9.9.46.1.3.1.1.18.1')
6
+ @manager.walk(oid) do |r|
7
+ r.each do |varbind|
8
+ vlan_id = varbind.name.index(oid).to_s.to_i
9
+ vlan_ifindex = varbind.value.to_i
10
+
11
+ # NOTE: Ignore ids between 1002 and 1005 they are seemingly fake
12
+ next if vlan_id.between?(1002, 1005)
13
+ yield vlan_id, vlan_ifindex
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/dell/ports')
2
+ require File.expand_path(File.dirname(__FILE__) + '/dell/vlans')
3
+
4
+ module Copian
5
+ module Collector
6
+ class Dell < Generic
7
+ def vlans # :yields: id, ifindex, name
8
+ load_ifnames
9
+
10
+ vlans_collector.collect do |vlan_id, vlan_index|
11
+ yield vlan_id, vlan_index, @ifnames[vlan_index]
12
+ end
13
+ end
14
+ def ports # :yields: ifindex, ifname, addresses_array
15
+ load_ifnames
16
+
17
+ ports_collector.collect do |port_ifindex, port_addresses|
18
+ yield port_ifindex, @ifnames[port_ifindex], port_addresses
19
+ end
20
+ end
21
+ private
22
+ def vlans_collector
23
+ @vlans_collector ||= DellVlansCollector.new(@manager)
24
+ end
25
+ def ports_collector
26
+ @ports_collector ||=
27
+ DellPortsCollector.new(@manager)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ module Copian
2
+ module Collector
3
+ class DellPortsCollector < PortsCollector # :nodoc:
4
+ def collect
5
+ oid = SNMP::ObjectId.new('1.3.6.1.2.1.17.7.1.2.2.1.2')
6
+ results = Hash.new
7
+
8
+ manager.walk(oid) do |r|
9
+ r.each do |varbind|
10
+ results[varbind.value.to_i] ||= Array.new
11
+ results[varbind.value.to_i] << suboid_to_mac(varbind.name.index(oid))
12
+ end
13
+ end
14
+
15
+ results.each do |if_index, addresses|
16
+ yield if_index, addresses
17
+ end
18
+ end
19
+ protected
20
+ def suboid_to_mac(oid)
21
+ super(oid.to_s.gsub(/^[0-9]+\./, ''))
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,23 @@
1
+ module Copian
2
+ module Collector
3
+ class DellVlansCollector < AbstractCollector # :nodoc:
4
+ # ---
5
+ # Dell switches assign VLANs ifIndex values equal to
6
+ # the VLAN ID + 100000.
7
+ # +++
8
+ def collect
9
+ oid = SNMP::ObjectID.new('1.3.6.1.2.1.2.2.1.3')
10
+ @manager.walk(oid) do |r|
11
+ r.each do |varbind|
12
+ next unless varbind.value.to_i == 53 # propVirtual type
13
+ vlan_index = varbind.name.index(oid).to_s.to_i
14
+ vlan_id = vlan_index - 100000
15
+ vlan_id = 1 if vlan_id == 0
16
+
17
+ yield vlan_id, vlan_index
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ module Copian
2
+ module Collector
3
+ class DescriptionCollector < AbstractCollector # :nodoc:
4
+ def collect
5
+ oid = SNMP::ObjectId.new('1.3.6.1.2.1.2.2.1.2')
6
+ @manager.walk(oid) do |r|
7
+ r.each do |varbind|
8
+ yield varbind.name.index(oid), varbind.value.to_s
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,71 @@
1
+ module Copian
2
+ module Collector
3
+ class Generic
4
+ def inspect
5
+ "#<#{self.class} #{@manager.host}@#{@manager.community}>"
6
+ end
7
+ def initialize(ip_addr, community, version = :SNMPv2c)
8
+ @manager = SNMP::Manager.new(:Host => ip_addr,
9
+ :Community => community, :Version => version)
10
+ end
11
+ def port_stats # :yields: ifindex, name, mtu, speed, admin_status, oper_status
12
+ load_ifnames
13
+
14
+ port_stats_collector.collect do |ifindex, mtu, speed, admin_status, oper_status|
15
+ yield ifindex, @ifnames[ifindex], mtu, speed, admin_status, oper_status
16
+ end
17
+ end
18
+
19
+ # Collect bandwidth statistics
20
+ #
21
+ # Arguments:
22
+ # +options+
23
+ #
24
+ # Valid Options
25
+ # +:b64+ :Set to true to enable b64 bandwidth collection. Default false.
26
+ def bandwidth(options = {}) # :yields: ifindex, inoctets, outoctets
27
+ load_ifnames
28
+
29
+ collect_method = options[:b64] == true ? :collect64 : :collect
30
+ bandwidth_collector.send(collect_method) do |ifindex, inoctets, outoctets|
31
+ yield ifindex, @ifnames[ifindex], inoctets, outoctets
32
+ end
33
+ end
34
+
35
+ def descriptions # :yields: ifindex, ifname, ifdescr
36
+ load_ifnames
37
+
38
+ description_collector.collect do |ifindex, ifdescr|
39
+ yield ifindex, @ifnames[ifindex], ifdescr
40
+ end
41
+ end
42
+ protected
43
+ # :stopdoc:
44
+ def load_ifnames
45
+ return if @loaded_ifnames
46
+ oid = SNMP::ObjectId.new('1.3.6.1.2.1.31.1.1.1.1')
47
+ @manager.walk(oid) do |r|
48
+ r.each do |varbind|
49
+ append_ifname(varbind.name.index(oid).to_s.to_i,
50
+ varbind.value.to_s)
51
+ end
52
+ end
53
+ @loaded_ifnames = true
54
+ end
55
+ def append_ifname(ifindex, ifname)
56
+ @ifnames ||= Hash.new
57
+ @ifnames[ifindex] = ifname
58
+ end
59
+ def port_stats_collector
60
+ @port_stats_collector ||= PortStatsCollector.new(@manager)
61
+ end
62
+ def bandwidth_collector
63
+ @bandwidth_collector ||= BandwidthCollector.new(@manager)
64
+ end
65
+ def description_collector
66
+ @description_collector ||= DescriptionCollector.new(@manager)
67
+ end
68
+ # :startdoc:
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,33 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/hp/ports')
2
+ require File.expand_path(File.dirname(__FILE__) + '/hp/vlans')
3
+
4
+ module Copian
5
+ module Collector
6
+ class Hp < Generic
7
+ def vlans # :yields: id, ifindex, name
8
+ load_ifnames
9
+
10
+ vlans_collector.collect do |vlan_id, vlan_index|
11
+ vlan_name = @ifnames[vlan_index]
12
+ vlan_id = vlan_name.gsub(/[^0-9]/, '').to_i
13
+ yield vlan_id, vlan_index, vlan_name
14
+ end
15
+ end
16
+ def ports # :yields: ifindex, ifname, addresses_array
17
+ load_ifnames
18
+
19
+ ports_collector.collect do |port_ifindex, port_addresses|
20
+ yield port_ifindex, @ifnames[port_ifindex], port_addresses
21
+ end
22
+ end
23
+ private
24
+ def vlans_collector
25
+ @vlans_collector ||= HpVlansCollector.new(@manager)
26
+ end
27
+ def ports_collector
28
+ @ports_collector ||=
29
+ HpPortsCollector.new(@manager)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,25 @@
1
+ module Copian
2
+ module Collector
3
+ class HpPortsCollector < PortsCollector # :nodoc:
4
+ def collect
5
+ oid = SNMP::ObjectId.new('1.3.6.1.4.1.11.2.14.11.5.1.9.4.2.1.1')
6
+ results = Hash.new
7
+
8
+ manager.walk(oid) do |r|
9
+ r.each do |varbind|
10
+ results[varbind.value.to_i] ||= Array.new
11
+ results[varbind.value.to_i] << suboid_to_mac(varbind.name.index(oid))
12
+ end
13
+ end
14
+
15
+ results.each do |if_index, addresses|
16
+ yield if_index, addresses
17
+ end
18
+ end
19
+ protected
20
+ def suboid_to_mac(oid)
21
+ super(oid.to_s.gsub(/^[0-9]+\./, ''))
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,18 @@
1
+ module Copian
2
+ module Collector
3
+ class HpVlansCollector < AbstractCollector # :nodoc:
4
+ def collect
5
+ oid = SNMP::ObjectID.new('1.3.6.1.2.1.2.2.1.3')
6
+ @manager.walk(oid) do |r|
7
+ r.each do |varbind|
8
+ next unless varbind.value.to_i == 53 # propVirtual type
9
+ vlan_index = varbind.name.index(oid).to_s.to_i
10
+ # Not sure how to get this vlan ID, ifName sort of has it
11
+
12
+ yield nil, vlan_index
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,45 @@
1
+ module Copian
2
+ module Collector
3
+ class PortStatsCollector < AbstractCollector # :nodoc:
4
+ def initialize(manager)
5
+ super(manager)
6
+ @interfaces = Hash.new
7
+ end
8
+ def collect
9
+ load_mtu
10
+ load_speed
11
+ load_oper_status
12
+ load_admin_status
13
+
14
+ @interfaces.each do |ifindex, p|
15
+ yield ifindex, p[:mtu], p[:speed], p[:admin_status], p[:oper_status]
16
+ end
17
+ end
18
+ protected
19
+ def load_mtu
20
+ load_property(:mtu, SNMP::ObjectId.new('1.3.6.1.2.1.2.2.1.4'))
21
+ end
22
+ def load_speed
23
+ load_property(:speed, SNMP::ObjectId.new('1.3.6.1.2.1.2.2.1.5'))
24
+ end
25
+ def load_admin_status
26
+ load_property(:admin_status, SNMP::ObjectId.new('1.3.6.1.2.1.2.2.1.7'))
27
+ end
28
+ def load_oper_status
29
+ load_property(:oper_status, SNMP::ObjectId.new('1.3.6.1.2.1.2.2.1.8'))
30
+ end
31
+ def load_property(property, oid)
32
+ @manager.walk(oid) do |r|
33
+ r.each do |varbind|
34
+ append_property(varbind.name.index(oid), property,
35
+ varbind.value.to_i)
36
+ end
37
+ end
38
+ end
39
+ def append_property(index, property, value)
40
+ @interfaces[index.to_s.to_i] ||= Hash.new
41
+ @interfaces[index.to_s.to_i][property] = value
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,12 @@
1
+ module Copian
2
+ module Collector
3
+ class PortsCollector < AbstractCollector # :nodoc:
4
+ protected
5
+ def suboid_to_mac(oid)
6
+ oid.to_s.split('.').collect { |i|
7
+ i.to_i
8
+ }.pack('C' * 6).unpack('H2' * 6).join(':')
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class CopianTest < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'mocha'
5
+
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'copian'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: copian
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.2
5
+ platform: ruby
6
+ authors:
7
+ - Geoff Garside
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-06 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: snmp
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.0.2
24
+ version:
25
+ description: Suite of SNMP collectors for different types of network devices
26
+ email: geoff@geoffgarside.co.uk
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README
34
+ files:
35
+ - .gitignore
36
+ - LICENSE
37
+ - README
38
+ - Rakefile
39
+ - VERSION.yml
40
+ - lib/copian.rb
41
+ - lib/copian/collector/abstract_collector.rb
42
+ - lib/copian/collector/addresses_collector.rb
43
+ - lib/copian/collector/bandwidth_collector.rb
44
+ - lib/copian/collector/description_collector.rb
45
+ - lib/copian/collector/cisco.rb
46
+ - lib/copian/collector/cisco/addresses.rb
47
+ - lib/copian/collector/cisco/ports.rb
48
+ - lib/copian/collector/cisco/vlans.rb
49
+ - lib/copian/collector/dell.rb
50
+ - lib/copian/collector/dell/ports.rb
51
+ - lib/copian/collector/dell/vlans.rb
52
+ - lib/copian/collector/generic.rb
53
+ - lib/copian/collector/hp.rb
54
+ - lib/copian/collector/hp/ports.rb
55
+ - lib/copian/collector/hp/vlans.rb
56
+ - lib/copian/collector/port_stats_collector.rb
57
+ - lib/copian/collector/ports_collector.rb
58
+ - test/copian_test.rb
59
+ - test/test_helper.rb
60
+ has_rdoc: true
61
+ homepage: http://github.com/geoffgarside/copian
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --charset=UTF-8
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.3.5
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Suite of SNMP collectors for different types of network devices
88
+ test_files:
89
+ - test/copian_test.rb
90
+ - test/test_helper.rb