snmp_table_viewer 0.0.4
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.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9db3534a0e0d11c1747bd4f2edbc2d98990fd1ed
|
4
|
+
data.tar.gz: f0302013da02ee45a7712a22524029ed73bdf039
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5ba88ae246f5ef4c89703d4760fefb11f20185466e9225b4b18dfcf8d371e43d0d5cf5a690e461e90cbcbc34a433c2fdacd5b834a3b2219b6dcaaf9184eef829
|
7
|
+
data.tar.gz: 077a5ec639f89fd10ddb13a7958f8164487229d4a6f3a622732b2e10f41ac6b2d494bc4e241a6a0379663802270aff29e5ece6d36940eb497d026b3be8e8c486
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
engines:
|
2
|
+
duplication:
|
3
|
+
enabled: true
|
4
|
+
config:
|
5
|
+
languages:
|
6
|
+
ruby:
|
7
|
+
mass_threshold: 20
|
8
|
+
fixme:
|
9
|
+
enabled: true
|
10
|
+
rubocop:
|
11
|
+
enabled: true
|
12
|
+
ratings:
|
13
|
+
paths:
|
14
|
+
- app/**/*
|
15
|
+
- lib/**/*
|
16
|
+
exclude_paths: # customize
|
17
|
+
- .bundle/
|
18
|
+
- doc/
|
19
|
+
- spec/
|
20
|
+
- tmp/
|
21
|
+
|
data/.gitignore
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Because this is a gem, ignore Gemfile.lock:
|
2
|
+
|
3
|
+
Gemfile.lock
|
4
|
+
|
5
|
+
# And because this is Ruby, ignore the following
|
6
|
+
# (source: https://github.com/github/gitignore/blob/master/Ruby.gitignore):
|
7
|
+
|
8
|
+
todo.txt
|
9
|
+
*.gem
|
10
|
+
*.rbc
|
11
|
+
.bundle
|
12
|
+
.config
|
13
|
+
coverage
|
14
|
+
InstalledFiles
|
15
|
+
lib/bundler/man
|
16
|
+
pkg
|
17
|
+
rdoc
|
18
|
+
spec/reports
|
19
|
+
test/tmp
|
20
|
+
test/version_tmp
|
21
|
+
tmp
|
22
|
+
gemfiles/*.lock
|
23
|
+
|
24
|
+
# YARD artifacts
|
25
|
+
.yardoc
|
26
|
+
_yardoc
|
27
|
+
doc/
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', all_on_start: true, all_after_pass: true do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
7
|
+
watch(%r{^lib/([^/]+)/(.+)\.rb$}) { |m| "spec/#{m[1]}/#{m[2]}_spec.rb" }
|
8
|
+
watch('spec/spec_helper.rb') { "spec" }
|
9
|
+
end
|
data/LICENSE.rdoc
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
==Copyright
|
2
|
+
Copyright (c) 2017, Robert Gauld. All rights reserved.
|
3
|
+
|
4
|
+
|
5
|
+
==License
|
6
|
+
This code can be used under the BSD License (reproduced below).
|
7
|
+
Commiters to the project give Robert Gauld the right to redistribute their commits
|
8
|
+
under the BSD license. Should the project be re-licensed and the commiter can not be
|
9
|
+
contacted either by the email address accompanying their commits or the project's community
|
10
|
+
then Robert Gauld shall have the right to re-license their commits on their behalf.
|
11
|
+
|
12
|
+
For the purposes of this project the community will be taken to include:
|
13
|
+
|
14
|
+
- GitHub (make sure you can be contacted through the user name making the commit)
|
15
|
+
- The Online Scout Manager forum
|
16
|
+
|
17
|
+
|
18
|
+
===BSD License
|
19
|
+
Redistribution and use in source and binary forms, with or without modification,
|
20
|
+
are permitted provided that the following conditions are met:
|
21
|
+
|
22
|
+
- Redistributions of source code must retain the above copyright notice,
|
23
|
+
this list of conditions and the following disclaimer.
|
24
|
+
- Redistributions in binary form must reproduce the above copyright notice,
|
25
|
+
this list of conditions and the following disclaimer in the documentation and/or
|
26
|
+
other materials provided with the distribution.
|
27
|
+
- Neither the name of the OSM Extender nor the names of its contributors
|
28
|
+
may be used to endorse or promote products derived from this software
|
29
|
+
without specific prior written permission.
|
30
|
+
|
31
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
|
32
|
+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
33
|
+
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
34
|
+
SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
35
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
36
|
+
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
37
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
38
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
39
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
[](http://badge.fury.io/rb/snmp_table_viewer)
|
2
|
+
[](https://gemnasium.com/robertgauld/snmp_table_viewer)
|
3
|
+
|
4
|
+
Master branch:
|
5
|
+
[](http://travis-ci.org/robertgauld/snmp_table_viewer)
|
6
|
+
[](https://coveralls.io/r/robertgauld/snmp_table_viewer)
|
7
|
+
[](https://codeclimate.com/github/robertgauld/snmp_table_viewer)
|
8
|
+
|
9
|
+
Staging branch:
|
10
|
+
[](http://travis-ci.org/robertgauld/snmp_table_viewer)
|
11
|
+
[](https://coveralls.io/r/robertgauld/snmp_table_viewer)
|
12
|
+
[](https://codeclimate.com/github/robertgauld/snmp_table_viewer)
|
13
|
+
|
14
|
+
|
15
|
+
## Build State
|
16
|
+
This project uses continuous integration to help ensure that a quality product is delivered.
|
17
|
+
Travis CI monitors two branches (versions) of the code - Master (which is what gets released)
|
18
|
+
and Staging (which is what is currently being developed ready for moving to master).
|
19
|
+
|
20
|
+
|
21
|
+
## Ruby Versions
|
22
|
+
This gem supports the following versions of ruby, it may work on other versions but is not tested against them so don't rely on it.
|
23
|
+
|
24
|
+
* 2.3.0
|
25
|
+
* 2.3.1
|
26
|
+
* 2.4.0
|
27
|
+
|
28
|
+
|
29
|
+
## SNMP Table Viewer
|
30
|
+
|
31
|
+
Easily view SNMP tables. The data in the table can be easily converted and formatted in a number of ways.
|
32
|
+
|
33
|
+
|
34
|
+
## Installation
|
35
|
+
|
36
|
+
Add to your Gemfile and run the `bundle` command to install it.
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gem 'snmp_table_viewer', '~> 0.0'
|
40
|
+
```
|
41
|
+
|
42
|
+
|
43
|
+
## Executable
|
44
|
+
|
45
|
+
```
|
46
|
+
Usage: snmp-table-viewer [options]
|
47
|
+
-h, -?, --help Prints this help.
|
48
|
+
--headings HEADINGS Headings to use in the table (e.g. "A, Bc, D").
|
49
|
+
--headings-for TYPE Use headings for this table type (ifTable).
|
50
|
+
--format FORMAT How to format the output (table|csv|json|raw) (default table).
|
51
|
+
--converter CONVERTER A converter to run on the data before formatting (iftable).
|
52
|
+
|
53
|
+
SNMP common options:
|
54
|
+
-v, --version VERSION SNMP version to use (1|2|3|) (default 3).
|
55
|
+
--host HOST The host to connect to.
|
56
|
+
--port PORT p PORT
|
57
|
+
SNMP port to connect to (default 161).
|
58
|
+
--base-oid OID The oid at the start of the table. Can by dotted numbers or ifTable
|
59
|
+
|
60
|
+
SNMP version 1 and 2 options:
|
61
|
+
-c, --comunity COMMUNITY SNMP comunity (default "public").
|
62
|
+
|
63
|
+
SNMP version 3 options:
|
64
|
+
-u, --user, --username USER SNMP user.
|
65
|
+
-l, --security-level LEVEL Security level to use (no_auth|auth_no_priv|auth_priv).
|
66
|
+
-a AUTH_PROTOCOL, Authentication protocol to use (MD5|SHA) (default MD5).
|
67
|
+
--auth-protocol
|
68
|
+
-A AUTH_PASSWORD, Authentication password to use.
|
69
|
+
--auth-password
|
70
|
+
-x PRIV_PROTOCOL, Privacy protocol to use (DES|AES) (default DES).
|
71
|
+
--priv-protocol
|
72
|
+
-X PRIV_PASSWORD, Privacy password to use.
|
73
|
+
--priv-password
|
74
|
+
|
75
|
+
Table formatter options:
|
76
|
+
--[no-]transpose-table Transpose the output table (swap rows and columns).
|
77
|
+
```
|
78
|
+
|
79
|
+
## Documentation & Versioning
|
80
|
+
|
81
|
+
Documentation can be found on [rubydoc.info](http://rubydoc.info/github/robertgauld/snmp_table_viewer/master/frames)
|
82
|
+
|
83
|
+
We follow the [Semantic Versioning](http://semver.org/) concept,
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "rake"
|
2
|
+
require "rubygems"
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require 'rspec/core/rake_task'
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
task default: :spec
|
9
|
+
|
10
|
+
|
11
|
+
namespace :ci do
|
12
|
+
desc "Run the Travis CI tests"
|
13
|
+
task :travis do
|
14
|
+
Rake::Task[:spec].invoke
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,150 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require_relative File.join('..', 'lib', 'snmp_table_viewer')
|
5
|
+
|
6
|
+
def parse_command_line
|
7
|
+
options = {
|
8
|
+
SNMPTableViewer::Formatter::Table => {
|
9
|
+
transpose: false,
|
10
|
+
},
|
11
|
+
snmp: {
|
12
|
+
common: {
|
13
|
+
version: 'v3',
|
14
|
+
host: 'localhost',
|
15
|
+
port: 161,
|
16
|
+
},
|
17
|
+
'v1' => {
|
18
|
+
community: 'public',
|
19
|
+
},
|
20
|
+
'v2' => {
|
21
|
+
community: 'public',
|
22
|
+
},
|
23
|
+
'v3' => {
|
24
|
+
auth_protocol: :md5,
|
25
|
+
priv_protocol: :des,
|
26
|
+
},
|
27
|
+
},
|
28
|
+
base_oid: '',
|
29
|
+
headings: [],
|
30
|
+
formatter: SNMPTableViewer::Formatter::Table,
|
31
|
+
}
|
32
|
+
headings_for = {
|
33
|
+
'ifTable' => ['Index', 'Descr', 'Type', 'Mtu', 'Speed', 'PhysAddress', 'AdminStatus', 'OperStatus', 'LastChange', 'InOctets', 'InUcastPkts', 'InNUcastkts', 'InDiscards', 'InErrors', 'InUnknownPrortos', 'OutOctets', 'OutUcastPkts', 'OutNUcastPkts', 'OutDiscards', 'OutErrors', 'OutQLen', 'Specific'],
|
34
|
+
}
|
35
|
+
formatters = {
|
36
|
+
'table' => SNMPTableViewer::Formatter::Table,
|
37
|
+
'csv' => SNMPTableViewer::Formatter::CSV,
|
38
|
+
'json' => SNMPTableViewer::Formatter::JSON,
|
39
|
+
'raw' => SNMPTableViewer::Formatter::Raw,
|
40
|
+
}
|
41
|
+
converters = {
|
42
|
+
'iftable' => SNMPTableViewer::Converter::IfTable,
|
43
|
+
}
|
44
|
+
base_oids = {
|
45
|
+
'iftable' => '1.3.6.1.2.1.2.2',
|
46
|
+
}
|
47
|
+
snmp_version = 'v3'
|
48
|
+
|
49
|
+
parser = OptionParser.new do |opts|
|
50
|
+
opts.banner = "Usage: snmp-table-viewer [options]"
|
51
|
+
|
52
|
+
opts.on('-h', '--help', '-?', 'Prints this help.') do
|
53
|
+
puts opts
|
54
|
+
exit
|
55
|
+
end
|
56
|
+
|
57
|
+
opts.on('--headings HEADINGS', Array, 'Headings to use in the table (e.g. "A, Bc, D").') do |v|
|
58
|
+
options[:headings] += v.map(&:strip)
|
59
|
+
end
|
60
|
+
|
61
|
+
opts.on('--headings-for TYPE', String, "Use headings for this table type (#{headings_for.keys.join('|')}).") do |v|
|
62
|
+
options[:headings] += headings_for[v] || []
|
63
|
+
end
|
64
|
+
|
65
|
+
opts.on('--format FORMAT', String, "How to format the output (#{formatters.keys.join('|')}) (default table).") do |v|
|
66
|
+
options[:formatter] = formatters[v.downcase]
|
67
|
+
end
|
68
|
+
|
69
|
+
opts.on('--converter CONVERTER', String, "A converter to run on the data before formatting (#{converters.keys.join('|')}).") do |v|
|
70
|
+
options[:converter] = converters[v.downcase]
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
opts.separator "\nSNMP common options:"
|
75
|
+
|
76
|
+
opts.on('-vVERSION', '--version VERSION', 'SNMP version to use (1|2|3|) (default 3).') do |version|
|
77
|
+
snmp_version = "v#{version}"
|
78
|
+
options[:snmp][:common][:version] = snmp_version
|
79
|
+
end
|
80
|
+
|
81
|
+
opts.on('--host HOST', 'The host to connect to.') do |v|
|
82
|
+
options[:snmp][:common][:host] = v
|
83
|
+
end
|
84
|
+
|
85
|
+
opts.on('p PORT', '--port PORT', Integer, 'SNMP port to connect to (default 161).') do |v|
|
86
|
+
options[:snmp][:common][:port] = v
|
87
|
+
end
|
88
|
+
|
89
|
+
opts.on('--base-oid OID', 'The oid at the start of the table. Can by dotted numbers or ifTable') do |v|
|
90
|
+
options[:base_oid] = base_oids[v.downcase] || v
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
opts.separator "\nSNMP version 1 and 2 options:"
|
96
|
+
|
97
|
+
opts.on('-c COMMUNITY', '--comunity COMMUNITY', 'SNMP comunity (default "public").') do |community|
|
98
|
+
options[:snmp][snmp_version][:community] = community
|
99
|
+
end
|
100
|
+
|
101
|
+
|
102
|
+
opts.separator "\nSNMP version 3 options:"
|
103
|
+
|
104
|
+
opts.on('-u USER', '--user USER', '--username USER', 'SNMP user.') do |user|
|
105
|
+
options[:snmp]['v3'][:username] = user
|
106
|
+
end
|
107
|
+
opts.on('-l LEVEL', '--security-level LEVEL', 'Security level to use (no_auth|auth_no_priv|auth_priv).') do |level|
|
108
|
+
options[:snmp]['v3'][:security_level] = level
|
109
|
+
end
|
110
|
+
opts.on('-a AUTH_PROTOCOL', '--auth-protocol AUTH_PROTOCOL', 'Authentication protocol to use (MD5|SHA) (default MD5).') do |value|
|
111
|
+
options[:snmp]['v3'][:auth_protocol] = value.downcase.to_sym
|
112
|
+
end
|
113
|
+
opts.on('-A AUTH_PASSWORD', '--auth-password AUTH_PASSWORD', 'Authentication password to use.', String) do |value|
|
114
|
+
options[:snmp]['v3'][:auth_password] = value
|
115
|
+
end
|
116
|
+
opts.on('-x PRIV_PROTOCOL', '--priv-protocol PRIV_PROTOCOL', 'Privacy protocol to use (DES|AES) (default DES).') do |value|
|
117
|
+
options[:snmp]['v3'][:priv_protocol] = value.downcase.to_sym
|
118
|
+
end
|
119
|
+
opts.on('-X PRIV_PASSWORD', '--priv-password PRIV_PASSWORD', 'Privacy password to use.', String) do |value|
|
120
|
+
options[:snmp]['v3'][:priv_password] = value
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
opts.separator "\nTable formatter options:"
|
125
|
+
opts.on('--[no-]transpose-table', 'Transpose the output table (swap rows and columns).') do |v|
|
126
|
+
options[SNMPTableViewer::Formatter::Table][:transpose] = v
|
127
|
+
end
|
128
|
+
|
129
|
+
end # create parser
|
130
|
+
|
131
|
+
parser.parse!(ARGV)
|
132
|
+
options
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
options = parse_command_line
|
139
|
+
snmp_options = options[:snmp][:common].clone
|
140
|
+
snmp_options.merge!(options[:snmp][snmp_options[:version]])
|
141
|
+
|
142
|
+
data = SNMPTableViewer::Fetcher.fetch(base_oid: options[:base_oid], **snmp_options)
|
143
|
+
|
144
|
+
converter = options[:converter]
|
145
|
+
data = converter.convert(data) unless converter.nil?
|
146
|
+
|
147
|
+
formatter = options[:formatter]
|
148
|
+
formatter_options = options[formatter] || {}
|
149
|
+
formatter = formatter.new(data: data, headings: options[:headings])
|
150
|
+
puts formatter.output(**formatter_options)
|