Class: Snmpjr::SessionV2C

Inherits:
Object
  • Object
show all
Defined in:
lib/snmpjr/session_v2c.rb

Direct Known Subclasses

SessionV3

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSessionV2C

Returns a new instance of SessionV2C.



8
9
10
# File 'lib/snmpjr/session_v2c.rb', line 8

def initialize
  @snmp = Snmpjr::Wrappers::Snmp.new(Snmpjr::Wrappers::Transport::DefaultUdpTransportMapping.new)
end

Instance Attribute Details

#snmpObject (readonly)

Returns the value of attribute snmp.



6
7
8
# File 'lib/snmpjr/session_v2c.rb', line 6

def snmp
  @snmp
end

Instance Method Details

#closeObject



31
32
33
# File 'lib/snmpjr/session_v2c.rb', line 31

def close
  @snmp.close
end

#send(pdu, target) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/snmpjr/session_v2c.rb', line 16

def send pdu, target
  begin
    result = @snmp.send(pdu, target)
  rescue Exception => error
    raise RuntimeError.new(error)
  end
  if result.response.nil?
    raise Snmpjr::TargetTimeoutError.new('Request timed out')
  else
    result.response.variable_bindings.map{|vb|
      construct_response(vb)
    }
  end
end

#startObject



12
13
14
# File 'lib/snmpjr/session_v2c.rb', line 12

def start
  @snmp.listen
end