I am running a ruby script right now which executes an action based on a specific type of filtering.
Its a system that purges assets older than 90 days. I've created a new query that looks for members of a exception group.
I cannot figure out at all how to handle checking if the old_assets array member is a group of the Ignore_assets member and if they do match skip that one asset and do not delete it.
puts 'Logged into Nexpose'
at_exit { nsc.logout }
ignore_assets = Nexpose::AssetGroup.load(nsc, 30).devices.each do |device|
puts "Asset ID to be Ignored: #{device.id}"
end
puts "Searching for Assets to Delete"
old_assets = nsc.filter(Search::Field::SCAN_DATE, Search::Operator::EARLIER_THAN, '90')
old_assets.each do |asset|
nsc.delete_asset(asset.id)
puts ("Asset ID to be Deleted: #{asset.id}")
end
puts "Assets have been deleted."
EDIT: I have to match it by device.id because of the way the assets are defined. See below
Asset ID to be Ignored: 8773
#<Nexpose::Device:0x3a28358>
Asset ID to be Deleted: 8773
#<Nexpose::FilteredAsset:0x3a287a8>