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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NETSNMP
4
- VERSION = "0.1.8"
4
+ VERSION = "0.4.1"
5
5
  end
data/sig/client.rbs ADDED
@@ -0,0 +1,24 @@
1
+ module NETSNMP
2
+ class Client
3
+
4
+ def get: (*untyped) -> untyped
5
+ | (*untyped) { (PDU) -> void } -> untyped
6
+
7
+ def get_next: (*untyped) -> untyped
8
+ | (*untyped) { (PDU) -> void } -> untyped
9
+
10
+ def set: (*untyped) -> untyped
11
+ | (*untyped) { (PDU) -> void } -> untyped
12
+
13
+ def inform: (*untyped) -> untyped
14
+ | (*untyped) { (PDU) -> void } -> untyped
15
+
16
+ def walk: (oid: oid) -> _Each[oid_type, oid_value]
17
+
18
+ def close: () -> void
19
+
20
+ private
21
+
22
+ def initialize: (?version?: snmp_version, **untyped) -> untyped
23
+ end
24
+ end
data/sig/loggable.rbs ADDED
@@ -0,0 +1,16 @@
1
+ module NETSNMP
2
+ module Loggable
3
+ interface _Debugger
4
+ def <<: (string) -> void
5
+ end
6
+
7
+ DEBUG_LEVEL: Integer
8
+ DEBUG: _Debugger
9
+
10
+ private
11
+
12
+ def initialize: (?debug: _DEBUGGER, ?debug_level: Integer, **untyped) -> void
13
+
14
+ def log: (?level: Integer) { () -> String } -> void
15
+ end
16
+ end
data/sig/message.rbs ADDED
@@ -0,0 +1,9 @@
1
+ module NETSNMP
2
+ class Message
3
+ prepend Loggable
4
+
5
+ def decode: (String stream, security_parameters: SecurityParameters) -> [ScopedPDU, String, Integer, Integer]
6
+
7
+ def encode: (ScopedPDU pdu, security_parameters: SecurityParameters, ?engine_boots: Integer, ?engine_time: Integer) -> String
8
+ end
9
+ end
data/sig/mib.rbs ADDED
@@ -0,0 +1,21 @@
1
+ module NETSNMP
2
+ module MIB
3
+ type import = {ids: Array[{name: string}], name: string} | {ids: {name: string}, name: string}
4
+
5
+
6
+ MIBDIRS: Array[String]
7
+ PARSER: Parser
8
+
9
+ @parser_mutex: Mutex
10
+ @modules_loaded: Array[String]
11
+ @object_identifiers: Hash[String, String]
12
+
13
+ def self?.oid: (String identifier) -> String?
14
+ | (Array[_ToS] identifier) -> String?
15
+
16
+ def self?.load: (String mod) -> void
17
+
18
+ def self?.load_imports: ((Array[import] | import)? data) -> Hash[String, Array[String]]?
19
+ def self?.load_defaults: () -> void
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ module NETSNMP
2
+ module MIB
3
+ class Parser
4
+
5
+ end
6
+ end
7
+ end
data/sig/netsnmp.rbs ADDED
@@ -0,0 +1,19 @@
1
+ module NETSNMP
2
+ interface _Logger
3
+ def <<: (string) -> void
4
+ end
5
+
6
+ interface _Authenticate
7
+ def reset: () -> void
8
+ def <<: (string) -> void
9
+ def digest: () -> String
10
+ end
11
+
12
+ interface _Encrypt
13
+ def encrypt: (String payload, engine_boots: Integer, engine_time: Integer) -> String
14
+
15
+ def decrypt: (String payload, salt: String, engine_boots: Integer, engine_time: Integer) -> String
16
+ end
17
+
18
+ type snmp_version = 0 | 1 | 3 | :v1 | :v2c | :v3 | nil
19
+ end
data/sig/oid.rbs ADDED
@@ -0,0 +1,18 @@
1
+ module NETSNMP
2
+ type oid = String | Array[_ToS]
3
+
4
+ type oid_type = Integer | :ipaddress | :counter32 | :gauge | :timetick | :opaque | :nsap | :counter64 | :uinteger
5
+
6
+ type oid_value = String | Integer | Timetick | true | false | nil | IPAddr
7
+
8
+ # type oid_options = {}
9
+
10
+ module OID
11
+
12
+ def self?.build: (oid) -> String
13
+
14
+ def self?.to_asn: (String oid) -> OpenSSL::ASN1::ObjectId
15
+
16
+ def self?.parent?: (String oid, String oid) -> bool
17
+ end
18
+ end
data/sig/openssl.rbs ADDED
@@ -0,0 +1,20 @@
1
+ module OpenSSL
2
+ module ASN1
3
+ class ASN1Data
4
+ end
5
+ class ObjectId < ASN1Data
6
+ end
7
+ class Primitive < ASN1Data
8
+ end
9
+ class Integer < ASN1Data
10
+ end
11
+ class OctetString < ASN1Data
12
+ end
13
+ class Sequence < ASN1Data
14
+ end
15
+ end
16
+ end
17
+
18
+ interface _ToAsn
19
+ def to_asn: () -> OpenSSL::ASN1::ASN1Data
20
+ end
data/sig/pdu.rbs ADDED
@@ -0,0 +1,48 @@
1
+ module NETSNMP
2
+ type pdu_type = :get | :getnext | :set | :inform | :trap | :response
3
+
4
+ class PDU
5
+
6
+ # type pdu_options = {
7
+ # headers: [snmp_version?, String?],
8
+ # ?request_id: String,
9
+ # ?error_status: Integer,
10
+ # ?error_index: Integer,
11
+ # ?varbinds: Array[varbind_options]
12
+ # }
13
+
14
+ attr_reader varbinds: Array[Varbind]
15
+ attr_reader type: Integer
16
+ attr_reader version: snmp_version
17
+ attr_reader community: String
18
+ attr_reader request_id: Integer
19
+
20
+ def self.decode: (String der) -> PDU
21
+ | (OpenSSL::ASN1::ASN1Data der) -> PDU
22
+
23
+ def self.build: (pdu_type, **untyped) -> PDU
24
+
25
+
26
+ def to_asn: () -> OpenSSL::ASN1::ASN1Data
27
+
28
+ def to_der: () -> String
29
+
30
+ def add_varbind: (oid: oid, **varbind_options) -> void
31
+ alias << add_varbind
32
+
33
+ private
34
+
35
+ def initialize: (
36
+ type: Integer,
37
+ headers: [snmp_version?, String?],
38
+ ?request_id: Integer,
39
+ ?error_status: Integer,
40
+ ?error_index: Integer,
41
+ ?varbinds: Array[varbind_options]
42
+ ) -> untyped
43
+
44
+ def encode_headers_asn: () -> [OpenSSL::ASN1::Integer, OpenSSL::ASN1::OctetString]
45
+
46
+ def check_error_status: (Integer) -> void
47
+ end
48
+ end
@@ -0,0 +1,15 @@
1
+ module NETSNMP
2
+ class ScopedPDU < PDU
3
+ attr_reader engine_id: String
4
+
5
+ private
6
+
7
+ def initialize: (
8
+ type: Integer,
9
+ headers: [String?, String?],
10
+ **untyped
11
+ ) -> void
12
+
13
+ def encode_headers_asn: () -> [OpenSSL::ASN1::OctetString, OpenSSL::ASN1::OctetString]
14
+ end
15
+ end
@@ -0,0 +1,58 @@
1
+ module NETSNMP
2
+ class SecurityParameters
3
+ prepend Loggable
4
+
5
+ type security_level = :noauth | :auth_no_priv | :auth_priv | 0 | 1 | 3 | nil
6
+
7
+ type auth_protocol = :md5 | :sha
8
+ type priv_protocol = :des | :aes
9
+
10
+
11
+ @auth_protocol: auth_protocol?
12
+ @auth_password: String?
13
+ @priv_protocol: priv_protocol?
14
+ @priv_password: String?
15
+ @digest: _Authenticate?
16
+ @encryption: _Encrypt?
17
+
18
+ attr_reader security_level: security_level
19
+ attr_reader username: String
20
+ attr_reader engine_id: String
21
+
22
+ def engine_id=: (String id) -> void
23
+
24
+ def encode: (_ToAsn, salt: OpenSSL::ASN1::ASN1Data, engine_time: Integer, engine_boots: Integer) -> [OpenSSL::ASN1::ASN1Data, OpenSSL::ASN1::ASN1Data]
25
+
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
27
+
28
+ def sign: (String message) -> String?
29
+
30
+ def verify: (String stream, String salt, ?security_level: Integer?) -> void
31
+
32
+ def must_revalidate?: () -> bool
33
+
34
+ private
35
+
36
+ def initialize: (
37
+ username: String,
38
+ ?engine_id: String,
39
+ ?security_level: security_level?,
40
+ ?auth_protocol: auth_protocol?,
41
+ ?auth_password: String?,
42
+ ?priv_protocol: priv_protocol?,
43
+ ?priv_password: String?,
44
+ ) -> untyped
45
+
46
+ def auth_key: () -> String
47
+
48
+ def priv_key: () -> String
49
+
50
+ def check_parameters: () -> void
51
+
52
+ def localize_key: (String key) -> String
53
+
54
+ def passkey: (String password) -> String
55
+
56
+ def authorizable?: () -> bool
57
+ end
58
+ end
data/sig/session.rbs ADDED
@@ -0,0 +1,38 @@
1
+ module NETSNMP
2
+ class Session
3
+ prepend Loggable
4
+
5
+ @transport: _Transport
6
+ @version: 0 | 1 | 3
7
+ @community: String?
8
+
9
+ def close: () -> void
10
+
11
+ def build_pdu: (pdu_type, *untyped) -> PDU
12
+
13
+ def send: (PDU) -> PDU
14
+
15
+ private
16
+
17
+ def initialize: (?version: snmp_version, ?community: String, **untyped) -> untyped
18
+
19
+ def validate: (?host: String?, ?port: Integer, ?proxy: _Transport, ?timeout: Integer, **untyped) -> void
20
+
21
+ class Transport
22
+ def initialize: (String host, Integer port, timeout: Integer) -> untyped
23
+ def close: () -> void
24
+ def send: (String payload) -> String
25
+ def write: (String) -> void
26
+ def recv: () -> void
27
+
28
+ private
29
+
30
+ def wait: (:wait_readable | :wait_writable) -> void
31
+ end
32
+ end
33
+
34
+ interface _Transport
35
+ def close: () -> void
36
+ def send: (String payload) -> String
37
+ end
38
+ end
data/sig/timeticks.rbs ADDED
@@ -0,0 +1,7 @@
1
+ module NETSNMP
2
+ class Timetick < Numeric
3
+ @ticks: Integer
4
+
5
+ def to_asn: () -> OpenSSL::ASN1::ASN1Data
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ module NETSNMP
2
+ class V3Session < Session
3
+
4
+ def build_pdu: (pdu_type, *untyped) -> ScopedPDU
5
+
6
+ def send: (ScopedPDU pdu) -> ScopedPDU
7
+ | (ScopedPDU pdu) -> [PDU, String, Integer, Integer]
8
+
9
+ private
10
+
11
+ def encode: (ScopedPDU) -> String
12
+
13
+ def initialize: (?context: String, **untyped) -> untyped
14
+
15
+ def security_parameters: () -> SecurityParameters
16
+
17
+ def probe_for_engine: () -> String
18
+
19
+ def decode: (String, ?security_parameters: SecurityParameters) -> [PDU, String, Integer, Integer]
20
+ end
21
+ end
data/sig/varbind.rbs ADDED
@@ -0,0 +1,30 @@
1
+ module NETSNMP
2
+ type varbind_options = untyped
3
+
4
+ class Varbind
5
+
6
+ type varbind_value = OpenSSL::ASN1::OctetString | OpenSSL::ASN1::Primitive | OpenSSL::ASN1::ASN1Data | oid_value
7
+
8
+ attr_reader oid: String
9
+ attr_reader value: oid_value
10
+
11
+ def to_asn: () -> OpenSSL::ASN1::Sequence
12
+
13
+ def to_der: () -> String
14
+
15
+ def convert_val: (varbind_value) -> oid_value
16
+
17
+
18
+ def convert_to_asn: (oid_type, oid_value) -> OpenSSL::ASN1::ASN1Data
19
+
20
+ def convert_application_asn: (OpenSSL::ASN1::ASN1Data asn) -> oid_value
21
+
22
+ private
23
+
24
+ def initialize: (oid, ?value: varbind_value, ?type: oid_type) -> untyped
25
+
26
+ def unpack_32bit_integer: (String) -> Integer
27
+
28
+ def unpack_64bit_integer: (String) -> Integer
29
+ end
30
+ end
data/spec/client_spec.rb CHANGED
@@ -3,11 +3,11 @@
3
3
  require_relative "support/request_examples"
4
4
 
5
5
  RSpec.describe NETSNMP::Client do
6
- let(:host) { "localhost" }
6
+ let(:host) { SNMPHOST }
7
7
 
8
8
  let(:device_options) do
9
9
  {
10
- peername: "localhost",
10
+ peername: SNMPHOST,
11
11
  port: SNMPPORT
12
12
  }
13
13
  end
@@ -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" }