Class: Net::SNMP::ProviderDsl
- Inherits:
-
Object
- Object
- Net::SNMP::ProviderDsl
- Includes:
- Debug
- Defined in:
- lib/net/snmp/agent/provider_dsl.rb
Overview
A ProviderDsl represents the context in which each handler for the varbinds of a single message are executed. The ProviderDsl object lives only as long as a single message is being processed, and offers convenience functions for accessing the members of the request as well as providing responses for each varbind in the request.
Instance Attribute Summary collapse
-
#message ⇒ Object
The message object for the current request.
-
#response_pdu ⇒ Object
The response PDU being constructed for the current request.
-
#varbind ⇒ Object
‘varbind` is the current varbind.
Instance Method Summary collapse
-
#add_varbind(options) ⇒ Object
Adds a varbind to the response PDU.
-
#echo ⇒ Object
(also: #ok)
Adds a copy of the current varbind to the response packet Useful in a set, to indicate success to the manager.
-
#end_of_mib ⇒ Object
Adds a varbind to the response indicating that the END OF MIB has been reached.
-
#error(the_error) ⇒ Object
(also: #errstat, #error_status)
Sets the error_status on the response pdu.
-
#initialize ⇒ ProviderDsl
constructor
A new instance of ProviderDsl.
-
#max_repetitions ⇒ Object
The maximum number of repetitions for each bulk retrieved varbind.
-
#no_such_instance(oid = nil) ⇒ Object
Adds a varbind to the response indicating that no such instance exists at the given oid.
-
#no_such_object(oid = nil) ⇒ Object
Adds a varbind to the response indicating that no such object exists at the given oid.
-
#oid ⇒ Object
The OID of the current varbind being processed.
-
#oid_str ⇒ Object
The OID of the current varbind being processed as a string.
-
#pdu ⇒ Object
The PDU for the current request.
-
#reply(varbind_options) ⇒ Object
(also: #add)
Used to set a varbind on the response packet.
-
#value ⇒ Object
The value of the current varbind being processed.
-
#variable ⇒ Object
The MIB variable name of the current varbind.
Methods included from Debug
Constructor Details
#initialize ⇒ ProviderDsl
Returns a new instance of ProviderDsl.
12 13 14 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 12 def initialize @variable_index = 1 end |
Instance Attribute Details
#message ⇒ Object
The message object for the current request.
26 27 28 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 26 def @message end |
#response_pdu ⇒ Object
The response PDU being constructed for the current request.
29 30 31 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 29 def response_pdu @response_pdu end |
#varbind ⇒ Object
‘varbind` is the current varbind. The RequestDispatcher resets this value for each varbind in the request, then execs the approriate provider’s handler for that varbind in the context of this ProviderDsl object.
23 24 25 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 23 def varbind @varbind end |
Instance Method Details
#add_varbind(options) ⇒ Object
Adds a varbind to the response PDU. MUST use this method (or one that delegates to it) to set response varbinds on the response_pdu to make sure the variable_index is maintained automatically.
119 120 121 122 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 119 def add_varbind() response_pdu.add_varbind() @variable_index += 1 end |
#echo ⇒ Object Also known as: ok
Adds a copy of the current varbind to the response packet Useful in a set, to indicate success to the manager
86 87 88 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 86 def echo add_varbind(oid: varbind.oid, type: varbind.type, value: varbind.value) end |
#end_of_mib ⇒ Object
Adds a varbind to the response indicating that the END OF MIB has been reached
110 111 112 113 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 110 def end_of_mib oid ||= varbind.oid add_varbind(oid: oid, type: Constants::SNMP_ENDOFMIBVIEW) end |
#error(the_error) ⇒ Object Also known as: errstat, error_status
Sets the error_status on the response pdu
125 126 127 128 129 130 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 125 def error(the_error) response_pdu.error = the_error response_pdu.error_index = @variable_index # echo the varbind back to the manager so it can tell what object failed echo end |
#max_repetitions ⇒ Object
The maximum number of repetitions for each bulk retrieved varbind
57 58 59 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 57 def max_repetitions pdu.max_repetitions end |
#no_such_instance(oid = nil) ⇒ Object
Adds a varbind to the response indicating that no such instance exists at the given oid. If no oid is supplied, or if oid is nil, then the oid from the current varbind is used.
104 105 106 107 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 104 def no_such_instance(oid=nil) oid ||= varbind.oid add_varbind(oid: oid, type: Constants::SNMP_NOSUCHINSTANCE) end |
#no_such_object(oid = nil) ⇒ Object
Adds a varbind to the response indicating that no such object exists at the given oid. If no oid is supplied, or if oid is nil, then the oid from the current varbind is used.
96 97 98 99 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 96 def no_such_object(oid=nil) oid ||= varbind.oid add_varbind(oid: oid, type: Constants::SNMP_NOSUCHOBJECT) end |
#oid ⇒ Object
The OID of the current varbind being processed.
37 38 39 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 37 def oid varbind.oid end |
#oid_str ⇒ Object
The OID of the current varbind being processed as a string.
47 48 49 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 47 def oid_str varbind.oid.to_s end |
#pdu ⇒ Object
The PDU for the current request.
32 33 34 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 32 def pdu .pdu end |
#reply(varbind_options) ⇒ Object Also known as: add
Used to set a varbind on the response packet.
-
If a hash is supplied, accepts the same options as PDU#add_varbind, except that if no oid is supplied, the oid from the current varbind is used.
-
If the argument is not a hash, it is used as the value of the varbind, with the current varbind’s oid, and the type is derived as with PDU#add_varbind
72 73 74 75 76 77 78 79 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 72 def reply() if .kind_of?(Hash) [:oid] ||= varbind.oid add_varbind() else add_varbind(oid: varbind.oid, value: ) end end |
#value ⇒ Object
The value of the current varbind being processed.
52 53 54 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 52 def value varbind.value end |
#variable ⇒ Object
The MIB variable name of the current varbind
42 43 44 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 42 def variable oid.label end |