Class: EventMachine::SnmpAgent::ProtocolHandler

Inherits:
Connection
  • Object
show all
Defined in:
lib/snmpagent/agent.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ProtocolHandler

Returns a new instance of ProtocolHandler.



36
37
38
# File 'lib/snmpagent/agent.rb', line 36

def initialize *args
	super
end

Instance Method Details

#receive_data(data) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/snmpagent/agent.rb', line 42

def receive_data data
	pdu = Net::SnmpPdu.parse(data.read_ber(Net::SNMP::AsnSyntax))
	result = @handler.process_request pdu.pdu_type, pdu.community, pdu.variables
	if result.error_status
		resp = Net::SnmpPdu.new
		resp.pdu_type = :get_response
		resp.request_id = pdu.request_id
		resp.error_status = result.error_status
		resp.error_index = result.error_index if result.error_index
		if result.variables
			result.variables.each {|name, value| resp.add_variable_binding name, value}
		end
		send_data resp.to_ber_string
	end
end

#set_handler(handler) ⇒ Object



39
40
41
# File 'lib/snmpagent/agent.rb', line 39

def set_handler handler
	@handler = handler
end