Skip to content

Instantly share code, notes, and snippets.

@zerwes
Last active June 10, 2020 03:33
Show Gist options
  • Save zerwes/05cd99012ac329833f0355bcb84214f6 to your computer and use it in GitHub Desktop.
Save zerwes/05cd99012ac329833f0355bcb84214f6 to your computer and use it in GitHub Desktop.
#! /usr/bin/env ruby
require 'sophos/sg/rest'
require "resolv"
client = Sophos::SG::REST::Client.new(
'https://$RESTAPIUSER:$TOKEN@$URL:$PORT/api/',
fingerprint: '$CERTHASH')
typelist = ['host', 'group', 'network', 'range']
typelist.each do |type|
olist = client.objects('network/'+type)
olist.each do |href|
begin
ousedby = client.get(client.path_object('network/'+type+'/', href._ref) + '/usedby')
if ousedby.objects.length == 0 and ousedby.nodes.length == 0
unusedo = client.object('network/'+type, href._ref)
puts 'unused network/'+type+' definition: '+unusedo.name
# client.destroy_object(unusedo.to_h)
end
end
end
end
# vim: tabstop=2 expandtab shiftwidth=2 softtabstop=2 smartindent nu
@zerwes
Copy link
Author

zerwes commented Nov 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment