netsnmp 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.travis.yml +4 -4
  4. data/Gemfile +5 -1
  5. data/README.md +124 -63
  6. data/lib/netsnmp.rb +66 -10
  7. data/lib/netsnmp/client.rb +93 -75
  8. data/lib/netsnmp/encryption/aes.rb +84 -0
  9. data/lib/netsnmp/encryption/des.rb +80 -0
  10. data/lib/netsnmp/encryption/none.rb +17 -0
  11. data/lib/netsnmp/errors.rb +1 -3
  12. data/lib/netsnmp/message.rb +81 -0
  13. data/lib/netsnmp/oid.rb +18 -137
  14. data/lib/netsnmp/pdu.rb +106 -64
  15. data/lib/netsnmp/scoped_pdu.rb +23 -0
  16. data/lib/netsnmp/security_parameters.rb +198 -0
  17. data/lib/netsnmp/session.rb +84 -275
  18. data/lib/netsnmp/v3_session.rb +81 -0
  19. data/lib/netsnmp/varbind.rb +65 -156
  20. data/lib/netsnmp/version.rb +2 -1
  21. data/netsnmp.gemspec +2 -8
  22. data/spec/client_spec.rb +147 -99
  23. data/spec/handlers/celluloid_spec.rb +33 -20
  24. data/spec/oid_spec.rb +11 -5
  25. data/spec/pdu_spec.rb +22 -22
  26. data/spec/security_parameters_spec.rb +40 -0
  27. data/spec/session_spec.rb +0 -23
  28. data/spec/support/celluloid.rb +24 -0
  29. data/spec/support/request_examples.rb +36 -0
  30. data/spec/support/start_docker.sh +15 -1
  31. data/spec/v3_session_spec.rb +21 -0
  32. data/spec/varbind_spec.rb +2 -51
  33. metadata +30 -76
  34. data/lib/netsnmp/core.rb +0 -12
  35. data/lib/netsnmp/core/client.rb +0 -15
  36. data/lib/netsnmp/core/constants.rb +0 -153
  37. data/lib/netsnmp/core/inline.rb +0 -20
  38. data/lib/netsnmp/core/libc.rb +0 -48
  39. data/lib/netsnmp/core/libsnmp.rb +0 -44
  40. data/lib/netsnmp/core/structures.rb +0 -167
  41. data/lib/netsnmp/core/utilities.rb +0 -13
  42. data/lib/netsnmp/handlers/celluloid.rb +0 -27
  43. data/lib/netsnmp/handlers/em.rb +0 -56
  44. data/spec/core/libc_spec.rb +0 -2
  45. data/spec/core/libsnmp_spec.rb +0 -32
  46. data/spec/core/structures_spec.rb +0 -54
  47. data/spec/handlers/em_client_spec.rb +0 -34
