snmp-open 0.1.0 → 0.1.1

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
  SHA1:
3
- metadata.gz: fc671a4ac4d5b81dac6e7b60cac57b3a594412ee
4
- data.tar.gz: e0b20a2c2c326b581ac7d8d1e5cf3216eff00d61
3
+ metadata.gz: 5f5f31288054f467dd80af94303c650adb60d8e6
4
+ data.tar.gz: 055b4581a3151737dc7b6027c19c17c2e43c563f
5
5
  SHA512:
6
- metadata.gz: 55b08ab034b1221571fbbba4c3d1d00be4332668ee284aeed676afe07a18fb9094bd584f4936ce3885999371fb90a3758491c2edb69d8c23d90fe5f482b4c56f
7
- data.tar.gz: cfcd6ee89c71ca7814e8c26e668627c0580058e8290d151ccf5ff5ce20c26e20476c851d173aae2f6dbe3b03ca125199d2235faeb7711268fe7ea20e60ad54fa
6
+ metadata.gz: ddfdc84646517ad15ae203b4f8c8776e8a3da371336298f62c100e336432d674f64127837d365eb437bac0d2fd63676712fd100778009b944daff50bd579f5c2
7
+ data.tar.gz: dca85d9c73d4a41943c6d83eaf38024af48edf7b7e5d4c6dc6206d944eadc76e2edba9809b2add5f71814b85c2fef7d754eef43e2c310e1abe2b3588f2a9c6b1
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # SNMP::Open
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/snmp-open.svg)](https://rubygems.org/gems/snmp-open)
4
+ [![Build Status](https://travis-ci.org/bjmllr/snmp-open.svg)](https://travis-ci.org/bjmllr/snmp-open)
5
+
3
6
  Ruby wrapper for the Net-SNMP command line programs `snmpget`, `snmpwalk`, and `snmpbulkwalk`.
4
7
 
5
8
  ## Installation
@@ -0,0 +1,50 @@
1
+ require 'snmp/open/parser'
2
+
3
+ module SNMP
4
+ class Open
5
+ # Test double for SNMP::Open that reads from the filesystem instead of
6
+ # running SNMP commands. Expects a 'walk' directory to be present if #walk
7
+ # will be used, and a 'get' directory if #get will be used. Within each
8
+ # directory, files named according to the numeric OIDs to be used are
9
+ # expected to be present, containing the output of an snmpwalk or snmpget
10
+ # run over the given OID.
11
+ #
12
+ # Produces warnings describing an snmpbulkwalk or snmpget command that could
13
+ # be used to generate a needed file, if the file is unavailable. Controlled
14
+ # by the `warnings` option.
15
+
16
+ class FileReader
17
+ def initialize(directory, options = {})
18
+ @directory = directory
19
+ @warnings = options.delete(:warnings)
20
+ @command_generator = SNMP::Open.new(options.merge(host: '$OPTIONS'))
21
+ end
22
+
23
+ def get(oids)
24
+ return enum_for(:get, oids) unless block_given?
25
+ texts = oids.map { |o| File.read(File.join(@directory, 'get', o)) }
26
+ Parser.new(oids).parse(texts).each { |*args| yield(*args) }
27
+ rescue Errno::ENOENT => err
28
+ if @warnings
29
+ oids.each do |oid|
30
+ warn "#{@command_generator.cli(:get, oid)} > get/#{oid}"
31
+ end
32
+ end
33
+ raise err
34
+ end
35
+
36
+ def walk(oids, *rest)
37
+ return enum_for(:walk, oids, *rest) unless block_given?
38
+ texts = oids.map { |o| File.read(File.join(@directory, 'walk', o)) }
39
+ Parser.new(oids).parse(texts).each { |*args| yield(*args) }
40
+ rescue Errno::ENOENT => err
41
+ if @warnings
42
+ oids.each do |oid|
43
+ warn "#{@command_generator.cli(:bulkwalk, oid)} > walk/#{oid}"
44
+ end
45
+ end
46
+ raise err
47
+ end
48
+ end # class FileReader
49
+ end # class Open
50
+ end # module SNMP
@@ -1,5 +1,5 @@
1
1
  module Snmp
2
2
  module Open
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.1.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snmp-open
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Miller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-30 00:00:00.000000000 Z
11
+ date: 2017-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,6 +85,7 @@ files:
85
85
  - bin/console
86
86
  - bin/setup
87
87
  - lib/snmp/open.rb
88
+ - lib/snmp/open/file_reader.rb
88
89
  - lib/snmp/open/parser.rb
89
90
  - lib/snmp/open/version.rb
90
91
  - snmp-open.gemspec