Class: NETSNMP::Session

Inherits:
Object
  • Object
show all
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

V3Session

Defined Under Namespace

Classes: Transport

Constant Summary collapse

TIMEOUT =
2

Instance Method Summary collapse

Constructor Details

#initialize(version: 1, community: "public", **options) ⇒ Session

Returns a new instance of Session.

Parameters:

  • opts (Hash)

    the options set



9
10
11
12
13
# File 'lib/netsnmp/session.rb', line 9

def initialize(version: 1, community: "public", **options)
  @version   = 1
  @community = community
  validate(options)
end

Instance Method Details

#build_pdu(type, *vars) ⇒ NETSNMP::PDU

Returns a pdu.

Parameters:

  • type (Symbol)

    the type of PDU (:get, :set, :getnext)

  • vars (Array<Hashes>)

    collection of options to generate varbinds (see NETSMP::Varbind.new for all the possible options)

Returns:



27
28
29
# File 'lib/netsnmp/session.rb', line 27

def build_pdu(type, *vars)
  PDU.build(type, headers: [ @version, @community ], varbinds: vars)
end

#closeObject

Closes the session



16
17
18
19
20
# File 'lib/netsnmp/session.rb', line 16

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

Parameters:

Returns:



37
38
39
40
41
# File 'lib/netsnmp/session.rb', line 37

def send(pdu)
  encoded_request = encode(pdu) 
  encoded_response = @transport.send(encoded_request)
  decode(encoded_response)
end