Skip to content

Instantly share code, notes, and snippets.

@dLobatog
Created July 25, 2019 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dLobatog/0ea95043431c0c38e223bbfb1cdfb860 to your computer and use it in GitHub Desktop.
Save dLobatog/0ea95043431c0c38e223bbfb1cdfb860 to your computer and use it in GitHub Desktop.
Host.find_each(100).map do |host|
inventory_host = HostInventoryAPI.new(
host,
host.account,
Settings.host_inventory_url,
host.account.b64identity
).host_already_in_inventory
if inventory_host
old_id = host.id
host.update(id: inventory_host.id)
ProfileHost.where(host_id: old_id).update_all(host_id: inventory_host.id)
RuleResult.where(host_id: old_id).update_all(host_id: inventory_host.id)
else
# Host is not in the inventory? Do not destroy as API could be broken
host.not_found
end
end
class Host
def not_found
not_found_count += 1
destroy if not_found > 3
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment