snmp_table_viewer 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.codeclimate.yml +21 -0
- data/.gitignore +27 -0
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +4 -0
- data/Guardfile +9 -0
- data/LICENSE.rdoc +39 -0
- data/README.md +83 -0
- data/Rakefile +16 -0
- data/bin/snmp-table-viewer +150 -0
- data/lib/snmp_table_viewer/converter/if_table.rb +296 -0
- data/lib/snmp_table_viewer/converter.rb +8 -0
- data/lib/snmp_table_viewer/fetcher.rb +24 -0
- data/lib/snmp_table_viewer/formatter/csv.rb +12 -0
- data/lib/snmp_table_viewer/formatter/json.rb +17 -0
- data/lib/snmp_table_viewer/formatter/raw.rb +12 -0
- data/lib/snmp_table_viewer/formatter/table.rb +30 -0
- data/lib/snmp_table_viewer/formatter.rb +30 -0
- data/lib/snmp_table_viewer.rb +14 -0
- data/snmp_table_viewer.gemspec +30 -0
- data/spec/snmp_table_viewer/converter/if_table_spec.rb +36 -0
- data/spec/snmp_table_viewer/converter_spec.rb +2 -0
- data/spec/snmp_table_viewer/fetcher_spec.rb +23 -0
- data/spec/snmp_table_viewer/formatter/csv_spec.rb +26 -0
- data/spec/snmp_table_viewer/formatter/json_spec.rb +26 -0
- data/spec/snmp_table_viewer/formatter/raw_spec.rb +26 -0
- data/spec/snmp_table_viewer/formatter/table_spec.rb +73 -0
- data/spec/snmp_table_viewer/formatter_spec.rb +42 -0
- data/spec/snmp_table_viewer_spec.rb +2 -0
- data/spec/spec_helper.rb +122 -0
- data/version.rb +3 -0
- metadata +202 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
describe SNMPTableViewer::Formatter::Table do
|
2
|
+
|
3
|
+
describe '#output' do
|
4
|
+
|
5
|
+
it 'With headings' do
|
6
|
+
headings = ['heading1', 'heading2', 'heading3']
|
7
|
+
data = [
|
8
|
+
['row1col1', 'row1col2', 'a,b'],
|
9
|
+
['row2col1', 'row2col2', 'b,c']
|
10
|
+
]
|
11
|
+
formatter = described_class.new(data: data, headings: headings)
|
12
|
+
expect(formatter.output).to eq [
|
13
|
+
'+----------+----------+----------+',
|
14
|
+
'| heading1 | heading2 | heading3 |',
|
15
|
+
'+----------+----------+----------+',
|
16
|
+
'| row1col1 | row1col2 | a,b |',
|
17
|
+
'| row2col1 | row2col2 | b,c |',
|
18
|
+
'+----------+----------+----------+',
|
19
|
+
].join("\n")
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'Without headings' do
|
23
|
+
data = [
|
24
|
+
['row1col1', 'row1col2', 'a,b'],
|
25
|
+
['row2col1', 'row2col2', 'b,c']
|
26
|
+
]
|
27
|
+
formatter = described_class.new(data: data)
|
28
|
+
expect(formatter.output).to eq [
|
29
|
+
'+----------+----------+-----+',
|
30
|
+
'| row1col1 | row1col2 | a,b |',
|
31
|
+
'| row2col1 | row2col2 | b,c |',
|
32
|
+
'+----------+----------+-----+',
|
33
|
+
].join("\n")
|
34
|
+
end
|
35
|
+
|
36
|
+
describe 'Transposes output' do
|
37
|
+
|
38
|
+
it 'With headings' do
|
39
|
+
headings = ['heading1', 'heading2', 'heading3']
|
40
|
+
data = [
|
41
|
+
['row1col1', 'row1col2', 'a,b'],
|
42
|
+
['row2col1', 'row2col2', 'b,c']
|
43
|
+
]
|
44
|
+
formatter = described_class.new(data: data, headings: headings)
|
45
|
+
expect(formatter.output(transpose: true)).to eq [
|
46
|
+
'+----------+----------+----------+',
|
47
|
+
'| heading1 | row1col1 | row2col1 |',
|
48
|
+
'| heading2 | row1col2 | row2col2 |',
|
49
|
+
'| heading3 | a,b | b,c |',
|
50
|
+
'+----------+----------+----------+',
|
51
|
+
].join("\n")
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'Without headings' do
|
55
|
+
data = [
|
56
|
+
['row1col1', 'row1col2', 'a,b'],
|
57
|
+
['row2col1', 'row2col2', 'b,c']
|
58
|
+
]
|
59
|
+
formatter = described_class.new(data: data)
|
60
|
+
expect(formatter.output(transpose: true)).to eq [
|
61
|
+
'+----------+----------+',
|
62
|
+
'| row1col1 | row2col1 |',
|
63
|
+
'| row1col2 | row2col2 |',
|
64
|
+
'| a,b | b,c |',
|
65
|
+
'+----------+----------+',
|
66
|
+
].join("\n")
|
67
|
+
end
|
68
|
+
|
69
|
+
end # describe transposes output
|
70
|
+
|
71
|
+
end # describe #output
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
describe SNMPTableViewer::Formatter do
|
2
|
+
|
3
|
+
describe 'Create' do
|
4
|
+
it "Requires data" do
|
5
|
+
expect{described_class.new}.to raise_error(ArgumentError, 'missing keyword: data')
|
6
|
+
end
|
7
|
+
it "Has data" do
|
8
|
+
expect(described_class.new(data: [])).to_not be_nil
|
9
|
+
expect(described_class.new(data: [], headings: [])).to_not be_nil
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#has_headings?' do
|
14
|
+
it 'Headings are present' do
|
15
|
+
formatter = described_class.new(data: [], headings: ['A heading'])
|
16
|
+
expect(formatter.send(:has_headings?)).to be true
|
17
|
+
end
|
18
|
+
it 'Headings are not present' do
|
19
|
+
formatter = described_class.new(data: [])
|
20
|
+
expect(formatter.send(:has_headings?)).to be false
|
21
|
+
end
|
22
|
+
it 'Headings are not in an array' do
|
23
|
+
formatter = described_class.new(data: [], headings: {})
|
24
|
+
expect(formatter.send(:has_headings?)).to be false
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#data_with_headings' do
|
29
|
+
it 'Headings are present' do
|
30
|
+
headings = ['heading1', 'heading2']
|
31
|
+
data_line = ['data1', 'data2']
|
32
|
+
formatter = described_class.new(data: [data_line], headings: headings)
|
33
|
+
expect(formatter.send(:data_with_headings)).to eq [headings, data_line]
|
34
|
+
end
|
35
|
+
it 'Headings are not present' do
|
36
|
+
data_line = ['data1', 'data2']
|
37
|
+
formatter = described_class.new(data: [data_line])
|
38
|
+
expect(formatter.send(:data_with_headings)).to eq [data_line]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.coverage_dir(File.join('tmp', 'coverage'))
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter 'spec/'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'coveralls' and Coveralls.wear! if ENV['TRAVIS']
|
8
|
+
|
9
|
+
require_relative '../lib/snmp_table_viewer'
|
10
|
+
|
11
|
+
|
12
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
13
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
14
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
15
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
16
|
+
# files.
|
17
|
+
#
|
18
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
19
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
20
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
21
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
22
|
+
# a separate helper file that requires the additional dependencies and performs
|
23
|
+
# the additional setup, and require it from the spec files that actually need
|
24
|
+
# it.
|
25
|
+
#
|
26
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
27
|
+
RSpec.configure do |config|
|
28
|
+
# rspec-expectations config goes here. You can use an alternate
|
29
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
30
|
+
# assertions if you prefer.
|
31
|
+
config.expect_with :rspec do |expectations|
|
32
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
33
|
+
# and `failure_message` of custom matchers include text for helper methods
|
34
|
+
# defined using `chain`, e.g.:
|
35
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
36
|
+
# # => "be bigger than 2 and smaller than 4"
|
37
|
+
# ...rather than:
|
38
|
+
# # => "be bigger than 2"
|
39
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
40
|
+
end
|
41
|
+
|
42
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
43
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
44
|
+
config.mock_with :rspec do |mocks|
|
45
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
46
|
+
# a real object. This is generally recommended, and will default to
|
47
|
+
# `true` in RSpec 4.
|
48
|
+
mocks.verify_partial_doubles = true
|
49
|
+
|
50
|
+
# Using the expect syntax is preferable to the should syntax in some cases.
|
51
|
+
# The problem here is that the :should syntax that RSpec uses can fail in
|
52
|
+
# the case of proxy objects, and objects that include the delegate module.
|
53
|
+
# Essentially it requires that we define methods on every object in the
|
54
|
+
# system. Not owning every object means that we cannot ensure this works in
|
55
|
+
# a consistent manner. The expect syntax gets around this problem by not
|
56
|
+
# relying on RSpec specific methods being defined on every object in the
|
57
|
+
# system.
|
58
|
+
#configuration.syntax = [:expect, :should]
|
59
|
+
mocks.syntax = :expect
|
60
|
+
end
|
61
|
+
|
62
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
63
|
+
# have no way to turn it off -- the option exists only for backwards
|
64
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
65
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
66
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
67
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
68
|
+
|
69
|
+
# The settings below are suggested to provide a good initial experience
|
70
|
+
# with RSpec, but feel free to customize to your heart's content.
|
71
|
+
=begin
|
72
|
+
# This allows you to limit a spec run to individual examples or groups
|
73
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
74
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
75
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
76
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
77
|
+
config.filter_run_when_matching :focus
|
78
|
+
|
79
|
+
# Allows RSpec to persist some state between runs in order to support
|
80
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
81
|
+
# you configure your source control system to ignore this file.
|
82
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
83
|
+
|
84
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
85
|
+
# recommended. For more details, see:
|
86
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
87
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
88
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
89
|
+
config.disable_monkey_patching!
|
90
|
+
|
91
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
92
|
+
# be too noisy due to issues in dependencies.
|
93
|
+
config.warnings = true
|
94
|
+
|
95
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
96
|
+
# file, and it's useful to allow more verbose output when running an
|
97
|
+
# individual spec file.
|
98
|
+
if config.files_to_run.one?
|
99
|
+
# Use the documentation formatter for detailed output,
|
100
|
+
# unless a formatter has already been configured
|
101
|
+
# (e.g. via a command-line flag).
|
102
|
+
config.default_formatter = "doc"
|
103
|
+
end
|
104
|
+
|
105
|
+
# Print the 10 slowest examples and example groups at the
|
106
|
+
# end of the spec run, to help surface which specs are running
|
107
|
+
# particularly slow.
|
108
|
+
config.profile_examples = 10
|
109
|
+
|
110
|
+
# Run specs in random order to surface order dependencies. If you find an
|
111
|
+
# order dependency and want to debug it, you can fix the order by providing
|
112
|
+
# the seed, which is printed after each run.
|
113
|
+
# --seed 1234
|
114
|
+
config.order = :random
|
115
|
+
|
116
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
117
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
118
|
+
# test failures related to randomization by passing the same `--seed` value
|
119
|
+
# as the one that triggered the failure.
|
120
|
+
Kernel.srand config.seed
|
121
|
+
=end
|
122
|
+
end
|
data/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: snmp_table_viewer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Gauld
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: netsnmp
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.1.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: terminal-table
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.8.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.8.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.14.1
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '4'
|
65
|
+
type: :development
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 2.14.1
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '4'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: guard-rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '4.2'
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 4.2.5
|
85
|
+
type: :development
|
86
|
+
prerelease: false
|
87
|
+
version_requirements: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '4.2'
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 4.2.5
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: rb-inotify
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0.9'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0.9'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: coveralls
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0.7'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0.7'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: simplecov
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0.7'
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - "~>"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0.7'
|
137
|
+
description: Easily view SNMP tables in a variety of different formats including as
|
138
|
+
a table in the terminal, json or csv.
|
139
|
+
email:
|
140
|
+
- robert@robertgauld.co.uk
|
141
|
+
executables:
|
142
|
+
- snmp-table-viewer
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".codeclimate.yml"
|
147
|
+
- ".gitignore"
|
148
|
+
- ".rspec"
|
149
|
+
- ".travis.yml"
|
150
|
+
- CHANGELOG.md
|
151
|
+
- Gemfile
|
152
|
+
- Guardfile
|
153
|
+
- LICENSE.rdoc
|
154
|
+
- README.md
|
155
|
+
- Rakefile
|
156
|
+
- bin/snmp-table-viewer
|
157
|
+
- lib/snmp_table_viewer.rb
|
158
|
+
- lib/snmp_table_viewer/converter.rb
|
159
|
+
- lib/snmp_table_viewer/converter/if_table.rb
|
160
|
+
- lib/snmp_table_viewer/fetcher.rb
|
161
|
+
- lib/snmp_table_viewer/formatter.rb
|
162
|
+
- lib/snmp_table_viewer/formatter/csv.rb
|
163
|
+
- lib/snmp_table_viewer/formatter/json.rb
|
164
|
+
- lib/snmp_table_viewer/formatter/raw.rb
|
165
|
+
- lib/snmp_table_viewer/formatter/table.rb
|
166
|
+
- snmp_table_viewer.gemspec
|
167
|
+
- spec/snmp_table_viewer/converter/if_table_spec.rb
|
168
|
+
- spec/snmp_table_viewer/converter_spec.rb
|
169
|
+
- spec/snmp_table_viewer/fetcher_spec.rb
|
170
|
+
- spec/snmp_table_viewer/formatter/csv_spec.rb
|
171
|
+
- spec/snmp_table_viewer/formatter/json_spec.rb
|
172
|
+
- spec/snmp_table_viewer/formatter/raw_spec.rb
|
173
|
+
- spec/snmp_table_viewer/formatter/table_spec.rb
|
174
|
+
- spec/snmp_table_viewer/formatter_spec.rb
|
175
|
+
- spec/snmp_table_viewer_spec.rb
|
176
|
+
- spec/spec_helper.rb
|
177
|
+
- version.rb
|
178
|
+
homepage: https://github.com/robertgauld/snmp-table-viewer
|
179
|
+
licenses:
|
180
|
+
- BSD 3 clause
|
181
|
+
metadata: {}
|
182
|
+
post_install_message:
|
183
|
+
rdoc_options: []
|
184
|
+
require_paths:
|
185
|
+
- lib
|
186
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: '0'
|
191
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
|
+
requirements: []
|
197
|
+
rubyforge_project:
|
198
|
+
rubygems_version: 2.5.1
|
199
|
+
signing_key:
|
200
|
+
specification_version: 4
|
201
|
+
summary: Easily view SNMP tables.
|
202
|
+
test_files: []
|