Skip to content

Instantly share code, notes, and snippets.

@rlsit
Forked from zerwes/sophosUnusedObjects.rb
Last active January 4, 2018 12:49
Show Gist options
  • Save rlsit/6bf583b346ea3a54fe7325613e4f234b to your computer and use it in GitHub Desktop.
Save rlsit/6bf583b346ea3a54fe7325613e4f234b to your computer and use it in GitHub Desktop.
list unused objects on a sophos SG via rest api
#! /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