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 Python 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 | ||||
---|---|---|---|---|
| ||||
import requests r = requests.get('http://iqsonar-host/api/v1/devices',auth=('admin','password')) max = r.headers['X-fetch-count'] data = r.json() count = len(data) |
By default the REST API "/api/v1/devices" page will return 200 devices at a time. We can increase or decrease this using the "fetch_size" parameter. The variable max contains the total number of devices. If this is more than 200 we would need to fetch a second batch - see other worked examples in this series for more details on that. In this example we will print at most 200. data holds the RestAPI data converted into a Python data structure, count is the number of devices returned. Also note that if you specify incorrect credentials, Python will throw an exception when you call the r.headers method.
At this point in the script, we have a variable data which contains the JSON output from the Rest API.
...