Last active
June 10, 2020 03:33
-
-
Save zerwes/05cd99012ac329833f0355bcb84214f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://ideas.sophos.com/forums/17359-sg-utm/suggestions/178309-definitions-show-unused-objects