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.
...
Field Name | V3 Description | V4 Comment |
---|---|---|
Hostname | The hostname of the device the application is running on | Get this from the Applications endpoint. Possibly a list of devices. Might need to follow the Applications/Application_ID enpoint for some clusters. |
FQDN | Fully Qualified Domain Name of the device | Get this from the Applications endpoint. Possibly a list of devices. Might need to follow the Applications/Application_ID enpoint for some clusters. |
SoftwareName | SoftwareName Enterprise application name | Get this from the Applications endpoint. |
SoftwareVersion | Version | Get this from the Applications endpoint. |
SoftwareVendor | Software vendor name | Get this from the Applications endpoint. |
SoftwareEdition | Software Edition (Enterprise, Web, etc) | Get this from the Applications endpoint where applicable. |
InstanceIdentifier | Unique application name | Use the name field in the Applications endpoint. For database applications, this is in the "instance" name. For VMWare clusters it is the node name, etc. |
ClusterInformation | The 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 |
UserCount | Number of users (where applicable) | Get this from the Applications/Application_ID endpoint |
LastScanDate | Timestamp of last scan | Get this from the Applications endpoint. |
Location | Location of the application (user defined, inherited from the device location) | Get this from the Applications endpoint device section for non-clustered applications. |
Language | SQL Server instance language (SQL Server only) | Not exposed via V4 RestAPI |
ApplicationID | Unique Identifier for the application | Get this from the Applications endpoint. |
DeviceID | Unique Identifier for the device. Can be used to map to OutputDevices | Get 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. |
DNSHostname | The hostname for the device as reported by DNS | Get 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. |
DNSFQDN | The FQDN for the device as reported from DNS | Get 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. |
Evidence | This column not available in V4 | Not exposed via V4 RestAPI |
...
Build the CSV file header row
PowerShell has a number of built in libraries for handling output to various file formats. For this example we will be saving the results in a CSV file that can be viewed directly in EXCEL or imported into other databases.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# Build the CSV File header row $csv = @() $row = New-Object System.Object $row | Add-Member -MemberType NoteProperty -Name "Hostname" -Value $null $row | Add-Member -MemberType NoteProperty -Name "FQDN" -Value $null $row | Add-Member -MemberType NoteProperty -Name "SoftwareName" -Value $null $row | Add-Member -MemberType NoteProperty -Name "SoftwareVersion" -Value $null $row | Add-Member -MemberType NoteProperty -Name "SoftwareVendor" -Value $null $row | Add-Member -MemberType NoteProperty -Name "SoftwareEdition" -Value $null $row | Add-Member -MemberType NoteProperty -Name "InstanceIdentifier" -Value $null $row | Add-Member -MemberType NoteProperty -Name "ClusterInformation" -Value $null $row | Add-Member -MemberType NoteProperty -Name "UserCount" -Value $null $row | Add-Member -MemberType NoteProperty -Name "LastScanDate" -Value $null $row | Add-Member -MemberType NoteProperty -Name "Location" -Value $null $row | Add-Member -MemberType NoteProperty -Name "Language" -Value $null $row | Add-Member -MemberType NoteProperty -Name "ApplicationID" -Value $null $row | Add-Member -MemberType NoteProperty -Name "DeviceID" -Value $null $row | Add-Member -MemberType NoteProperty -Name "DNSHostname" -Value $null $row | Add-Member -MemberType NoteProperty -Name "DNSFQDN" -Value $null $row | Add-Member -MemberType NoteProperty -Name "Evidence" -Value $null |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
$offset = 1 # offset
$seen = 1; # first offset is 1, not 0
while ( $seen -lt $appCount)
{
$url = -join ("http://", $sonar, "/api/v1/applications/?offset=", $offset, "&fetch_size=", $fs)
$applications = Invoke-RestMethod $url -Credential $credential
$i = 1
while ($i -lt $applications.count)
{
# Process $applications[$i]
$csv += $row
$i = $i + 1; # keep track for inner loop
$seen = $seen + 1; # keep track for outer loop
if ( $seen % 10 -eq 0) {
# progress indicator - display a "." every 10 devices
write-host "." -nonewline
}
}
# Finished this batch
$offset = $seen
}
write-host " Done. Saving output to OutputApplications.csv now."
$csv | Export-csv OutputApplications.csv -NoTypeInformation # We will further refine this line later |
...