lib/logstash/inputs/snmp.rb in logstash-input-snmp-1.3.0 vs lib/logstash/inputs/snmp.rb in logstash-input-snmp-1.3.1

- old
+ new

@@ -190,56 +190,76 @@ end end def run(queue) # for now a naive single threaded poller which sleeps off the remaining interval between - # each run. each run polls all the defined hosts for the get and walk options. + # each run. each run polls all the defined hosts for the get, table and walk options. stoppable_interval_runner.every(@interval, "polling hosts") do - @client_definitions.each do |definition| - client = definition[:client] - result = {} - if !definition[:get].empty? - oids = definition[:get] - begin - result = result.merge(client.get(oids, @oid_root_skip, @oid_path_length)) - rescue => e - logger.error("error invoking get operation for OIDs: #{oids}, ignoring", - host: definition[:host_address], exception: e, backtrace: e.backtrace) + poll_clients(queue) + end + end + + def poll_clients(queue) + @client_definitions.each do |definition| + client = definition[:client] + host = definition[:host_address] + result = {} + + if !definition[:get].empty? + oids = definition[:get] + begin + data = client.get(oids, @oid_root_skip, @oid_path_length) + if data + result.update(data) + else + logger.debug? && logger.debug("get operation returned no response", host: host, oids: oids) end + rescue => e + logger.error("error invoking get operation, ignoring", host: host, oids: oids, exception: e, backtrace: e.backtrace) end - if !definition[:walk].empty? - definition[:walk].each do |oid| - begin - result = result.merge(client.walk(oid, @oid_root_skip, @oid_path_length)) - rescue => e - logger.error("error invoking walk operation on OID: #{oid}, ignoring", - host: definition[:host_address], exception: e, backtrace: e.backtrace) + end + + if !definition[:walk].empty? + definition[:walk].each do |oid| + begin + data = client.walk(oid, @oid_root_skip, @oid_path_length) + if data + result.update(data) + else + logger.debug? && logger.debug("walk operation returned no response", host: host, oid: oid) end + rescue => e + logger.error("error invoking walk operation, ignoring", host: host, oid: oid, exception: e, backtrace: e.backtrace) end end + end - if !Array(@tables).empty? - @tables.each do |table_entry| - begin - result = result.merge(client.table(table_entry, @oid_root_skip, @oid_path_length)) - rescue => e - logger.error("error invoking table operation on OID: #{table_entry['name']}, ignoring", - host: definition[:host_address], exception: e, backtrace: e.backtrace) + if !Array(@tables).empty? + @tables.each do |table_entry| + begin + data = client.table(table_entry, @oid_root_skip, @oid_path_length) + if data + result.update(data) + else + logger.debug? && logger.debug("table operation returned no response", host: host, table: table_entry) end + rescue => e + logger.error("error invoking table operation, ignoring", + host: host, table_name: table_entry['name'], exception: e, backtrace: e.backtrace) end end + end - unless result.empty? - event = targeted_event_factory.new_event(result) - event.set(@host_protocol_field, definition[:host_protocol]) - event.set(@host_address_field, definition[:host_address]) - event.set(@host_port_field, definition[:host_port]) - event.set(@host_community_field, definition[:host_community]) - decorate(event) - queue << event - else - logger.debug? && logger.debug("no snmp data retrieved", host: definition[:host_address]) - end + unless result.empty? + event = targeted_event_factory.new_event(result) + event.set(@host_protocol_field, definition[:host_protocol]) + event.set(@host_address_field, definition[:host_address]) + event.set(@host_port_field, definition[:host_port]) + event.set(@host_community_field, definition[:host_community]) + decorate(event) + queue << event + else + logger.debug? && logger.debug("no snmp data retrieved", host: definition[:host_address]) end end end def stoppable_interval_runner