netsnmp 0.1.3 → 0.1.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.
@@ -1,8 +1,8 @@
1
- FROM python:2
2
- Maintainer Tiago Cardoso <tiago.cardoso@swisscom.com>
1
+ FROM python:2.7-alpine
2
+ Maintainer Tiago Cardoso <cardoso_tiago@hotmail.com>
3
3
 
4
4
  RUN easy_install snmpsim==0.3.0
5
- RUN easy_install pycrypto
5
+ RUN easy_install pycrypto==2.6.1
6
6
  EXPOSE 1161
7
7
  # Create non-privileged user
8
8
  RUN useradd -m snmp_server
@@ -1,31 +1,37 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copied from celluloid-io spec helpers
2
4
  module CelluloidHelpers
3
5
  class WrapperActor
4
6
  include ::Celluloid::IO
5
7
  execute_block_on_receiver :wrap
6
-
8
+
7
9
  def wrap
8
10
  yield
9
11
  end
10
12
  end
11
-
13
+
12
14
  def with_wrapper_actor
13
15
  WrapperActor.new
14
16
  end
17
+
15
18
  def within_io_actor(&block)
16
19
  actor = WrapperActor.new
17
20
  actor.wrap(&block)
18
21
  ensure
19
- actor.terminate if actor.alive? rescue nil
22
+ begin
23
+ actor.terminate if actor.alive?
24
+ rescue StandardError
25
+ nil
26
+ end
20
27
  end
21
28
 
22
-
23
29
  class Proxy < NETSNMP::Session::Transport
24
30
  MAXPDUSIZE = 0xffff + 1
25
31
 
26
32
  def initialize(host, port)
27
33
  @socket = Celluloid::IO::UDPSocket.new
28
- @socket.connect( host, port )
34
+ @socket.connect(host, port)
29
35
  @timeout = 2
30
36
  end
31
37
 
@@ -34,6 +40,7 @@ module CelluloidHelpers
34
40
  end
35
41
 
36
42
  private
43
+
37
44
  def wait(mode)
38
45
  Celluloid.timeout(@timeout) do
39
46
  @socket.__send__(mode)
@@ -41,6 +48,5 @@ module CelluloidHelpers
41
48
  rescue Celluloid::TaskTimeout
42
49
  raise Timeout::Error, "Timeout after #{@timeout} seconds"
43
50
  end
44
-
45
51
  end
46
52
  end
@@ -1,10 +1,14 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.shared_examples "an snmp client" do
2
- let(:device_options) { {
3
- host: "localhost",
4
- port: SNMPPORT
5
- } }
6
- let(:protocol_options) { { } }
7
- let(:extra_options) { { } }
4
+ let(:device_options) do
5
+ {
6
+ host: "localhost",
7
+ port: SNMPPORT
8
+ }
9
+ end
10
+ let(:protocol_options) { {} }
11
+ let(:extra_options) { {} }
8
12
  let(:options) { protocol_options.merge(device_options).merge(extra_options) }
9
13
 
10
14
  subject { described_class.new(options) }
@@ -14,6 +18,14 @@ RSpec.shared_examples "an snmp client" do
14
18
  it "fetches the varbinds for a given oid" do
15
19
  expect(value).to eq(get_result)
16
20
  end
