netsnmp 0.1.8 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +60 -27
  3. data/lib/netsnmp.rb +3 -21
  4. data/lib/netsnmp/client.rb +4 -5
  5. data/lib/netsnmp/encryption/aes.rb +1 -3
  6. data/lib/netsnmp/encryption/des.rb +0 -2
  7. data/lib/netsnmp/errors.rb +1 -0
  8. data/lib/netsnmp/extensions.rb +113 -0
  9. data/lib/netsnmp/loggable.rb +36 -0
  10. data/lib/netsnmp/message.rb +70 -28
  11. data/lib/netsnmp/mib.rb +172 -0
  12. data/lib/netsnmp/mib/parser.rb +750 -0
  13. data/lib/netsnmp/oid.rb +7 -12
  14. data/lib/netsnmp/pdu.rb +23 -12
  15. data/lib/netsnmp/scoped_pdu.rb +8 -2
  16. data/lib/netsnmp/security_parameters.rb +22 -14
  17. data/lib/netsnmp/session.rb +14 -16
  18. data/lib/netsnmp/v3_session.rb +21 -9
  19. data/lib/netsnmp/varbind.rb +27 -22
  20. data/lib/netsnmp/version.rb +1 -1
  21. data/sig/client.rbs +24 -0
  22. data/sig/loggable.rbs +16 -0
  23. data/sig/message.rbs +9 -0
  24. data/sig/mib.rbs +21 -0
  25. data/sig/mib/parser.rbs +7 -0
  26. data/sig/netsnmp.rbs +19 -0
  27. data/sig/oid.rbs +18 -0
  28. data/sig/openssl.rbs +20 -0
  29. data/sig/pdu.rbs +48 -0
  30. data/sig/scoped_pdu.rbs +15 -0
  31. data/sig/security_parameters.rbs +58 -0
  32. data/sig/session.rbs +38 -0
  33. data/sig/timeticks.rbs +7 -0
  34. data/sig/v3_session.rbs +21 -0
  35. data/sig/varbind.rbs +30 -0
  36. data/spec/client_spec.rb +26 -8
  37. data/spec/handlers/celluloid_spec.rb +4 -3
  38. data/spec/mib_spec.rb +13 -0
  39. data/spec/session_spec.rb +2 -2
  40. data/spec/spec_helper.rb +9 -5
  41. data/spec/support/request_examples.rb +2 -2
  42. data/spec/v3_session_spec.rb +4 -4
  43. data/spec/varbind_spec.rb +5 -3
  44. metadata +31 -71
  45. data/.coveralls.yml +0 -1
  46. data/.gitignore +0 -14
  47. data/.rspec +0 -2
  48. data/.rubocop.yml +0 -11
  49. data/.rubocop_todo.yml +0 -69
  50. data/.travis.yml +0 -28
  51. data/Gemfile +0 -22
  52. data/Rakefile +0 -30
  53. data/netsnmp.gemspec +0 -31
  54. data/spec/support/Dockerfile +0 -14
  55. data/spec/support/specs.sh +0 -51
  56. data/spec/support/stop_docker.sh +0 -5
@@ -4,7 +4,7 @@ require "celluloid/io"
4
4
  require_relative "../support/request_examples"
5
5
  require_relative "../support/celluloid"
6
6
 
7
- RSpec.describe "with cellulloid", type: :celluloid do
7
+ RSpec.describe "with cellulloid", type: :celluloid, if: RUBY_ENGINE == "truffleruby" do
8
8
  include CelluloidHelpers
9
9
  let(:user_options) do
