Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The REST API allows users to query the iQSonar results directly using the web client protocol. The results are returned in JSON format. This article is part of a series on how to make use of the Rest API.

This worked example uses PowerShell to produce a CSV file containing details of devices directly from the scan results. We look for the host name, the total installed RAM and the CPU type. The device name will be listed in the "device" results. For the CPU Type and the installed RAM we need to then go to the details page for the device.

...

Code Block
languagepowershell
titleFor each device, get hostname, ram, cpu
$count = 01
$uri_a = 'http://iqsonar-host/api/v1/devices/?offset='
$uri_b = '&fetch_size=1'

# This is going to hold the CSV file, let's build the header row
$csv = @() 
$row = New-Object System.Object
$row | Add-Member -MemberType NoteProperty -Name "Host" -Value $null
$row | Add-Member -MemberType NoteProperty -Name "RAM" -Value $null
$row | Add-Member -MemberType NoteProperty -Name "CPU Type" -Value $null


while ($count -le $deviceCount)
{	
	# Build the URL
	$count = $count + 1
	$url =  -join ($uri_a, $count, $uri_b )
	$dev = Invoke-RestMethod $url -Credential $credential
	
	$row = New-Object System.Object
	# Put the hostname in to the row
	$row | Add-Member -MemberType NoteProperty -Name "Host" -Value $dev.host_name ; 
	# Get the link to the rest of the details	
	$url2 = $dev.self	
	$device = Invoke-RestMethod $url2 -Credential $credential
	
	$row | Add-Member -MemberType NoteProperty -Name "RAM" -Value device.total_memory_mb
	$row | Add-Member -MemberType NoteProperty -Name "CPU Type" -Value $device.cpu.cpu_model
	$csv += $row
	# display progress
	write-host "." -nonewline
	$count = $count + 1
}

Step Three - save the output

...