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.
-
#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.
Methods included from Debug
#debug, #fatal, #info, #print_packet, #time, #warn
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.
108 109 110 111 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 108 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
81 82 83 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 81 def echo add_varbind(oid: varbind.oid, type: varbind.type, value: varbind.value) end |
#error(the_error) ⇒ Object Also known as: errstat, error_status
Sets the error_status on the response pdu
114 115 116 117 118 119 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 114 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
52 53 54 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 52 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.
99 100 101 102 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 99 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.
91 92 93 94 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 91 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.
42 43 44 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 42 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
67 68 69 70 71 72 73 74 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 67 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.
47 48 49 |
# File 'lib/net/snmp/agent/provider_dsl.rb', line 47 def value varbind.value end |