arpdb 0.1.8 → 0.2.0

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/README.md CHANGED
@@ -27,12 +27,10 @@ Or install it yourself as:
27
27
  require 'arpdb'
28
28
  include Arpdb
29
29
 
30
- devices = %w(10.40.5.1 10.43.5.1)
30
+ hosts = %w(10.40.5.1 10.43.5.1)
31
31
  community = 'public'
32
32
 
33
- adb = Arp.new(devices, community)
34
-
35
- adb.scan
33
+ adb = Arp.new(hosts.collect { |host| SNMPTransport.new(host, community) }).scan
36
34
 
37
35
  puts adb.mac_to_ip "7a70dec81b02"
38
36
  puts adb.ip_to_mac "172.27.50.2"
@@ -40,7 +38,7 @@ puts adb.ip_to_mac "172.27.50.2"
40
38
  puts adb.locate_mac "7a70dec81b02"
41
39
  puts adb.locate_ip "172.27.50.2"
42
40
 
43
- adb.refresh
41
+ adb.rescan
44
42
 
45
43
  ```
46
44
 
data/lib/arpdb/arp.rb CHANGED
@@ -7,11 +7,14 @@ module Arpdb
7
7
  class ArpdbError < StandardError
8
8
  end
9
9
 
10
- attr_accessor :db
11
-
12
- def initialize(hostlist, community = 'public')
13
- @hostlist = hostlist
14
- @community = community
10
+ attr_accessor :db, :snmp_transports
11
+
12
+ # Oh gimme my syringe, I want to do some dependency injection!
13
+ # On a more serious note: snmp_transports is expected to be either
14
+ # Arpdb::SNMPTransport or array of those. This way we can easily pass
15
+ # mocked SNMPTransport here for off-the-hook testing.
16
+ def initialize(snmp_transports)
17
+ snmp_transports.is_a?(Array) ? @snmp_transports = snmp_transports : @snmp_transports = [snmp_transports]
15
18
  @db = Array.new
16
19
  end
17
20
 
@@ -20,18 +23,16 @@ module Arpdb
20
23
  end
21
24
 
22
25
  def scan
23
- @hostlist.each do |host|
24
- handle_exceptions do
25
- st = SNMPTransport.new(host, @community)
26
+ handle_exceptions do
27
+ snmp_transports.each do |st|
26
28
  location = st.get('1.3.6.1.2.1.1.6.0')
27
29
 
28
30
  st.walk(%w(1.3.6.1.2.1.4.22.1.2 1.3.6.1.2.1.4.22.1.3)).each do |row|
29
- @db << {mac: row.first, ip: row.last, host: host, location: location}
31
+ @db << {mac: row.first, ip: row.last, host: st.host, location: location}
30
32
  end
31
- st.close
32
33
  end
33
-
34
34
  end
35
+
35
36
  self
36
37
  end
37
38
 
@@ -2,9 +2,10 @@ require 'snmp'
2
2
 
3
3
  class SNMPTransport
4
4
 
5
- attr_accessor :manager
5
+ attr_accessor :manager, :host
6
6
 
7
7
  def initialize(host, community = 'public')
8
+ @host = host
8
9
  @manager = SNMP::Manager.new(host: host, community: community, mib_modules: [], retries: 1)
9
10
  end
10
11
 
@@ -24,10 +25,6 @@ class SNMPTransport
24
25
  manager.get(oid).each_varbind { |vb| return decode_value(vb) }
25
26
  end
26
27
 
27
- def close
28
- manager.close
29
- end
30
-
31
28
  private
32
29
 
33
30
  def decode_value(vb)
data/lib/arpdb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Arpdb
2
- VERSION = "0.1.8"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arpdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: