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.

...

Other documents in the Knowlede Base showing how to produce equivalent results have been written for PHP 7 (which produces HTML output), PERL and for PowerShell

A longer worked example in python can be found here.

Pre-requsites

  • NOTE: both Python 2 and Python 3 are actively used in different environments. This example uses Python 3 syntax.
  • You need to know the URL for you iQSonar install - in this example our host is iqsonar-host
  • You need credentials for the iQSonar install - in this example we use the default login admin / password
  • You need the  "requests" module for Python which handles web requests very nicely. If this is not installed on your system you can install it as follows:

...

Code Block
languagepy
titleConnect to host
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.

...