10
10
  { username: "authprivmd5des", auth_password: "maplesyrup",
@@ -31,14 +31,15 @@ RSpec.describe "with cellulloid", type: :celluloid do
31
31
  WALK
32
32
  end
33
33
 
34
+ before(:all) { Celluloid.boot }
34
35
  around(:each) do |example|
35
36
  within_io_actor { example.run }
36
37
  end
37
- let(:proxy) { CelluloidHelpers::Proxy.new("localhost", SNMPPORT) }
38
+ let(:proxy) { CelluloidHelpers::Proxy.new(SNMPHOST, SNMPPORT) }
38
39
  after(:each) { proxy.close }
39
40
 
40
41
  it_behaves_like "an snmp client" do
41
- subject { NETSNMP::Client.new(options) }
42
+ subject { NETSNMP::Client.new(**options) }
42
43
  let(:device_options) { { proxy: proxy } }
43
44
  let(:protocol_options) { user_options }
44
45
  let(:extra_options) { { version: 3, context: "a172334d7d97871b72241397f713fa12" } }
data/spec/mib_spec.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe NETSNMP::MIB do
4
+ describe ".oid" do
5
+ it { expect(described_class.oid("1.2.3.4")).to eq("1.2.3.4") }
6
+ it { expect(described_class.oid("ifTable")).to eq("1.3.6.1.2.1.2.2") }
7
+ it { expect(described_class.oid("sysDescr.0")).to eq("1.3.6.1.2.1.1.1.0") }
8
+ it { expect(described_class.oid("ifTable.1.23")).to eq("1.3.6.1.2.1.2.2.1.23") }
9
+ it { expect(described_class.oid("IF-MIB::ifTable.1.23")).to eq("1.3.6.1.2.1.2.2.1.23") }
10
+ it { expect(described_class.oid("IFMIB::ifTable.1.23")).to be_nil }
11
+ it { expect(described_class.oid("IF-MIB::")).to be_nil }
12
+ end
13
+ end
data/spec/session_spec.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe NETSNMP::Session do
4
- let(:host) { "localhost" }
4
+ let(:host) { SNMPHOST }
5
5
  let(:options) do
6
6
  {
7
7
  version: "2c",
@@ -9,6 +9,6 @@ RSpec.describe NETSNMP::Session do
9
9
  port: SNMPPORT
10
10
  }
11
11
  end
12
- subject { described_class.new(host, options) }
12
+ subject { described_class.new(host: host, **options) }
13
13
  after { subject.close }
14
14
  end
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "simplecov" if ENV["COVERAGE"]
4
- require "coveralls"
5
- Coveralls.wear!
3
+ GC.auto_compact = true if GC.respond_to?(:auto_compact=)
4
+
5
+ if ENV.key?("CI")
6
+ require "simplecov"
7
+ SimpleCov.command_name "#{RUBY_ENGINE}-#{RUBY_VERSION}"
8
+ SimpleCov.coverage_dir "coverage/#{RUBY_ENGINE}-#{RUBY_VERSION}"
9
+ end
6
10
 
7
11
  if defined?(SimpleCov)
8
12
  SimpleCov.start do
9
- minimum_coverage 85
10
13
  add_filter ".bundle"
11
14
  add_filter "/spec/"
12
15
  end
@@ -17,7 +20,8 @@ Bundler.require(:default, :test)
17
20
 
18
21
  require "netsnmp"
19
22
 
20
- SNMPPORT = (ENV["SNMP_PORT"] || 1161).to_i
23
+ SNMPPORT = ENV.fetch("SNMP_PORT", 1161).to_i
24
+ SNMPHOST = ENV.fetch("SNMP_HOST", "localhost")
21
25
 
22
26
  # This file was generated by the `rspec --init` command. Conventionally, all
23
27
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -3,7 +3,7 @@
3
3
  RSpec.shared_examples "an snmp client" do
4
4
  let(:device_options) do
5
5
  {
6
- host: "localhost",
6
+ host: SNMPHOST,
7
7
  port: SNMPPORT
8
8
  }
9
9
  end
@@ -11,7 +11,7 @@ RSpec.shared_examples "an snmp client" do
11
11
  let(:extra_options) { {} }
12
12
  let(:options) { protocol_options.merge(device_options).merge(extra_options) }
13
13
 
14
- subject { described_class.new(options) }
14
+ subject { described_class.new(**options) }
15
15
 
16
16
  describe "#get" do
17
17
  let(:value) { subject.get(oid: get_oid) }
@@ -7,19 +7,19 @@ RSpec.describe NETSNMP::V3Session do
7
7
  priv_protocol: :des, security_level: :auth_priv }