@@ -1,13 +0,0 @@
1
- module NETSNMP::Core
2
-
3
- def self.version
4
- LibSNMP.netsnmp_get_version
5
- end
6
-
7
-
8
- # Do not support versions lower than 5.5, as they're mostly buggy.
9
- if version < "5.5"
10
- raise LoadError, "The netsnmp version #{version} is incompatible with this version of ffi-netsnmp-core"
11
- end
12
-
13
- end
@@ -1,27 +0,0 @@
1
- require 'netsnmp'
2
- module NETSNMP
3
- module Celluloid
4
- class Client < ::NETSNMP::Client
5
-
6
- def initialize(*args)
7
- @session = Celluloid::Session.new(*args)
8
- super
9
- end
10
-
11
- end
12
-
13
- class Session < ::NETSNMP::Session
14
- def wait_readable
15
- return super unless ::Celluloid::IO.evented?
16
- ::Celluloid::IO.wait_readable(transport)
17
- [[transport]]
18
- end
19
-
20
- def wait_writable
21
- return super unless ::Celluloid::IO.evented?
22
- ::Celluloid::IO.wait_writable(transport)
23
- [[],[transport]]
24
- end
25
- end
26
- end
27
- end
@@ -1,56 +0,0 @@
1
- require 'netsnmp'
2
- module NETSNMP
3
- module EM
4
- class Client < ::NETSNMP::Client
5
-
6
- def initialize(*args)
7
- @session = EM::Session.new(*args)
8
- super
9
- end
10
-
11
- end
12
-
13
- class Session < ::NETSNMP::Session
14
- module Watcher
15
- def initialize(client, deferable)
16
- @client = client
17
- @deferable = deferable
18
- @is_watching = true
19
- end
20
-
21
- def notify_readable
22
- detach
23
- begin
24
- operation = nil
25
- @client.__send__ :async_read
26
- result = @client.__send__ :handle_response
27
- rescue => e
28
- @deferable.fail(e)
29
- else
30
- @deferable.succeed(result)
31
- end
32
- end
33
-
34
- def watching?
35
- @is_watching
36
- end
37
-
38
- def unbind
39
- @is_watching = false
40
- end
41
- end
42
-
43
- def send(pdu)
44
- if ::EM.reactor_running?
45
- write(pdu)
46
- deferable = ::EM::DefaultDeferrable.new
47
- watch = ::EM.watch(transport.fileno, Watcher, self, deferable)
48
- watch.notify_readable = true
49
- ::EM::Synchrony.sync deferable
50
- else
51
- super
52
- end
53
- end
54
- end
55
- end
56
- end
@@ -1,2 +0,0 @@
1
- RSpec.describe NETSNMP::Core::C do
2
- end
@@ -1,32 +0,0 @@
1
- RSpec.describe NETSNMP::Core::LibSNMP do
2
- subject { described_class }
3
- it "exposes initialization and shutdown methods" do
4
- [:init_snmp, :snmp_perror].each do |meth|
5
- is_expected.to respond_to(meth)
6
- end
7
- end
8
-
9
- it "exposes netsnmp session handling methods" do
10
- [:snmp_sess_init, :snmp_sess_open, :snmp_sess_close, :generate_Ku].each do |meth|
11
- is_expected.to respond_to(meth)
12
- end
13
- end
14
-
15
- it "exposes netsnmp read API" do
16
- [:snmp_sess_synch_response, :snmp_sess_send].each do |meth|
17
- is_expected.to respond_to(meth)
18
- end
19
- end
20
-
21
- it "exposes netsnmp session async send/read" do
22
- [:snmp_sess_async_send, :snmp_sess_select_info, :snmp_sess_read].each do |meth|
23
- is_expected.to respond_to(meth)
24
- end
25
- end
26
-
27
- it "exposes the pdu API" do
28
- [:snmp_pdu_create, :snmp_free_pdu, :snmp_pdu_add_variable].each do |meth|
29
- is_expected.to respond_to(meth)
30
- end
31
- end
32
- end
@@ -1,54 +0,0 @@
1
- RSpec.describe NETSNMP::Core::Structures do
2
- describe NETSNMP::Core::Structures::Session do
3
- [:version, :retries, :timeout, :flags, :subsession, :next, :peername, :remote_port, :localname, :local_port, :authenticator,
4
- :callback, :callback_magic, :community, :community_len, :rcvMsgMaxSize, :sndMsgMaxSize, :isAuthoritative, :contextEngineID,
5
- :contextEngineIDLen, :engineBoots, :engineTime, :contextName, :contextNameLen, :securityEngineID, :securityEngineIDLen,
6
- :securityName, :securityNameLen, :securityAuthProto, :securityAuthProtoLen, :securityAuthKey, :securityAuthKeyLen,
7
- :securityAuthLocalKey, :securityAuthLocalKeyLen, :securityPrivProto, :securityPrivProtoLen, :securityPrivKey, :securityPrivKeyLen,
8
- :securityPrivLocalKey, :securityPrivLocalKeyLen, :securityModel, :securityLevel, :paramName, :securityInfo, :myvoid].each do |attr|
9
- it { expect(subject[attr]).not_to be_nil }
10
- end
11
- end
12
-
13
- describe NETSNMP::Core::Structures::Vardata do
14
- [:integer, :string, :objid, :bitstring, :counter64, :float, :double].each do |attr|
15
- it { expect(subject[attr]).not_to be_nil }
16
- end
17
- end
18
-
19
- describe NETSNMP::Core::Structures::VariableList do
20
- [:next_variable, :name, :name_length, :type, :val, :val_len, :name_loc, :buf, :data, :dataFreeHook, :index].each do |attr|
21
- it { expect(subject[attr]).not_to be_nil }
22
- end
23
- end
24
-
25
- describe NETSNMP::Core::Structures::PDU do
26
- [:version, :command, :reqid, :msgid, :transid, :sessid, :errstat, :errindex, :time, :flags, :securityModel,
27
- :securityLevel, :msgParseModel, :transport_data, :transport_data_length, :tDomain, :tDomainLen, :variables,
28
- :community, :community_len, :enterprise, :enterprise_length, :trap_type, :specific_type, :agent_addr,
29
- :contextEngineID, :contextEngineIDLen, :contextName, :contextNameLen, :securityEngineID, :securityEngineIDLen,
30
- :securityName, :securityNameLen, :priority, :range_subid, :securityStateRef].each do |attr|
31
- it { expect(subject[attr]).not_to be_nil }
32
- end
33
- end
34
-
35
- describe NETSNMP::Core::Structures::SessionList do
36
- [:next, :session, :transport, :internal].each do |attr|
37
- it { expect(subject[attr]).not_to be_nil }
38
- end
39
- end
40
-
41
- describe NETSNMP::Core::Structures::Transport do
42
- [:domain, :domain_length, :local, :local_length, :remote, :remote_length,
43
- :sock, :flags, :data, :data_length, :msgMaxSize, :base_transport].each do |attr|
44
- it { expect(subject[attr]).not_to be_nil }
45
- end
46
- end
47
-
48
- describe NETSNMP::Core::Structures::Counter64 do
49
- [:high, :low].each do |attr|
50
- it { expect(subject[attr]).not_to be_nil }
51
- end
52
- end
53
-
54
- end
@@ -1,34 +0,0 @@
1
- require 'em-synchrony'
2
- require 'netsnmp/handlers/em'
3
-
4
- RSpec.describe NETSNMP::EM::Client do
5
- let(:host) { "localhost" }
6
- let(:host_options) { {
7
- peername: "localhost",
8
- port: SNMPPORT,
9
- username: "simulator",
10
- auth_password: "auctoritas",
11
- auth_protocol: :md5,
12
- priv_password: "privatus",
13
- priv_protocol: :des
14
- } }
15
-
16
- subject { described_class.new(host, options) }
17
-
18
- describe "#get" do
19
- let(:oid) { "1.3.6.1.2.1.1.5.0" } # sysName.0
20
- let(:options) { host_options.merge(context: "a172334d7d97871b72241397f713fa12") }
21
- it "fetches the varbinds for a given oid" do
22
- value = nil
23
- EM.synchrony do
24
- begin
25
- value = subject.get(oid)
26
- ensure
27
- EM.stop_event_loop
28
- end
29
- end
30
- expect(value).to eq("tt")
31
- end
32
- end
33
-
34
- end