Fix some blocked/allow laggards after migrating. Add DuckDB for outstanding analyitcs performance. Start adding an import for all bot networks
This commit is contained in:
@@ -15,31 +15,14 @@ class FetchIpapiDataJob < ApplicationJob
|
||||
ipapi_data = Ipapi.lookup(sample_ip)
|
||||
|
||||
if ipapi_data.present? && !ipapi_data.key?('error')
|
||||
# Check if IPAPI returned a different route than our tracking network
|
||||
ipapi_route = ipapi_data.dig('asn', 'route')
|
||||
target_network = tracking_network
|
||||
# Process IPAPI data and create network ranges
|
||||
result = Ipapi.process_ipapi_data(ipapi_data, tracking_network)
|
||||
|
||||
if ipapi_route.present? && ipapi_route != tracking_network.cidr
|
||||
# IPAPI returned a different CIDR - find or create that network range
|
||||
Rails.logger.info "IPAPI returned different route: #{ipapi_route} (requested: #{tracking_network.cidr})"
|
||||
# Mark the tracking network as having been queried
|
||||
# Use the broadest CIDR returned for deduplication
|
||||
tracking_network.mark_ipapi_queried!(result[:broadest_cidr])
|
||||
|
||||
target_network = NetworkRange.find_or_create_by(network: ipapi_route) do |nr|
|
||||
nr.source = 'api_imported'
|
||||
nr.creation_reason = "Created from IPAPI lookup for #{tracking_network.cidr}"
|
||||
end
|
||||
|
||||
Rails.logger.info "Storing IPAPI data on correct network: #{target_network.cidr}"
|
||||
end
|
||||
|
||||
# Store data on the target network (wherever IPAPI said it belongs)
|
||||
target_network.set_network_data(:ipapi, ipapi_data)
|
||||
target_network.last_api_fetch = Time.current
|
||||
target_network.save!
|
||||
|
||||
# Mark the tracking network as having been queried, with the CIDR that was returned
|
||||
tracking_network.mark_ipapi_queried!(target_network.cidr)
|
||||
|
||||
Rails.logger.info "Successfully fetched IPAPI data for #{tracking_network.cidr} (stored on #{target_network.cidr})"
|
||||
Rails.logger.info "Successfully fetched IPAPI data for #{tracking_network.cidr} (created #{result[:networks].length} networks)"
|
||||
|
||||
# Broadcast to the tracking network
|
||||
broadcast_ipapi_update(tracking_network, ipapi_data)
|
||||
|
||||
Reference in New Issue
Block a user