Clear down your site config via the RestAPI

A number of our larger customers scan different portions of their estate at different times. This means that between scans, they need to delete the previous scan data without re-installing the application.

Up to and including the Gwynn R3 release, this was achieved using an SQL Stored Procedure.

With the Hilary release, this functionality was exposed via the RestAPI

Hillary R1 method

Hillary R1 was the first iQSonar version which supported this functionality via the RestAPI. The exposed method was called using a GET request. (GET is the normal http request type.) Note: the encoded username and password pair in the CURL call corresponds to the login 'admin' and password 'password' which are the default iQSonar credentials you are forced to change on when you log in the first time.

Delete configuration using CURL
curl -H 'Authorization: Basic YWRtaW46cGFzc3dvcmQ=' 'http://youriqsonarserver/api/v1/deletetargets'

As iQSonar is always installed on a Microsoft Windows server, PowerShell should always be available to the administrator. To invoke the same URL using powershell, we can prompt for a username and password then use the Invoke-RestMethod cmdlet

Delete targets with PowerShell
$cred = Get-Credential
$url = 'http://youriqsonarserver/api/v1/deletetargets'
Invoke-RestMethod -Credential $cred -Uri $url

The response will return an ID code that can be used in subsequent calls to see if the request has completed. A large estate may take some time to clear down.

Hillary R2 and later method

As the delete targets command changes the underlying data, using a GET request to do this is technically not compliant with the RestAPI specification as GET requests are supposed to be idempotent (i.e. calling the same request multiple times will return the same result, and GET requests are not supposed to change the underlying data store). Therefore this API endpoint was changed in Hillary R2 to comply with the RestAPI Specification.

Delete configuration using CURL
curl -X 'DELETE' -H 'Authorization: Basic YWRtaW46cGFzc3dvcmQ=' 'http://youriqsonarserver/api/v1/targets'

As iQSonar is always installed on a Microsoft Windows server, PowerShell should always be available to the administrator. To invoke the same URL using powershell, we can prompt for a username and password then use the Invoke-RestMethod cmdlet

Delete targets with PowerShell
$cred = Get-Credential
$url = 'http://youriqsonarserver/api/v1/targets'
Invoke-RestMethod -Method DELETE -Credential $cred -Uri $url

 The response will return an ID code that can be used in subsequent calls to see if the request has completed. A large estate may take some time to clear down.

Sample results: using the example above for an iQSonar instance installed on the host 'vm-mike-rc', we get the following:

It can take some time to clear down a complex estate. The RestAPI endpoint 'targets/deletestatus/<statusid>' will let us know when the task is complete. The screenshot below uses the request_id from the previous request to check if the target deletion has completed:

Now, if we go to the UI, we will see that all the target locations are empty of targets, but the credentials still exist.