Module: SNMP4EM::SNMPCommonRequests
- Included in:
- Manager
- Defined in:
- lib/snmp4em/snmp_common_requests.rb
Instance Method Summary collapse
-
#get(oids, args = {}) ⇒ Object
Sends an SNMP-GET request to the remote agent for all OIDs specified in the oids array.
-
#getnext(oids, args = {}) ⇒ Object
Sends an SNMP-GETNEXT request to the remote agent for all OIDs specified in the oids array.
-
#set(oids, args = {}) ⇒ Object
Sends an SNMP-SET request to the remote agent for all OIDs specified in the oids hash.
-
#walk(oids, args = {}) ⇒ Object
Sends a series of SNMP-GETNEXT requests to simulate an SNMP “walk” operation.
Instance Method Details
#get(oids, args = {}) ⇒ Object
Sends an SNMP-GET request to the remote agent for all OIDs specified in the oids array. Returns a SNMP4EM::SnmpGetRequest object, which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the result will be a hash, mapping requested OID values to results. Errors will be returned as a SNMP::ResponseError.
Optional arguments can be passed into args, including:
-
return_raw - Return objects and errors as their raw SNMP types, such as SNMP::Integer instead of native Ruby integers, SNMP::OctetString instead of native Ruby strings, etc. (default: false)
-
version - Override the version provided in the Manager constructor
13 14 15 16 |
# File 'lib/snmp4em/snmp_common_requests.rb', line 13 def get(oids, args = {}) request = SnmpGetRequest.new(self, oids, args.merge(:version => @version)) if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end end |
#getnext(oids, args = {}) ⇒ Object
Sends an SNMP-GETNEXT request to the remote agent for all OIDs specified in the oids array. Returns a SNMP4EM::SnmpGetRequest object, which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the result will be a hash, mapping requested OID values to two-element arrays consisting of [next_oid , next_value]. OIDs resulting in an error will map to an instance of SNMP::ResponseError instead.
Optional arguments can be passed into args, including:
-
return_raw - Return objects and errors as their raw SNMP types, such as SNMP::Integer instead of native Ruby integers, SNMP::OctetString instead of native Ruby strings, etc. (default: false)
-
version - Override the version provided in the Manager constructor
27 28 29 30 |
# File 'lib/snmp4em/snmp_common_requests.rb', line 27 def getnext(oids, args = {}) request = SnmpGetNextRequest.new(self, oids, args.merge(:version => @version)) if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end end |
#set(oids, args = {}) ⇒ Object
Sends an SNMP-SET request to the remote agent for all OIDs specified in the oids hash. The hash must map OID values to requested values. Values can either be specified as Ruby native strings/integers, or as SNMP-specific classes (SNMP::IpAddress, etc). Returns a SNMP4EM::SnmpSetRequest object, which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the result will be a hash, mapping requested OID values to the returned value from the agent. Any values that were stored successfully will map to true, otherwise, the value will map to an instance of SNMP::ResponseError instead.
Optional arguments can be passed into args, including:
-
version - Override the version provided in the Manager constructor
41 42 43 44 |
# File 'lib/snmp4em/snmp_common_requests.rb', line 41 def set(oids, args = {}) request = SnmpSetRequest.new(self, oids, args.merge(:version => @version)) if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end end |
#walk(oids, args = {}) ⇒ Object
Sends a series of SNMP-GETNEXT requests to simulate an SNMP “walk” operation. Given an OID prefix, the library will keep requesting the next OID until that returned OID does not begin with the requested prefix. This gives the ability to retrieve entire portions of the SNMP tree in one “operation”. Multiple OID prefixes can be passed into the oids array, and will be fetched in parallel. The function returns a SNMP4EM::SnmpWalkRequest object, which implements EM::Deferrable. From there, implement a callback/errback to fetch the result. On success, the result will be a hash, mapping requested OID prefixes to the returned value. Successful walks will be mapped to a hash, where each pair is represented as (oid => value). Unsuccessful walks will be mapped to an instance of SNMP::ResponseError.
Optional arguments can be passed into args, including:
-
return_raw - Return objects and errors as their raw SNMP types, such as SNMP::Integer instead of native Ruby integers, SNMP::OctetString instead of native Ruby strings, etc. (default: false)
-
max_results - Maximum number of results to be returned for any single OID prefix (default: nil = unlimited)
-
version - Override the version provided in the Manager constructor
58 59 60 61 |
# File 'lib/snmp4em/snmp_common_requests.rb', line 58 def walk(oids, args = {}) request = SnmpWalkRequest.new(self, oids, args.merge(:version => @version)) if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end end |