-
-
Save rlsit/6bf583b346ea3a54fe7325613e4f234b to your computer and use it in GitHub Desktop.
list unused objects on a sophos SG via rest api
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 | |
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