net-snmp2 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +5 -0
  3. data/.rspec +1 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE +20 -0
  6. data/README.md +28 -0
  7. data/Rakefile +24 -0
  8. data/TODO.md +6 -0
  9. data/bin/mib2rb +129 -0
  10. data/bin/net-snmp2 +64 -0
  11. data/examples/agent.rb +104 -0
  12. data/examples/manager.rb +11 -0
  13. data/examples/trap_handler.rb +46 -0
  14. data/examples/v1_trap_session.rb +24 -0
  15. data/examples/v2_trap_session.rb +21 -0
  16. data/lib/net-snmp2.rb +85 -0
  17. data/lib/net/snmp.rb +27 -0
  18. data/lib/net/snmp/agent/agent.rb +48 -0
  19. data/lib/net/snmp/agent/provider.rb +51 -0
  20. data/lib/net/snmp/agent/provider_dsl.rb +124 -0
  21. data/lib/net/snmp/agent/request_dispatcher.rb +38 -0
  22. data/lib/net/snmp/constants.rb +287 -0
  23. data/lib/net/snmp/debug.rb +54 -0
  24. data/lib/net/snmp/dispatcher.rb +108 -0
  25. data/lib/net/snmp/error.rb +29 -0
  26. data/lib/net/snmp/listener.rb +76 -0
  27. data/lib/net/snmp/message.rb +142 -0
  28. data/lib/net/snmp/mib/mib.rb +67 -0
  29. data/lib/net/snmp/mib/module.rb +39 -0
  30. data/lib/net/snmp/mib/node.rb +122 -0
  31. data/lib/net/snmp/mib/templates.rb +48 -0
  32. data/lib/net/snmp/oid.rb +134 -0
  33. data/lib/net/snmp/pdu.rb +235 -0
  34. data/lib/net/snmp/repl/manager_repl.rb +243 -0
  35. data/lib/net/snmp/session.rb +560 -0
  36. data/lib/net/snmp/trap_handler/trap_handler.rb +42 -0
  37. data/lib/net/snmp/trap_handler/v1_trap_dsl.rb +44 -0
  38. data/lib/net/snmp/trap_handler/v2_trap_dsl.rb +38 -0
  39. data/lib/net/snmp/trap_session.rb +92 -0
  40. data/lib/net/snmp/utility.rb +10 -0
  41. data/lib/net/snmp/varbind.rb +57 -0
  42. data/lib/net/snmp/version.rb +5 -0
  43. data/lib/net/snmp/wrapper.rb +450 -0
  44. data/net-snmp2.gemspec +30 -0
  45. data/spec/README.md +105 -0
  46. data/spec/async_spec.rb +123 -0
  47. data/spec/em_spec.rb +23 -0
  48. data/spec/error_spec.rb +34 -0
  49. data/spec/fiber_spec.rb +41 -0
  50. data/spec/mib_spec.rb +68 -0
  51. data/spec/net-snmp_spec.rb +18 -0
  52. data/spec/oid_spec.rb +21 -0
  53. data/spec/spec_helper.rb +10 -0
  54. data/spec/sync_spec.rb +132 -0
  55. data/spec/thread_spec.rb +19 -0
  56. data/spec/trap_spec.rb +45 -0
  57. data/spec/utility_spec.rb +10 -0
  58. data/spec/wrapper_spec.rb +69 -0
  59. metadata +166 -0
