Class: NETSNMP::Session
- Inherits:
-
Object
- Object
- NETSNMP::Session
- Includes:
- Loggable
- Defined in:
- lib/netsnmp/session.rb
Overview
Let’s just remind that there is no session in snmp, this is just an abstraction.
Direct Known Subclasses
Defined Under Namespace
Classes: Transport
Constant Summary collapse
- TIMEOUT =
2
Constants included from Loggable
Loggable::DEBUG, Loggable::DEBUG_LEVEL
Instance Method Summary collapse
-
#build_pdu(type, *vars) ⇒ NETSNMP::PDU
A pdu.
-
#close ⇒ Object
Closes the session.
-
#initialize(version: 1, community: "public", **options) ⇒ Session
constructor
A new instance of Session.
-
#send(pdu) ⇒ NETSNMP::PDU
send a pdu, receives a pdu.
Methods included from Loggable
Constructor Details
#initialize(version: 1, community: "public", **options) ⇒ Session
Returns a new instance of Session.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/netsnmp/session.rb', line 12 def initialize(version: 1, community: "public", **) @version = case version when Integer then version # assume the use know what he's doing when /v?1/ then 0 when /v?2c?/ then 1 when /v?3/ then 3 else raise "unsupported snmp version (#{version})" end @community = community validate(**) initialize_logger(**) end |
Instance Method Details
#build_pdu(type, *vars) ⇒ NETSNMP::PDU
Returns a pdu.
38 39 40 |
# File 'lib/netsnmp/session.rb', line 38 def build_pdu(type, *vars) PDU.build(type, version: @version, community: @community, varbinds: vars) end |
#close ⇒ Object
Closes the session
27 28 29 30 31 |
# File 'lib/netsnmp/session.rb', line 27 def close # if the transport came as an argument, # then let the outer realm care for its lifecycle @transport.close unless @proxy end |
#send(pdu) ⇒ NETSNMP::PDU
send a pdu, receives a pdu
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/netsnmp/session.rb', line 48 def send(pdu) log { "sending request..." } log(level: 2) { pdu.to_hex } encoded_request = pdu.to_der log { Hexdump.dump(encoded_request) } encoded_response = @transport.send(encoded_request) log { "received response" } log { Hexdump.dump(encoded_response) } response_pdu = PDU.decode(encoded_response) log(level: 2) { response_pdu.to_hex } response_pdu end |