Class: NETSNMP::V3Session

Inherits:
Session
  • Object
show all
Defined in:
lib/netsnmp/v3_session.rb

Overview

Abstraction for the v3 semantics.

Constant Summary

Constants inherited from Session

Session::TIMEOUT

Constants included from Loggable

Loggable::DEBUG, Loggable::DEBUG_LEVEL

Instance Method Summary collapse

Methods inherited from Session

#close

Constructor Details

#initialize(context: "", **opts) ⇒ V3Session

Returns a new instance of V3Session.

Parameters:

  • version (String, Integer)

    SNMP version (always 3)



7
8
9
10
11
12
# File 'lib/netsnmp/v3_session.rb', line 7

def initialize(context: "", **opts)
  @context = context
  @security_parameters = opts.delete(:security_parameters)
  super
  @message_serializer = Message.new(**opts)
end

Instance Method Details

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

Returns a pdu.

Returns:

See Also:

  • NETSNMP::V3Session.{NETSNMP{NETSNMP::Session{NETSNMP::Session#build_pdu}


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

def build_pdu(type, *vars)
  engine_id = security_parameters.engine_id
  ScopedPDU.build(type, headers: [engine_id, @context], varbinds: vars)
end

#send(pdu) ⇒ Object

See Also:

  • NETSNMP::V3Session.{NETSNMP{NETSNMP::Session{NETSNMP::Session#send}


23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/netsnmp/v3_session.rb', line 23

def send(pdu)
  log { "sending request..." }
  encoded_request = encode(pdu)
  encoded_response = @transport.send(encoded_request)
  response_pdu, *args = decode(encoded_response)
  if response_pdu.type == 8
    varbind = response_pdu.varbinds.first
    if varbind.oid == "1.3.6.1.6.3.15.1.1.2.0" # IdNotInTimeWindow
      _, @engine_boots, @engine_time = args
      raise IdNotInTimeWindowError, "request timestamp is already out of time window"
    end
  end
  response_pdu
end