21
+ context "with multiple oids" do
22
+ let(:value) { subject.get({ oid: get_oid }, oid: next_oid) }
23
+ it "returns the values for both" do
24
+ expect(value).to be_a(Array)
25
+ expect(value).to include(/#{get_result}/)
26
+ expect(value).to include(/#{next_result}/)
27
+ end
28
+ end
17
29
  end
18
30
 
19
31
  describe "#get_next" do
@@ -28,9 +40,8 @@ RSpec.shared_examples "an snmp client" do
28
40
  describe "#walk" do
29
41
  let(:value) { subject.walk(oid: walk_oid) }
30
42
  it "fetches the varbinds for the next oid" do
31
- values = value.map {|oid, val| "#{oid}: #{val}" }.join("\n") << "\n"
43
+ values = value.map { |oid, val| "#{oid}: #{val}" }.join("\n") << "\n"
32
44
  expect(values).to eq(walk_result)
33
45
  end
34
46
  end
35
-
36
47
  end
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env bash
2
+ function start {
3
+ docker pull honeyryderchuck/snmp-server-emulator:latest
4
+ docker run -d -p :1161/udp --name test-snmp -v $(pwd)/spec/support/snmpsim:/home/snmp_server/.snmpsim honeyryderchuck/snmp-server-emulator \
5
+ --v3-engine-id=000000000000000000000002 \
6
+ --agent-udpv4-endpoint=0.0.0.0:1161 --agent-udpv6-endpoint='[::0]:1161' \
7
+ --v3-user=simulator --v3-auth-key=auctoritas --v3-priv-key=privatus \
8
+ --v3-user=authmd5 --v3-auth-key=maplesyrup --v3-auth-proto=MD5 --v3-priv-proto=NONE \
9
+ --v3-user=authsha --v3-auth-key=maplesyrup --v3-auth-proto=SHA --v3-priv-proto=NONE \
10
+ --v3-user=authprivshaaes --v3-auth-key=maplesyrup --v3-auth-proto=SHA \
11
+ --v3-priv-key=maplesyrup --v3-priv-proto=AES \
12
+ --v3-user=authprivmd5aes --v3-auth-key=maplesyrup --v3-auth-proto=MD5 \
13
+ --v3-priv-key=maplesyrup --v3-priv-proto=AES \
14
+ --v3-user=authprivshades --v3-auth-key=maplesyrup --v3-auth-proto=SHA \
15
+ --v3-priv-key=maplesyrup --v3-priv-proto=DES \
16
+ --v3-user=authprivmd5des --v3-auth-key=maplesyrup --v3-auth-proto=MD5 \
17
+ --v3-priv-key=maplesyrup --v3-priv-proto=DES \
18
+ --v3-user=unsafe --v3-auth-proto=NONE --v3-priv-proto=NONE
19
+
20
+ }
21
+
22
+
23
+ function finish {
24
+ docker stop test-snmp
25
+ docker rm test-snmp
26
+ }
27
+
28
+ trap finish EXIT
29
+
30
+ start
31
+ sleep 20 # give some time for the simulator to boot
32
+
33
+ port="$(docker port test-snmp 1161/udp)"
34
+ export SNMP_PORT=$(echo $port | cut -d':' -f2)
35
+
36
+ bundle exec rake spec:ci
37
+ bundle exec rubocop
38
+
39
+
@@ -1,5 +1,5 @@
1
- sudo docker build --build-arg http_proxy=$http_proxy --build-arg https_proxy=$https_proxy -t snmp-server-emulator -f spec/support/Dockerfile .
2
- sudo docker run -d -p :1161/udp --name test-snmp-emulator snmp-server-emulator \
1
+ docker build -t snmp-server -f spec/support/Dockerfile .
2
+ docker run -p :1161/udp --name test-snmp-emulator -v $(pwd)/spec/support/snmpsim:/home/snmp_server/.snmpsim snmp-server \
3
3
  --v3-engine-id=000000000000000000000002 \
4
4
  --agent-udpv4-endpoint=0.0.0.0:1161 --agent-udpv6-endpoint='[::0]:1161' \
5
5
  --v3-user=simulator --v3-auth-key=auctoritas --v3-priv-key=privatus \
@@ -14,6 +14,6 @@ sudo docker run -d -p :1161/udp --name test-snmp-emulator snmp-server-emulator \
14
14
  --v3-user=authprivmd5des --v3-auth-key=maplesyrup --v3-auth-proto=MD5 \
15
15
  --v3-priv-key=maplesyrup --v3-priv-proto=DES \
16
16
  --v3-user=unsafe --v3-auth-proto=NONE --v3-priv-proto=NONE
17
- sleep 20 # give some time for the simulator to boot
18
-
17
+ #sleep 20 # give some time for the simulator to boot
18
+ export SNMP_PORT=`echo $(docker port test-snmp-emulator 1161/udp) | cut -d':' -f2`
19
19
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # from https://ask.wireshark.org/questions/14002/how-to-decode-timeticks-hundreds-seconds-to-readable-date-time
2
4
  RSpec.describe NETSNMP::Timetick do
3
5
  subject { described_class.new(1525917187) }
@@ -1,7 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe NETSNMP::V3Session do
2
- let(:security_options) { { username: "authprivmd5des", auth_password: "maplesyrup",
3
- auth_protocol: :md5, priv_password: "maplesyrup",
4
- priv_protocol: :des, security_level: :auth_priv } }
4
+ let(:security_options) do
5
+ { username: "authprivmd5des", auth_password: "maplesyrup",
6
+ auth_protocol: :md5, priv_password: "maplesyrup",
7
+ priv_protocol: :des, security_level: :auth_priv }
8
+ end
5
9
  it "generates the security parameters handler" do
6
10
  sess = described_class.new(security_options.merge(host: "localhost", port: SNMPPORT))
7
11
  # not generated yet
@@ -16,6 +20,6 @@ RSpec.describe NETSNMP::V3Session do
16
20
  end
17
21
 
18
22
  it "fails if the pass object doesn't follow the expected api" do
19
- expect { described_class.new(host: "localhost", port: SNMPPORT, security_parameters: double) }.to raise_error(NETSNMP::Error)
23
+ expect { described_class.new(host: "localhost", port: SNMPPORT, security_parameters: double) }.to raise_error(NETSNMP::Error)
20
24
  end
21
25
  end
data/spec/varbind_spec.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  RSpec.describe NETSNMP::Varbind do
2
4
  describe "#to_der" do
3
5
  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) }