8
8
  end
9
9
  it "generates the security parameters handler" do
10
- sess = described_class.new(security_options.merge(host: "localhost", port: SNMPPORT))
10
+ sess = described_class.new(**security_options.merge(host: SNMPHOST, port: SNMPPORT))
11
11
  # not generated yet
12
12
  expect(sess.instance_variable_get(:@security_parameters)).to be_a(NETSNMP::SecurityParameters)
13
13
  end
14
14
 
15
15
  it "allows to pass a custom one" do
16
- sec_params = NETSNMP::SecurityParameters.new(security_options)
17
- sess = described_class.new(host: "localhost", port: SNMPPORT, security_parameters: sec_params)
16
+ sec_params = NETSNMP::SecurityParameters.new(**security_options)
17
+ sess = described_class.new(host: SNMPHOST, port: SNMPPORT, security_parameters: sec_params)
18
18
  # not generated yet
19
19
  expect(sess.instance_variable_get(:@security_parameters)).to be(sec_params)
20
20
  end
21
21
 
22
22
  it "fails if the pass object doesn't follow the expected api" do
23
- expect { described_class.new(host: "localhost", port: SNMPPORT, security_parameters: double) }.to raise_error(NETSNMP::Error)
23
+ expect { described_class.new(host: SNMPHOST, port: SNMPPORT, security_parameters: double) }.to raise_error(NETSNMP::Error)
24
24
  end
25
25
  end
data/spec/varbind_spec.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe NETSNMP::Varbind do
4
+ using NETSNMP::StringExtensions
5
+
4
6
  describe "#to_der" do
5
7
  it { expect(described_class.new(".1.3.6.1.2.1.1.1.0").to_der).to eq("0\f\006\b+\006\001\002\001\001\001\000\005\000".b) }
6
8
 
@@ -25,7 +27,7 @@ RSpec.describe NETSNMP::Varbind do
25
27
  gauge = 127
26
28
  varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :gauge, value: gauge)
27
29
  value_str = varbind.to_der[12..-1]
28
- header = value_str[0].unpack("B8").first
30
+ header = value_str[0].unpack1("B8")
29
31
 
30
32
  # Class: Primitive Application
31
33
  expect(header[0..1]).to eq("01")
@@ -43,7 +45,7 @@ RSpec.describe NETSNMP::Varbind do
43
45
  gauge = 128
44
46
  varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :gauge, value: gauge)
45
47
  value_str = varbind.to_der[12..-1]
46
- header = value_str[0].unpack("B8").first
48
+ header = value_str[0].unpack1("B8")
47
49
 
48
50
  # Class: Primitive Application
49
51
  expect(header[0..1]).to eq("01")
@@ -61,7 +63,7 @@ RSpec.describe NETSNMP::Varbind do
61
63
  gauge = 805
62
64
  varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :gauge, value: gauge)
63
65
  value_str = varbind.to_der[12..-1]
64
- header = value_str[0].unpack("B8").first
66
+ header = value_str[0].unpack1("B8")
65
67
 
66
68
  # Class: Primitive Application
67
69
  expect(header[0..1]).to eq("01")
metadata CHANGED
@@ -1,75 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsnmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-07 00:00:00.000000000 Z
11
+ date: 2021-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
14
+ name: parslet
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 10.1.0
20
- - - "~>"
21
- - !ruby/object:Gem::Version
22
- version: '10.1'
23
- type: :development
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- version: 10.1.0
30
- - - "~>"
31
- - !ruby/object:Gem::Version
32
- version: '10.1'
33
- - !ruby/object:Gem::Dependency
34
- name: rspec
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - ">="
38
- - !ruby/object:Gem::Version
39
- version: 3.5.0
40
- - - "~>"
41
- - !ruby/object:Gem::Version
42
- version: '3.5'
43
- type: :development
19
+ version: '0'
20
+ type: :runtime
44
21
  prerelease: false
45
22
  version_requirements: !ruby/object:Gem::Requirement
46
23
  requirements:
