Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

This is the second in a series of articles giving extended example of how to use the RestAPI. This article will demonstrate how to generate a report equivalent to the Version 3 "OutputApplications" view using PowerShell. For a shorter example that returns a simpler dataset, you can see the article Use RestAPI and PHP to generate a list of Applications.

Fields in the original report

Field NameV3 DescriptionV4 Comment
HostnameThe hostname of the device the application is running onGet this from the Applications endpoint. Possibly a list of devices.
Might need to follow the Applications/Application_ID enpoint for some clusters.
FQDNFully Qualified Domain Name of the deviceGet this from the Applications endpoint. Possibly a list of devices.
Might need to follow the Applications/Application_ID enpoint for some clusters.
SoftwareNameSoftwareName Enterprise application nameGet this from the Applications endpoint.
SoftwareVersionVersionGet this from the Applications endpoint.
SoftwareVendorSoftware vendor nameGet this from the Applications endpoint.
SoftwareEditionSoftware Edition (Enterprise, Web, etc)Get this from the Applications endpoint where applicable.
InstanceIdentifierUnique application nameFor database applications, this is in the "name" field of the Applications endpoint.
ClusterInformationThe cluster that the physical machine is part of.See clusters and/or parent_cluster in the Applications endpoint.
IN V3 this contained the cluster name and list of nodes separated by ";" for some cluster types, but not all
UserCountNumber of users (where applicable)Get this from the Applications/Application_ID endpoint
LastScanDateTimestamp of last scanGet this from the Applications endpoint.
LocationLocation of the application (user defined, inherited from the device location)Get this from the Applications endpoint device section for non-clustered applications.
LanguageSQL Server instance language (SQL Server only)Not exposed via V4 RestAPI
ApplicationIDUnique Identifier for the applicationGet this from the Applications endpoint.
DeviceIDUnique Identifier for the device. Can be used to map to OutputDevicesGet this from the Applications endpoint device section for non-clustered applications. Possibly a list of devices.
Might need to follow the Applications/Application_ID enpoint for some clusters.
DNSHostnameThe hostname for the device as reported by DNSGet this from the Applications endpoint device section for non-clustered applications. Possibly a list of devices.
Might need to follow the Applications/Application_ID enpoint for some clusters.
DNSFQDNThe FQDN for the device as reported from DNSGet this from the Applications endpoint device section for non-clustered applications. Possibly a list of devices.
Might need to follow the Applications/Application_ID enpoint for some clusters.
EvidenceThis column not available in V4Not exposed via V4 RestAPI


Connect to the RestAPI

The RestAPI uses HTTP basic authentication rather than domain credentials. To write a script that extracts data from the RestAPI you will need to know the login name and password for an iQSonar user who has the "access Rest API" permission enabled. By default the admin user always has this permission. These variables will need to be configured for your site:

Initial connection
$user    = "admin"
$pass    = "password"
$sonar	 = "iQSonar Host"
$secpass = ConvertTo-SecureString $pass -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($user,$secpass)

The first step is to determine exactly how many applications we're going to be collecting data for. This information is returned in the header of the RestAPI return value. By default a call to the devices endpoint will return a batch of 200 devices, and the user is expected to page through the list of available devices by making successive calls to this endpoint using an offset parameter to specify how many devices have already been seen. The fetch_size parameter is used to determine how many devices are returned per batch. The fastest way to determine the total number of available applications is to explicitly request the first device only. Since we want data from the headers of the result, we use the Invoke-WebRequest PowerShell cmdlet to get this information.

Get total number of devices
$uri     = -join ("http://", $sonar, "/api/v1/applications/?offset=1&fetch_size=1")
$r = Invoke-WebRequest $uri -Credential $credential
 
# $r.headers has HTML headers, $r.content has text content
$appCount = $r.headers.'X-fetch-count'
  • No labels