module SNMP4EM::SNMPCommonRequests

Public Instance Methods

get(oids, args = {}) click to toggle source

Sends an SNMP-GET request to the remote agent for all OIDs specified in the oids array. Returns a {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 {SNMP4EM::Manager} constructor

   # File lib/snmp4em/snmp_common_requests.rb
13 def get(oids, args = {})
14   request = SnmpGetRequest.new(self, oids, args.merge(:version => @version))
15   if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end
16 end
getnext(oids, args = {}) click to toggle source

Sends an SNMP-GETNEXT request to the remote agent for all OIDs specified in the oids array. Returns a {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 {SNMP4EM::Manager} constructor

   # File lib/snmp4em/snmp_common_requests.rb
27 def getnext(oids, args = {})
28   request = SnmpGetNextRequest.new(self, oids, args.merge(:version => @version))
29   if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end
30 end
set(oids, args = {}) click to toggle source

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 {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 {SNMP4EM::Manager} constructor

   # File lib/snmp4em/snmp_common_requests.rb
41 def set(oids, args = {})
42   request = SnmpSetRequest.new(self, oids, args.merge(:version => @version))
43   if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end
44 end
walk(oids, args = {}) click to toggle source

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 {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 {SNMP4EM::Manager} constructor

   # File lib/snmp4em/snmp_common_requests.rb
58 def walk(oids, args = {})
59   request = SnmpWalkRequest.new(self, oids, args.merge(:version => @version))
60   if (@fiber || args[:fiber]) then wrap_in_fiber(request) else request end
61 end