47
24
  - - ">="
48
25
  - !ruby/object:Gem::Version
49
- version: 3.5.0
50
- - - "~>"
51
- - !ruby/object:Gem::Version
52
- version: '3.5'
53
- - !ruby/object:Gem::Dependency
54
- name: celluloid-io
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '0.17'
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: 0.17.2
63
- type: :development
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - "~>"
68
- - !ruby/object:Gem::Version
69
- version: '0.17'
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- version: 0.17.2
26
+ version: '0'
73
27
  description: |2
74
28
  Wraps the net-snmp core usage into idiomatic ruby.
75
29
  It is designed to support as many environments and concurrency frameworks as possible.
@@ -78,24 +32,20 @@ executables: []
78
32
  extensions: []
79
33
  extra_rdoc_files: []
80
34
  files:
81
- - ".coveralls.yml"
82
- - ".gitignore"
83
- - ".rspec"
84
- - ".rubocop.yml"
85
- - ".rubocop_todo.yml"
86
- - ".travis.yml"
87
35
  - AUTHORS
88
- - Gemfile
89
36
  - LICENSE.txt
90
37
  - README.md
91
- - Rakefile
92
38
  - lib/netsnmp.rb
93
39
  - lib/netsnmp/client.rb
94
40
  - lib/netsnmp/encryption/aes.rb
95
41
  - lib/netsnmp/encryption/des.rb
96
42
  - lib/netsnmp/encryption/none.rb
97
43
  - lib/netsnmp/errors.rb
44
+ - lib/netsnmp/extensions.rb
45
+ - lib/netsnmp/loggable.rb
98
46
  - lib/netsnmp/message.rb
47
+ - lib/netsnmp/mib.rb
48
+ - lib/netsnmp/mib/parser.rb
99
49
  - lib/netsnmp/oid.rb
100
50
  - lib/netsnmp/pdu.rb
101
51
  - lib/netsnmp/scoped_pdu.rb
@@ -105,19 +55,31 @@ files:
105
55
  - lib/netsnmp/v3_session.rb
106
56
  - lib/netsnmp/varbind.rb
107
57
  - lib/netsnmp/version.rb
108
- - netsnmp.gemspec
58
+ - sig/client.rbs
59
+ - sig/loggable.rbs
60
+ - sig/message.rbs
61
+ - sig/mib.rbs
62
+ - sig/mib/parser.rbs
63
+ - sig/netsnmp.rbs
64
+ - sig/oid.rbs
65
+ - sig/openssl.rbs
66
+ - sig/pdu.rbs
67
+ - sig/scoped_pdu.rbs
68
+ - sig/security_parameters.rbs
69
+ - sig/session.rbs
70
+ - sig/timeticks.rbs
71
+ - sig/v3_session.rbs
72
+ - sig/varbind.rbs
109
73
  - spec/client_spec.rb
110
74
  - spec/handlers/celluloid_spec.rb
75
+ - spec/mib_spec.rb
111
76
  - spec/oid_spec.rb
112
77
  - spec/pdu_spec.rb
113
78
  - spec/security_parameters_spec.rb
114
79
  - spec/session_spec.rb
115
80
  - spec/spec_helper.rb
116
- - spec/support/Dockerfile
117
81
  - spec/support/celluloid.rb
118
82
  - spec/support/request_examples.rb
119
- - spec/support/specs.sh
120
- - spec/support/stop_docker.sh
121
83
  - spec/timeticks_spec.rb
122
84
  - spec/v3_session_spec.rb
123
85
  - spec/varbind_spec.rb
@@ -126,7 +88,7 @@ licenses:
126
88
  - Apache-2.0
127
89
  metadata:
128
90
  allowed_push_host: https://rubygems.org/
129
- post_install_message:
91
+ post_install_message:
130
92
  rdoc_options: []
131
93
  require_paths:
132
94
  - lib
@@ -142,23 +104,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
104
  version: '0'
143
105
  requirements:
144
106
  - net-snmp
145
- rubygems_version: 3.0.6
146
- signing_key:
107
+ rubygems_version: 3.2.15
108
+ signing_key:
147
109
  specification_version: 4
