netsnmp 0.2.0 → 0.5.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/sig/scoped_pdu.rbs CHANGED
@@ -1,6 +1,8 @@
1
1
  module NETSNMP
2
2
  class ScopedPDU < PDU
3
3
  attr_reader engine_id: String
4
+ attr_reader auth_param: String?
5
+ attr_reader security_level: Integer?
4
6
 
5
7
  private
6
8
 
@@ -1,5 +1,7 @@
1
1
  module NETSNMP
2
2
  class SecurityParameters
3
+ prepend Loggable
4
+
3
5
  type security_level = :noauth | :auth_no_priv | :auth_priv | 0 | 1 | 3 | nil
4
6
 
5
7
  type auth_protocol = :md5 | :sha
@@ -21,11 +23,11 @@ module NETSNMP
21
23
 
22
24
  def encode: (_ToAsn, salt: OpenSSL::ASN1::ASN1Data, engine_time: Integer, engine_boots: Integer) -> [OpenSSL::ASN1::ASN1Data, OpenSSL::ASN1::ASN1Data]
23
25
 
24
- def decode: (OpenSSL::ASN1::ASN1Data | String der, salt: OpenSSL::ASN1::ASN1Data | String, engine_time: Integer, engine_boots: Integer) -> OpenSSL::ASN1::ASN1Data
26
+ def decode: (OpenSSL::ASN1::ASN1Data | String der, salt: OpenSSL::ASN1::ASN1Data | String, engine_time: Integer, engine_boots: Integer, ?security_level: Integer?) -> OpenSSL::ASN1::ASN1Data
25
27
 
26
28
  def sign: (String message) -> String?
27
29
 
28
- def verify: (String stream, String salt) -> void
30
+ def verify: (String stream, String salt, ?security_level: Integer?) -> void
29
31
 
30
32
  def must_revalidate?: () -> bool
31
33
 
data/sig/session.rbs CHANGED
@@ -1,5 +1,7 @@
1
1
  module NETSNMP
2
2
  class Session
3
+ prepend Loggable
4
+
3
5
  @transport: _Transport
4
6
  @version: 0 | 1 | 3
5
7
  @community: String?
data/spec/client_spec.rb CHANGED
@@ -22,7 +22,7 @@ RSpec.describe NETSNMP::Client do
22
22
  let(:get_oid) { "1.3.6.1.2.1.1.5.0" }
23
23
  let(:next_oid) { "1.3.6.1.2.1.1.6.0" }
24
24
  let(:walk_oid) { "1.3.6.1.2.1.1" }
25
- let(:set_oid) { "1.3.6.1.2.1.1.3.0" } # sysUpTimeInstance
25
+ let(:set_oid) { "sysUpTime.0" } # sysUpTimeInstance
26
26
  let(:get_result) { "DEVICE-192.168.1.1" }
27
27
  let(:next_result) { "The Cloud" }
28
28
  let(:walk_result) do
@@ -48,10 +48,10 @@ RSpec.describe NETSNMP::Client do
48
48
  community: "public"
49
49
  }
50
50
  end
51
- let(:get_oid) { "1.3.6.1.2.1.1.5.0" }
51
+ let(:get_oid) { "sysName.0" }
52
52
  let(:next_oid) { "1.3.6.1.2.1.1.6.0" }
53
- let(:walk_oid) { "1.3.6.1.2.1.1" }
54
- let(:set_oid) { "1.3.6.1.2.1.1.3.0" }
53
+ let(:walk_oid) { "system" }
54
+ let(:set_oid) { "sysUpTime.0" }
55
55
  let(:get_result) { "DEVICE-192.168.1.1" }
56
56
  let(:next_result) { "The Cloud" }
57
57
  let(:walk_result) do
@@ -67,6 +67,24 @@ RSpec.describe NETSNMP::Client do
67
67
  WALK
68
68
  end
69
69
  let(:set_oid_result) { 43 }
70
+
71
+ context "when the returned value is a hex-string" do
72
+ let(:protocol_options) do
73
+ {
74
+ version: "2c",
75
+ community: "foreignformats/winxp1"
76
+ }
77
+ end
78
+ let(:hex_get_oid) { "1.3.6.1.2.1.25.3.7.1.3.10.1" }
79
+ let(:hex_get_result) { "\x01\x00\x00\x00" }
80
+ let(:hex_get_output) { "01 00 00 00" }
81
+ let(:value) { subject.get(oid: hex_get_oid) }
82
+
83
+ it "returns the string, which outputs the hex-representation" do
84
+ expect(value).to eq(hex_get_result)
85
+ expect(value.inspect).to include(hex_get_output)
86
+ end
87
+ end
70
88
  end
71
89
  end
72
90
 
@@ -78,9 +96,9 @@ RSpec.describe NETSNMP::Client do
78
96
  context: "a172334d7d97871b72241397f713fa12"
79
97
  }
80
98
  end
81
- let(:get_oid) { "1.3.6.1.2.1.1.5.0" }
99
+ let(:get_oid) { "sysName.0" }
82
100
  let(:next_oid) { "1.3.6.1.2.1.1.6.0" }
83
- let(:set_oid) { "1.3.6.1.2.1.1.3.0" } # sysUpTimeInstance
101
+ let(:set_oid) { "sysUpTime.0" } # sysUpTimeInstance
84
102
  let(:walk_oid) { "1.3.6.1.2.1.1.9.1.3" }
85
103
  let(:get_result) { "tt" }
86
104
  let(:next_result) { "KK12" }