@@ -15,6 +17,16 @@ RSpec.describe NETSNMP::Varbind do
15
17
  end
16
18
  context "when passed a type" do
17
19
  # TODO: tidy this for IP Addresses
20
+ it "converts gauge32" do
21
+ gauge = 805
22
+ varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :gauge, value: gauge)
23
+ expect(varbind.to_der).to end_with("B\x02\x03%".b)
24
+ end
25
+ it "converts counter32" do
26
+ gauge = 998932
27
+ varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :counter32, value: gauge)
28
+ expect(varbind.to_der).to end_with("A\x02>\x14".b)
29
+ end
18
30
  it "converts integer ticks" do
19
31
  timetick = 1
20
32
  varbind = described_class.new(".1.3.6.1.2.1.1.3.0", type: :timetick, value: timetick)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsnmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-02-21 00:00:00.000000000 Z
11
+ date: 2018-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -70,9 +70,9 @@ dependencies:
70
70
  - - ">="
71
71
  - !ruby/object:Gem::Version
72
72
  version: 0.17.2
73
- description: |
74
- Wraps the net-snmp core usage into idiomatic ruby.
75
- It is designed to support as many environments and concurrency frameworks as possible.
73
+ description: |2
74
+ Wraps the net-snmp core usage into idiomatic ruby.
75
+ It is designed to support as many environments and concurrency frameworks as possible.
76
76
  email: cardoso_tiago@hotmail.com
77
77
  executables: []
78
78
  extensions: []
@@ -81,6 +81,8 @@ files:
81
81
  - ".coveralls.yml"
82
82
  - ".gitignore"
83
83
  - ".rspec"
84
+ - ".rubocop.yml"
85
+ - ".rubocop_todo.yml"
84
86
  - ".travis.yml"
85
87
  - AUTHORS
86
88
  - Gemfile
@@ -114,7 +116,8 @@ files:
114
116
  - spec/support/Dockerfile
115
117
  - spec/support/celluloid.rb
116
118
  - spec/support/request_examples.rb
117
- - spec/support/start_docker.sh
119
+ - spec/support/specs.sh
120
+ - spec/support/start-docker.sh
118
121
  - spec/support/stop_docker.sh
119
122
  - spec/timeticks_spec.rb
120
123
  - spec/v3_session_spec.rb
@@ -132,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
132
135
  requirements:
133
136
  - - ">="
134
137
  - !ruby/object:Gem::Version
135
- version: 2.1.0
138
+ version: '0'
136
139
  required_rubygems_version: !ruby/object:Gem::Requirement
137
140
  requirements:
138
141
  - - ">="
@@ -141,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
144
  requirements:
142
145
  - net-snmp
143
146
  rubyforge_project:
144
- rubygems_version: 2.2.5
147
+ rubygems_version: 2.7.4
145
148
  signing_key:
146
149
  specification_version: 4
147
150
  summary: SNMP Client library
@@ -156,7 +159,8 @@ test_files:
156
159
  - spec/support/Dockerfile
157
160
  - spec/support/celluloid.rb
158
161
  - spec/support/request_examples.rb
159
- - spec/support/start_docker.sh
162
+ - spec/support/specs.sh
163
+ - spec/support/start-docker.sh
160
164
  - spec/support/stop_docker.sh
161
165
  - spec/timeticks_spec.rb
162
166
  - spec/v3_session_spec.rb