Sha256: d321cd6313bcf2ea812ad3491a31e9b89326ee374fff1ccc416d3afa6e21d0a9

Contents?: true

Size: 710 Bytes

Versions: 1

Compression:

Stored size: 710 Bytes

Contents

require 'snmpjr/wrappers/transport'
require 'snmpjr/response'

class Snmpjr
  class Session

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

    def start
      @snmp.listen
    end

    def send pdu, target
      begin
        result = @snmp.send(pdu, target)
        if result.response.nil?
          Snmpjr::Response.new(:error => 'Request timed out')
        else
          Snmpjr::Response.new(:value => result.response.variable_bindings.first.variable.to_s)
        end
      rescue Exception => error
        Snmpjr::Response.new(:error => error.to_s)
      end
    end

    def close
      @snmp.close
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
snmpjr-0.1.4-java lib/snmpjr/session.rb