@@ -159,6 +177,18 @@ RSpec.describe NETSNMP::Client do
159
177
  end
160
178
  it_behaves_like "an snmp client" do
161
179
  let(:protocol_options) { version_options.merge(user_options).merge(extra_options) }
180
+
181
+ context "with wrong auth password and wrong encrypting password" do
182
+ let(:user_options) do
183
+ { username: "authprivmd5des", auth_password: "wrongpassword",
184
+ auth_protocol: :md5, priv_password: "maplesyrup",
185
+ priv_protocol: :des }
186
+ end
187
+ let(:protocol_options) { version_options.merge(user_options).merge(extra_options) }
188
+ it "raises authentication error" do
189
+ expect { subject.get(oid: get_oid) }.to raise_error(NETSNMP::Error, "Authentication failure (incorrect password, community or key)")
190
+ end
191
+ end
162
192
  end
163
193
  end
164
194
 
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/spec_helper.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ GC.auto_compact = true if GC.respond_to?(:auto_compact=)
4
+
3
5
  if ENV.key?("CI")
4
6
  require "simplecov"
5
7
  SimpleCov.command_name "#{RUBY_ENGINE}-#{RUBY_VERSION}"
@@ -8,7 +10,6 @@ end
8
10
 
9
11
  if defined?(SimpleCov)
10
12
  SimpleCov.start do
11
- minimum_coverage 85
12
13
  add_filter ".bundle"
13
14
  add_filter "/spec/"
14
15
  end
@@ -26,7 +26,7 @@ module CelluloidHelpers
26
26
  end
27
27
  end
28
28
 
29
- class Proxy < NETSNMP::Session::Transport
29
+ class Proxy
30
30
  MAXPDUSIZE = 0xffff + 1
31
31
 
32
32
  def initialize(host, port)
@@ -35,18 +35,22 @@ module CelluloidHelpers
35
35
  @timeout = 2
36
36
  end
37
37
 
38
- def close
39
- @socket.close
38
+ def send(payload)
39
+ @socket.send(payload, 0)
40
+ recv
40
41
  end
41
42
 
42
- private
43
-
44
- def wait(mode)
43
+ def recv(bytesize = MAXPDUSIZE)
45
44
  Celluloid.timeout(@timeout) do
46
- @socket.__send__(mode)
45
+ datagram, = @socket.recvfrom(bytesize)
46
+ datagram
47
47
  end
48
48
  rescue Celluloid::TaskTimeout
49
49
  raise Timeout::Error, "Timeout after #{@timeout} seconds"
50
50
  end
51
+
52
+ def close
53
+ @socket.close
54
+ end
51
55
  end
52
56
  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,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsnmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-18 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2021-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: parslet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: |2
14
28
  Wraps the net-snmp core usage into idiomatic ruby.
15
29
  It is designed to support as many environments and concurrency frameworks as possible.
@@ -27,7 +41,11 @@ files:
27
41
  - lib/netsnmp/encryption/des.rb
28
42
  - lib/netsnmp/encryption/none.rb
29
43
  - lib/netsnmp/errors.rb
44
+ - lib/netsnmp/extensions.rb
45
+ - lib/netsnmp/loggable.rb
30
46
  - lib/netsnmp/message.rb
47
+ - lib/netsnmp/mib.rb
48
+ - lib/netsnmp/mib/parser.rb
31
49
  - lib/netsnmp/oid.rb
32
50
  - lib/netsnmp/pdu.rb
33
51
  - lib/netsnmp/scoped_pdu.rb
@@ -38,7 +56,10 @@ files:
38
56
  - lib/netsnmp/varbind.rb
39
57
  - lib/netsnmp/version.rb
40
58
  - sig/client.rbs
59
+ - sig/loggable.rbs
41
60
  - sig/message.rbs
61
+ - sig/mib.rbs
62
+ - sig/mib/parser.rbs
42
63
  - sig/netsnmp.rbs
43
64
  - sig/oid.rbs
44
65
  - sig/openssl.rbs
@@ -51,6 +72,7 @@ files:
51
72
  - sig/varbind.rbs
52
73
  - spec/client_spec.rb
53
74
  - spec/handlers/celluloid_spec.rb
75
+ - spec/mib_spec.rb
54
76
  - spec/oid_spec.rb
55
77
  - spec/pdu_spec.rb
56
78
  - spec/security_parameters_spec.rb
@@ -82,20 +104,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
104
  version: '0'
83
105
  requirements:
84
106
  - net-snmp
85
- rubygems_version: 3.1.4
107
+ rubygems_version: 3.2.15
86
108
  signing_key:
87
109
  specification_version: 4
88
110
  summary: SNMP Client library
89
111
  test_files:
90
- - spec/timeticks_spec.rb
91
- - spec/spec_helper.rb
92
- - spec/session_spec.rb
93
112
  - spec/client_spec.rb
113
+ - spec/handlers/celluloid_spec.rb
114
+ - spec/mib_spec.rb
94
115
  - spec/oid_spec.rb
95
- - spec/varbind_spec.rb
96
- - spec/support/request_examples.rb
97
- - spec/support/celluloid.rb
98
116
  - spec/pdu_spec.rb
99
117
  - spec/security_parameters_spec.rb
118
+ - spec/session_spec.rb
119
+ - spec/spec_helper.rb
120
+ - spec/support/celluloid.rb
121
+ - spec/support/request_examples.rb
122
+ - spec/timeticks_spec.rb
100
123
  - spec/v3_session_spec.rb
101
- - spec/handlers/celluloid_spec.rb
124
+ - spec/varbind_spec.rb