148
110
  summary: SNMP Client library
149
111
  test_files:
150
112
  - spec/client_spec.rb
151
113
  - spec/handlers/celluloid_spec.rb
114
+ - spec/mib_spec.rb
152
115
  - spec/oid_spec.rb
153
116
  - spec/pdu_spec.rb
154
117
  - spec/security_parameters_spec.rb
155
118
  - spec/session_spec.rb
156
119
  - spec/spec_helper.rb
157
- - spec/support/Dockerfile
158
120
  - spec/support/celluloid.rb
159
121
  - spec/support/request_examples.rb
160
- - spec/support/specs.sh
161
- - spec/support/stop_docker.sh
162
122
  - spec/timeticks_spec.rb
163
123
  - spec/v3_session_spec.rb
164
124
  - spec/varbind_spec.rb
data/.coveralls.yml DELETED
@@ -1 +0,0 @@
1
- service_name: travis-ci
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /coverage/
2
- /doc/
3
- /pkg/
4
- /tmp/
5
- /log/
6
- /.yardoc/
7
- /.bundle
8
- /Gemfile.lock
9
- /vendor
10
- .env
11
-
12
- *.DS_Store
13
- *.sw[po]
14
- *.nfs*
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,11 +0,0 @@
1
- inherit_from: .rubocop_todo.yml
2
-
3
- AllCops:
4
- TargetRubyVersion: 2.3
5
-
6
- Layout/IndentHeredoc:
7
- Enabled: false
8
-
9
- Style/NumericPredicate:
10
- Exclude:
11
- - lib/netsnmp.rb
data/.rubocop_todo.yml DELETED
@@ -1,69 +0,0 @@
1
- # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2018-02-07 22:49:11 +0000 using RuboCop version 0.52.1.
4
- # The point is for the user to remove these configuration records
5
- # one by one as the offenses are removed from the code base.
6
- # Note that changes in the inspected code, or installation of new
7
- # versions of RuboCop, may require this file to be generated again.
8
-
9
- Metrics/BlockLength:
10
- Max: 200
11
-
12
- # Offense count: 17
13
- Metrics/AbcSize:
14
- Max: 100
15
-
16
- # Offense count: 2
17
- # Configuration parameters: CountComments.
18
- Metrics/ClassLength:
19
- Max: 150
20
-
21
- # Offense count: 8
22
- Metrics/CyclomaticComplexity:
23
- Max: 20
24
-
25
- # Offense count: 22
26
- # Configuration parameters: CountComments.
27
- Metrics/MethodLength:
28
- Max: 50
29
-
30
- # Offense count: 2
31
- # Configuration parameters: CountKeywordArgs.
32
- Metrics/ParameterLists:
33
- Max: 7
34
-
35
- # Offense count: 1
36
- Metrics/PerceivedComplexity:
37
- Max: 9
38
-
39
- # Offense count: 10
40
- Style/Documentation:
41
- Exclude:
42
- - 'spec/**/*'
43
- - 'test/**/*'
44
- - 'lib/netsnmp.rb'
45
- - 'lib/netsnmp/encryption/aes.rb'
46
- - 'lib/netsnmp/encryption/des.rb'
47
- - 'lib/netsnmp/encryption/none.rb'
48
- - 'lib/netsnmp/scoped_pdu.rb'
49
- - 'lib/netsnmp/session.rb'
50
- - 'lib/netsnmp/timeticks.rb'
51
-
52
- # Offense count: 8
53
- # Cop supports --auto-correct.
54
- # Configuration parameters: Strict.
55
- Style/NumericLiterals:
56
- MinDigits: 11
57
-
58
- # Offense count: 264
59
- # Cop supports --auto-correct.
60
- # Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
61
- # SupportedStyles: single_quotes, double_quotes
62
- Style/StringLiterals:
63
- EnforcedStyle: double_quotes
64
-
65
- # Offense count: 112
66
- # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
67
- # URISchemes: http, https
68
- Metrics/LineLength:
69
- Max: 189