@@ -0,0 +1,24 @@
1
+ $: << '../lib'
2
+ require 'net-snmp2'
3
+
4
+ # Initialize SNMP and give it a logger
5
+ Net::SNMP.init
6
+ Net::SNMP::Debug.logger = Logger.new(STDOUT)
7
+ Net::SNMP::Debug.logger.level = Logger::DEBUG
8
+
9
+ puts "Opening session"
10
+ session = Net::SNMP::TrapSession.open(:peername => 'localhost', :version => '1', :community => 'public')
11
+
12
+ puts "Sending trap"
13
+
14
+ 100000.times do |i|
15
+ session.trap(
16
+ enterprise: '1.3.1',
17
+ trap_type: 6,
18
+ specific_type: 1,
19
+ uptime: 1000,
20
+ agent_addr: '127.0.0.1'
21
+ )
22
+ end
23
+
24
+ sleep 20
@@ -0,0 +1,21 @@
1
+ $: << '../lib'
2
+ require 'net-snmp2'
3
+
4
+ # Initialize SNMP and give it a logger
5
+ Net::SNMP.init
6
+ Net::SNMP::Debug.logger = Logger.new(STDOUT)
7
+ Net::SNMP::Debug.logger.level = Logger::DEBUG
8
+
9
+ puts "Opening session"
10
+ session = Net::SNMP::TrapSession.open(:peername => 'localhost', :version => '2c', :community => 'public')
11
+
12
+ puts "Sending trap"
13
+
14
+ 100000.times do |i|
15
+ puts session.trap_v2(
16
+ oid: '1.3.1.1',
17
+ uptime: 1000
18
+ )
19
+ end
20
+
21
+ sleep 20
@@ -0,0 +1,85 @@
1
+ require 'forwardable'
2
+ require 'nice-ffi'
3
+ require 'fiber'
4
+ require 'socket'
5
+ require 'logger'
6
+
7
+ %w(
8
+ snmp
9
+ snmp/debug
10
+ snmp/wrapper
11
+ snmp/version
12
+ snmp/constants
13
+ snmp/utility
14
+ snmp/oid
15
+ snmp/error
16
+ snmp/pdu
17
+ snmp/session
18
+ snmp/trap_session
19
+ snmp/varbind
20
+ snmp/listener
21
+ snmp/trap_handler/trap_handler
22
+ snmp/trap_handler/v1_trap_dsl
23
+ snmp/trap_handler/v2_trap_dsl
24
+ snmp/mib/mib
25
+ snmp/mib/node
26
+ snmp/mib/module
27
+ snmp/mib/templates
28
+ snmp/dispatcher
29
+ snmp/agent/agent
30
+ snmp/agent/provider
31
+ snmp/agent/provider_dsl
32
+ snmp/agent/request_dispatcher
33
+ snmp/message
34
+ ).each do |f|
35
+ require "#{File.dirname(__FILE__)}/net/#{f}"
36
+ end
37
+
38
+ # Save the description tests from the mib. This allows them to be printed
39
+ # if desired, by they may occupy significant amounts of memory...
40
+ Net::SNMP::Wrapper.snmp_set_save_descriptions(1)
41
+
42
+ # XXX
43
+ # I just monkeypatched this to take a nil first argument. Seems to work
44
+ # Should probably submit this as a patch
45
+
46
+ class NiceFFI::Struct < FFI::Struct
47
+ def initialize( val = nil, options={} )
48
+ # Stores certain kinds of member values so that we don't need
49
+ # to create a new object every time they are read.
50
+ @member_cache = {}
51
+
52
+ options = {:autorelease => true}.merge!( options )
53
+
54
+ case val
55
+
56
+ when Hash
57
+ super(FFI::Buffer.new(size))
58
+ init_from_hash( val ) # Read the values from a Hash.
59
+
60
+ # Note: plain "Array" would mean FFI::Struct::Array in this scope.
61
+ when ::Array
62
+ super(FFI::Buffer.new(size))
63
+ init_from_array( val ) # Read the values from an Array.
64
+
65
+ when String
66
+ super(FFI::Buffer.new(size))
67
+ init_from_bytes( val ) # Read the values from a bytestring.
68
+
69
+ when self.class
70
+ super(FFI::Buffer.new(size))
71
+ init_from_bytes( val.to_bytes ) # Read the values from another instance.
72
+
73
+ when FFI::Pointer, FFI::Buffer
74
+ val = _make_autopointer( val, options[:autorelease] )
75
+
76
+ # Normal FFI::Struct behavior to wrap the pointer.
77
+ super( val )
78
+
79
+ when nil
80
+ super(val)
81
+ else
82
+ raise TypeError, "cannot create new #{self.class} from #{val.inspect}"
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,27 @@
1
+ require 'net/snmp/constants'
2
+ module Net
3
+ module SNMP
4
+ include Net::SNMP::Constants
5
+
6
+ @thread_safe = false
7
+ @initialized = false
8
+
9
+ def self.init(tag="snmp")
10
+ Wrapper.init_snmp(tag)
11
+ @initialized = true
12
+ end
13
+
14
+ def self.thread_safe=(val)
15
+ @thread_safe = val
16
+ end
17
+
18
+ def self.thread_safe
19
+ @thread_safe
20
+ end
21
+
22
+ def self.initialized?
23
+ @initialized
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,48 @@
1
+ module Net::SNMP
2
+
3
+ # - Manages the request/response cycle for incoming messages
4
+ # + Listens for incoming requests
5
+ # + Parses request packets into Message objects
6
+ # + Dispatches the messages to (sub) Agents
7
+ # + Serializes the response from the subagents and sends it to the caller
8
+
9
+ class Agent
10
+ include Debug
11
+ extend Forwardable
12
+
13
+ attr_accessor :listener, :providers
14
+ def_delegators :listener, :start, :listen, :run, :stop, :kill
15
+
16
+ def initialize
17
+ @listener = Net::SNMP::Listener.new
18
+ @providers = []
19
+ @listener.on_message(&method(:process_message))
20
+ end
21
+
22
+ def provide(oid = :all, &block)
23
+ # Need a trailing dot on the oid so we can avoid
24
+ # considering 1.3.22 a child of 1.3.2
25
+ oid = (oid.to_sym == :all || oid.end_with?('.')) ? oid : "#{oid}."
26
+ provider = Provider.new(oid)
27
+ provider.instance_eval(&block)
28
+
29
+ # Providers are pushed onto the end of the provider queue.
30
+ # When dispatching, this is searched in order for a match.
31
+ # So, like exception handlers, you such specify providers
32
+ # in order of most -> least specific oid. ('1.3.1' comes before '1.3')
33
+ providers << provider
34
+ end
35
+
36
+ private
37
+
38
+ def process_message(message, from_address, from_port)
39
+ response_pdu = RequestDispatcher.dispatch(message, providers)
40
+ if response_pdu
41
+ Session.open(peername: from_address, port: from_port, version: message.version_name) do |sess|
42
+ sess.send_pdu response_pdu
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1,51 @@
1
+ module Net::SNMP
2
+
3
+ # Providers are responsible for handling requests for a given subtree
4
+ # of the system's MIB. The Provider object itself holds the root OID
5
+ # of the subtree provided, and handlers for the various request types.
6
+ # The handlers are executed for each varbind of the incoming message
7
+ # individually in the context of a ProviderDsl object.
8
+
9
+ class Provider
10
+ attr_accessor :oid,
11
+ :get_handler,
12
+ :set_handler,
13
+ :get_next_handler,
14
+ :get_bulk_handler
15
+
16
+ def initialize(oid)
17
+ @oid = oid
18
+ end
19
+
20
+ def handler_for(command)
21
+ # User might be tempted to just pass in the message, or pdu,
22
+ # if so, just pluck the command off of it.
23
+ if command.kind_of?(Message)
24
+ command = command.pdu.command
25
+ elsif command.kind_of?(PDU)
26
+ command = command.command
27
+ end
28
+
29
+ case command
30
+ when Constants::SNMP_MSG_GET
31
+ get_handler
32
+ when Constants::SNMP_MSG_GETNEXT
33
+ get_next_handler
34
+ when Constants::SNMP_MSG_GETBULK
35
+ get_bulk_handler
36
+ when Constants::SNMP_MSG_SET
37
+ set_handler
38
+ else
39
+ raise "Invalid command type: #{command}"
40
+ end
41
+ end
42
+
43
+ [:get, :set, :get_next, :get_bulk].each do |request_type|
44
+ self.class_eval %Q[
45
+ def #{request_type}(&proc)
46
+ self.#{request_type}_handler = proc
47
+ end
48
+ ]
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,124 @@
1
+ module Net::SNMP
2
+
3
+ # A ProviderDsl represents the context in which each handler
4
+ # for the varbinds of a single message are executed. The ProviderDsl
5
+ # object lives only as long as a single message is being processed,
6
+ # and offers convenience functions for accessing the members of the
7
+ # request as well as providing responses for each varbind in the request.
8
+
9
+ class ProviderDsl
10
+ include Debug
11
+
12
+ def initialize
13
+ @variable_index = 1
14
+ end
15
+
16
+ # Getters
17
+ # -------
18
+
19
+ # `varbind` is the current varbind. The RequestDispatcher
20
+ # resets this value for each varbind in the request, then
21
+ # execs the approriate provider's handler for that varbind
22
+ # in the context of this ProviderDsl object.
23
+ attr_accessor :varbind
24
+
25
+ # The message object for the current request.
26
+ attr_accessor :message
27
+
28
+ # The response PDU being constructed for the current request.
29
+ attr_accessor :response_pdu
30
+
31
+ # The PDU for the current request.
32
+ def pdu
33
+ message.pdu
34
+ end
35
+
36
+ # The OID of the current varbind being processed.
37
+ def oid
38
+ varbind.oid
39
+ end
40
+
41
+ # The OID of the current varbind being processed as a string.
42
+ def oid_str
43
+ varbind.oid.to_s
44
+ end
45
+
46
+ # The value of the current varbind being processed.
47
+ def value
48
+ varbind.value
49
+ end
50
+
51
+ # The maximum number of repetitions for each bulk retrieved varbind
52
+ def max_repetitions
53
+ pdu.max_repetitions
54
+ end
55
+
56
+ # Setters
57
+ # -------
58
+
59
+ # Used to set a varbind on the response packet.
60
+ #
61
+ # - If a hash is supplied, accepts the same options as
62
+ # PDU#add_varbind, except that if no oid is supplied,
63
+ # the oid from the current varbind is used.
64
+ # - If the argument is not a hash, it is used as the value of the
65
+ # varbind, with the current varbind's oid, and the type is derived
66
+ # as with PDU#add_varbind
67
+ def reply(varbind_options)
68
+ if varbind_options.kind_of?(Hash)
69
+ varbind_options[:oid] ||= varbind.oid
70
+ add_varbind(varbind_options)
71
+ else
72
+ add_varbind(oid: varbind.oid, value: varbind_options)
73
+ end
74
+ end
75
+
76
+ # add is more natural in a get_bulk
77
+ alias add reply
78
+
79
+ # Adds a copy of the current varbind to the response packet
80
+ # Useful in a set, to indicate success to the manager
81
+ def echo
82
+ add_varbind(oid: varbind.oid, type: varbind.type, value: varbind.value)
83
+ end
84
+
85
+ # ok... saves two characters.
86
+ alias ok echo
87
+
88
+ # Adds a varbind to the response indicating that no such object
89
+ # exists at the given oid. If no oid is supplied, or if oid is nil,
90
+ # then the oid from the current varbind is used.
91
+ def no_such_object(oid=nil)
92
+ oid ||= varbind.oid
93
+ add_varbind(oid: oid, type: Constants::SNMP_NOSUCHOBJECT)
94
+ end
95
+
96
+ # Adds a varbind to the response indicating that no such instance
97
+ # exists at the given oid. If no oid is supplied, or if oid is nil,
98
+ # then the oid from the current varbind is used.
99
+ def no_such_instance(oid=nil)
100
+ oid ||= varbind.oid
101
+ add_varbind(oid: oid, type: Constants::SNMP_NOSUCHINSTANCE)
102
+ end
103
+
104
+ # Adds a varbind to the response PDU.
105
+ # MUST use this method (or one that delegates to it)
106
+ # to set response varbinds on the response_pdu to make sure
107
+ # the variable_index is maintained automatically.
108
+ def add_varbind(options)
109
+ response_pdu.add_varbind(options)
110
+ @variable_index += 1
111
+ end
112
+
113
+ # Sets the error_status on the response pdu
114
+ def error(the_error)
115
+ response_pdu.error = the_error
116
+ response_pdu.error_index = @variable_index
117
+ # echo the varbind back to the manager so it can tell what object failed
118
+ echo
119
+ end
120
+ alias errstat error
121
+ alias error_status error
122
+
123
+ end
124
+ end
@@ -0,0 +1,38 @@
1
+ module Net::SNMP
2
+
3
+ # RequestDispatcher module handles calling all required providers for a request
4
+ # in the context of a ProviderDsl object (which itself provides the agent DSL)
5
+
6
+ module RequestDispatcher
7
+
8
+ def self.dispatch(message, providers)
9
+ response_pdu = Message::response_pdu_for(message)
10
+ context = ProviderDsl.new
11
+ context.message = message
12
+ context.response_pdu = response_pdu
13
+ message.pdu.varbinds.each_with_index do |vb, index|
14
+ context.varbind = vb
15
+ provider = providers.find { |p| p.oid == :all || vb.oid.to_s.start_with?(p.oid.to_s) }
16
+ if provider
17
+ if message.pdu.command == Constants::SNMP_MSG_GETBULK && index < message.pdu.non_repeaters
18
+ handler = provider.handler_for(Constants::SNMP_MSG_GETNEXT)
19
+ else
20
+ handler = provider.handler_for(message)
21
+ end
22
+ if handler
23
+ context.instance_exec(&handler)
24
+ else
25
+ Debug.warn "No handler for command: #{message.pdu.command} @ #{vb.oid}"
26
+ context.no_such_object
27
+ end
28
+ else
29
+ Debug.warn "No provider for oid: #{vb.oid}"
30
+ context.no_such_object
31
+ end
32
+ end
33
+
34
+ response_pdu
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,287 @@
1
+ module Net
2
+ module SNMP
3
+ module Constants
4
+ MAX_OID_LEN = 128
5
+
6
+ # Return values of various send functions
7
+ STAT_SUCCESS = 0
8
+ STAT_ERROR = 1
9
+ STAT_TIMEOUT = 2
10
+
11
+ # SNMP versions
12
+ SNMP_VERSION_1 = 0
13
+ SNMP_VERSION_2c = 1
14
+ SNMP_VERSION_3 = 3
15
+
16
+ # PDU variable types
17
+ ASN_BOOLEAN = 0x01
18
+ ASN_INTEGER = 0x02
19
+ ASN_BIT_STR = 0x03
20
+ ASN_OCTET_STR = 0x04
21
+ ASN_NULL = 0x05
22
+ ASN_OBJECT_ID = 0x06
23
+ ASN_SEQUENCE = 0x10
24
+ ASN_SET = 0x11
25
+
26
+ ASN_UNIVERSAL = 0x00
27
+ ASN_APPLICATION = 0x40
28
+ ASN_CONTEXT = 0x80
29
+ ASN_PRIVATE = 0xC0
30
+
31
+ ASN_PRIMITIVE = 0x00
32
+ ASN_CONSTRUCTOR = 0x20
33
+
34
+ ASN_LONG_LEN = 0x80
35
+ ASN_EXTENSION_ID = 0x1F
36
+ ASN_BIT8 = 0x80
37
+
38
+
39
+ ASN_IPADDRESS = (ASN_APPLICATION | 0)
40
+ ASN_COUNTER = (ASN_APPLICATION | 1)
41
+ ASN_GAUGE = (ASN_APPLICATION | 2)
42
+ ASN_UNSIGNED = (ASN_APPLICATION | 2) # RFC 1902 - same as GAUGE
43
+ ASN_TIMETICKS = (ASN_APPLICATION | 3)
44
+ ASN_OPAQUE = (ASN_APPLICATION | 4)
45
+ ASN_NSAP = (ASN_APPLICATION | 5) # historic - don't use
46
+ ASN_COUNTER64 = (ASN_APPLICATION | 6)
47
+ ASN_UINTEGER = (ASN_APPLICATION | 7) # historic - don't use
48
+
49
+ # Exception types for SNMPv2 and SNMPv3 (no value needed)
50
+ SNMP_NOSUCHOBJECT = (ASN_CONTEXT | ASN_PRIMITIVE | 0x0)
51
+ SNMP_NOSUCHINSTANCE = (ASN_CONTEXT | ASN_PRIMITIVE | 0x1)
52
+ SNMP_ENDOFMIBVIEW = (ASN_CONTEXT | ASN_PRIMITIVE | 0x2)
53
+
54
+
55
+ # PDU types
56
+ SNMP_MSG_GET = (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x0)
57
+ SNMP_MSG_GETNEXT = (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x1)
58
+ SNMP_MSG_RESPONSE = (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x2)
59
+ SNMP_MSG_SET = (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x3)
60
+ SNMP_MSG_TRAP = (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x4)
61
+ SNMP_MSG_GETBULK = (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x5)
62
+ SNMP_MSG_INFORM = (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x6)
63
+ SNMP_MSG_TRAP2 = (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x7)
64
+ SNMP_MSG_REPORT = (ASN_CONTEXT | ASN_CONSTRUCTOR | 0x8)
65
+
66
+
67
+ # Callback status codes
68
+ NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE = 1
69
+ NETSNMP_CALLBACK_OP_TIMED_OUT = 2
70
+ NETSNMP_CALLBACK_OP_SEND_FAILED = 3
71
+ NETSNMP_CALLBACK_OP_CONNECT = 4
72
+ NETSNMP_CALLBACK_OP_DISCONNECT = 5
73
+
74
+
75
+ # Error codes (the value of the field error-status in PDUs)
76
+
77
+ # in SNMPv1, SNMPsec, SNMPv2p, SNMPv2c, SNMPv2u, SNMPv2*, and SNMPv3 PDUs
78
+ SNMP_ERR_NOERROR = (0) # XXX Used only for PDUs?
79
+ SNMP_ERR_TOOBIG = (1)
80
+ SNMP_ERR_NOSUCHNAME = (2)
81
+ SNMP_ERR_BADVALUE = (3)
82
+ SNMP_ERR_READONLY = (4)
83
+ SNMP_ERR_GENERR = (5)
84
+
85
+ # in SNMPv2p, SNMPv2c, SNMPv2u, SNMPv2*, and SNMPv3 PDUs
86
+ SNMP_ERR_NOACCESS = (6)
87
+ SNMP_ERR_WRONGTYPE = (7)
88
+ SNMP_ERR_WRONGLENGTH = (8)
89
+ SNMP_ERR_WRONGENCODING = (9)
90
+ SNMP_ERR_WRONGVALUE = (10)
91
+ SNMP_ERR_NOCREATION = (11)
92
+ SNMP_ERR_INCONSISTENTVALUE = (12)
93
+ SNMP_ERR_RESOURCEUNAVAILABLE = (13)
94
+ SNMP_ERR_COMMITFAILED = (14)
95
+ SNMP_ERR_UNDOFAILED = (15)
96
+ SNMP_ERR_AUTHORIZATIONERROR = (16)
97
+ SNMP_ERR_NOTWRITABLE = (17)
98
+
99
+ # in SNMPv2c, SNMPv2u, SNMPv2*, and SNMPv3 PDUs
100
+ SNMP_ERR_INCONSISTENTNAME = (18)
101
+
102
+
103
+ # SNMP Errors
104
+ SNMPERR_SUCCESS = (0)
105
+ SNMPERR_GENERR = (-1)
106
+ SNMPERR_BAD_LOCPORT = (-2)
107
+ SNMPERR_BAD_ADDRESS = (-3)
108
+ SNMPERR_BAD_SESSION = (-4)
109
+ SNMPERR_TOO_LONG = (-5)
110
+ SNMPERR_NO_SOCKET = (-6)
111
+ SNMPERR_V2_IN_V1 = (-7)
112
+ SNMPERR_V1_IN_V2 = (-8)
113
+ SNMPERR_BAD_REPEATERS = (-9)
114
+ SNMPERR_BAD_REPETITIONS = (-10)
115
+ SNMPERR_BAD_ASN1_BUILD = (-11)
116
+ SNMPERR_BAD_SENDTO = (-12)
117
+ SNMPERR_BAD_PARSE = (-13)
118
+ SNMPERR_BAD_VERSION = (-14)
119
+ SNMPERR_BAD_SRC_PARTY = (-15)
120
+ SNMPERR_BAD_DST_PARTY = (-16)
121
+ SNMPERR_BAD_CONTEXT = (-17)
122
+ SNMPERR_BAD_COMMUNITY = (-18)
123
+ SNMPERR_NOAUTH_DESPRIV = (-19)
124
+ SNMPERR_BAD_ACL = (-20)
125
+ SNMPERR_BAD_PARTY = (-21)
126
+ SNMPERR_ABORT = (-22)
127
+ SNMPERR_UNKNOWN_PDU = (-23)
128
+ SNMPERR_TIMEOUT = (-24)
129
+ SNMPERR_BAD_RECVFROM = (-25)
130
+ SNMPERR_BAD_ENG_ID = (-26)
131
+ SNMPERR_BAD_SEC_NAME = (-27)
132
+ SNMPERR_BAD_SEC_LEVEL = (-28)
133
+ SNMPERR_ASN_PARSE_ERR = (-29)
134
+ SNMPERR_UNKNOWN_SEC_MODEL = (-30)
135
+ SNMPERR_INVALID_MSG = (-31)
136
+ SNMPERR_UNKNOWN_ENG_ID = (-32)
137
+ SNMPERR_UNKNOWN_USER_NAME = (-33)
138
+ SNMPERR_UNSUPPORTED_SEC_LEVEL = (-34)
139
+ SNMPERR_AUTHENTICATION_FAILURE = (-35)
140
+ SNMPERR_NOT_IN_TIME_WINDOW = (-36)
141
+ SNMPERR_DECRYPTION_ERR = (-37)
142
+ SNMPERR_SC_GENERAL_FAILURE = (-38)
143
+ SNMPERR_SC_NOT_CONFIGURED = (-39)
144
+ SNMPERR_KT_NOT_AVAILABLE = (-40)
145
+ SNMPERR_UNKNOWN_REPORT = (-41)
146
+ SNMPERR_USM_GENERICERROR = (-42)
147
+ SNMPERR_USM_UNKNOWNSECURITYNAME = (-43)
148
+ SNMPERR_USM_UNSUPPORTEDSECURITYLEVEL = (-44)
149
+ SNMPERR_USM_ENCRYPTIONERROR = (-45)
150
+ SNMPERR_USM_AUTHENTICATIONFAILURE = (-46)
151
+ SNMPERR_USM_PARSEERROR = (-47)
152
+ SNMPERR_USM_UNKNOWNENGINEID = (-48)
153
+ SNMPERR_USM_NOTINTIMEWINDOW = (-49)
154
+ SNMPERR_USM_DECRYPTIONERROR = (-50)
155
+ SNMPERR_NOMIB = (-51)
156
+ SNMPERR_RANGE = (-52)
157
+ SNMPERR_MAX_SUBID = (-53)
158
+ SNMPERR_BAD_SUBID = (-54)
159
+ SNMPERR_LONG_OID = (-55)
160
+ SNMPERR_BAD_NAME = (-56)
161
+ SNMPERR_VALUE = (-57)
162
+ SNMPERR_UNKNOWN_OBJID = (-58)
163
+ SNMPERR_NULL_PDU = (-59)
164
+ SNMPERR_NO_VARS = (-60)
165
+ SNMPERR_VAR_TYPE = (-61)
166
+ SNMPERR_MALLOC = (-62)
167
+ SNMPERR_KRB5 = (-63)
168
+ SNMPERR_PROTOCOL = (-64)
169
+ SNMPERR_OID_NONINCREASING = (-65)
170
+ SNMPERR_MAX = (-65)
171
+
172
+
173
+
174
+ USM_AUTH_KU_LEN = 32
175
+ USM_PRIV_KU_LEN = 32
176
+
177
+ # SNMPv3 Security Levels
178
+ SNMP_SEC_LEVEL_NOAUTH = 1
179
+ SNMP_SEC_LEVEL_AUTHNOPRIV = 2
180
+ SNMP_SEC_LEVEL_AUTHPRIV = 3
181
+
182
+ SNMP_DEFAULT_COMMUNITY_LEN = 0
183
+ SNMP_DEFAULT_RETRIES = -1
184
+ SNMP_DEFAULT_TIMEOUT = -1
185
+ SNMP_DEFAULT_REMPORT = 0
186
+ SNMP_DEFAULT_REQID = -1
187
+ SNMP_DEFAULT_MSGID = -1
188
+ SNMP_DEFAULT_ERRSTAT = -1
189
+ SNMP_DEFAULT_ERRINDEX = -1
190
+ SNMP_DEFAULT_ADDRESS = 0
191
+ SNMP_DEFAULT_ENTERPRISE_LENGTH = 0
192
+ SNMP_DEFAULT_TIME = 0
193
+ SNMP_DEFAULT_VERSION = -1
194
+ SNMP_DEFAULT_SECMODEL = -1
195
+ SNMP_DEFAULT_CONTEXT =
196
+
197
+ SNMP_MAX_MSG_SIZE = 1472
198
+ SNMP_MAX_MSG_V3_HDRS = (4+3+4+7+7+3+7+16)
199
+ SNMP_MAX_ENG_SIZE = 32
200
+ SNMP_MAX_SEC_NAME_SIZE = 256
201
+ SNMP_MAX_CONTEXT_SIZE = 256
202
+ SNMP_SEC_PARAM_BUF_SIZE = 256
203
+ SNMPV3_IGNORE_UNAUTH_REPORTS = 0
204
+ SNMP_SESS_NONAUTHORITATIVE = 0
205
+ SNMP_SESS_AUTHORITATIVE = 1
206
+ SNMP_SESS_UNKNOWNAUTH = 2
207
+ REPORT_STATS_LEN = 9
208
+ REPORT_snmpUnknownSecurityModels_NUM = 1
209
+ REPORT_snmpInvalidMsgs_NUM = 2
210
+ REPORT_usmStatsUnsupportedSecLevels_NUM = 1
211
+ REPORT_usmStatsNotInTimeWindows_NUM = 2
212
+ REPORT_usmStatsUnknownUserNames_NUM = 3
213
+ REPORT_usmStatsUnknownEngineIDs_NUM = 4
214
+ REPORT_usmStatsWrongDigests_NUM = 5
215
+ REPORT_usmStatsDecryptionErrors_NUM = 6
216
+ SNMP_DETAIL_SIZE = 512
217
+ SNMP_FLAGS_RESP_CALLBACK = 0x400
218
+ SNMP_FLAGS_USER_CREATED = 0x200
219
+ SNMP_FLAGS_DONT_PROBE = 0x100
220
+ SNMP_FLAGS_STREAM_SOCKET = 0x80
221
+ SNMP_FLAGS_LISTENING = 0x40
222
+ SNMP_FLAGS_SUBSESSION = 0x20
223
+ SNMP_FLAGS_STRIKE2 = 0x02
224
+ SNMP_FLAGS_STRIKE1 = 0x01
225
+
226
+
227
+ STAT_SNMPUNKNOWNSECURITYMODELS = 0
228
+ STAT_SNMPINVALIDMSGS = 1
229
+ STAT_SNMPUNKNOWNPDUHANDLERS = 2
230
+ STAT_MPD_STATS_START = 0
231
+ STAT_MPD_STATS_END = 2
232
+ STAT_USMSTATSUNSUPPORTEDSECLEVELS = 3
233
+ STAT_USMSTATSNOTINTIMEWINDOWS = 4
234
+ STAT_USMSTATSUNKNOWNUSERNAMES = 5
235
+ STAT_USMSTATSUNKNOWNENGINEIDS = 6
236
+ STAT_USMSTATSWRONGDIGESTS = 7
237
+ STAT_USMSTATSDECRYPTIONERRORS = 8
238
+ STAT_USM_STATS_START = 3
239
+ STAT_USM_STATS_END = 8
240
+ STAT_SNMPINPKTS = 9
241
+ STAT_SNMPOUTPKTS = 10
242
+ STAT_SNMPINBADVERSIONS = 11
243
+ STAT_SNMPINBADCOMMUNITYNAMES = 12
244
+ STAT_SNMPINBADCOMMUNITYUSES = 13
245
+ STAT_SNMPINASNPARSEERRS = 14
246
+ STAT_SNMPINTOOBIGS = 16
247
+ STAT_SNMPINNOSUCHNAMES = 17
248
+ STAT_SNMPINBADVALUES = 18
249
+ STAT_SNMPINREADONLYS = 19
250
+ STAT_SNMPINGENERRS = 20
251
+ STAT_SNMPINTOTALREQVARS = 21
252
+ STAT_SNMPINTOTALSETVARS = 22
253
+ STAT_SNMPINGETREQUESTS = 23
254
+ STAT_SNMPINGETNEXTS = 24
255
+ STAT_SNMPINSETREQUESTS = 25
256
+ STAT_SNMPINGETRESPONSES = 26
257
+ STAT_SNMPINTRAPS = 27
258
+ STAT_SNMPOUTTOOBIGS = 28
259
+ STAT_SNMPOUTNOSUCHNAMES = 29
260
+ STAT_SNMPOUTBADVALUES = 30
261
+ STAT_SNMPOUTGENERRS = 32
262
+ STAT_SNMPOUTGETREQUESTS = 33
263
+ STAT_SNMPOUTGETNEXTS = 34
264
+ STAT_SNMPOUTSETREQUESTS = 35
265
+ STAT_SNMPOUTGETRESPONSES = 36
266
+ STAT_SNMPOUTTRAPS = 37
267
+ STAT_SNMPSILENTDROPS = 39
268
+ STAT_SNMPPROXYDROPS = 40
269
+ STAT_SNMP_STATS_START = 9
270
+ STAT_SNMP_STATS_END = 40
271
+ STAT_SNMPUNAVAILABLECONTEXTS = 41
272
+ STAT_SNMPUNKNOWNCONTEXTS = 42
273
+ STAT_TARGET_STATS_START = 41
274
+ STAT_TARGET_STATS_END = 42
275
+ MAX_STATS = 43
276
+ PARSE_PACKET = 0
277
+ DUMP_PACKET = 1
278
+ MAX_SUBID = 0xFFFFFFFF
279
+ MIN_OID_LEN = 2
280
+
281
+ MAX_NAME_LEN = 128
282
+
283
+ OID_SYS_UP_TIME_INSTANCE = '1.3.6.1.2.1.1.3.0'
284
+ OID_SNMP_TRAP_OID = '1.3.6.1.6.3.1.1.4.1.0'
285
+ end
286
+ end
287
+ end