This article details how to generate report using the RestAPI which will mirror as closely as possible the "OutputDevices" report which was available in V3 of iQSonar.
You can download the latest version of the file: OutputDevices-v1.ps1, and simply customise the $user, $pass and $sonar values and it should run in your environment
...
Field | V3 Comment | RestAPI Comment |
---|---|---|
Hostname | Hostname of the device | Get this from the /devices RestAPI endpoint |
FQDN | Fully QUalified Domain Name of the device | Get this from the /devices/{Device_ID} RestAPI endpoint |
OS | OS description and service pack | Get this from the /devices/{Device_ID} RestAPI endpoint |
OS Install Date | OS description and service pack | Get this from the /devices/{Device_ID} RestAPI endpoint May not always be available |
Location | Location of the device | In V4 this represents the target configuration set used to define the device. Get this from the /devices RestAPI endpoint |
Serial Number | The serial number of the device | Get this from the /devices RestAPI endpoint |
PhysicalCPUCount | Number of physical CPUs or sockets in the Physical Device (which may differ from the Virtual or Logical host when a device is a virtual machine or partition) | IF the device is a physical device, this information is derived from the /devices/{Device_ID} RestAPI endpoint Where the virtualisation host is not scanned, then this field and all the other information about the physical host will not be able to be populated. |
PhysicalCoreCount | Sum of cores across all CPUs in the Physical Device (which may differ from the Virtual or Logical host when a device is a virtual machine or partition) | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
PhysicalCoresPerCPU | Physical core count divided by the physical CPU count | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
PhysicalCPUManufacturer | Manufacturer of the CPU on the Physical Device | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
PhysicalCPUModel | Model of the CPU on the Physical Device | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
PhysicalCPUSpeed | Speed of the CPU on the Physical Device | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
PhysicalRAM | Total amount of RAM on the Physical Device | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
VirtualCPUCount | Number of Virtual CPUs perceived by the device (only populated when the device is Virtual or Logical) | Get this from the /devices/{Device_ID} RestAPI endpoint; Only available if device is virtual or logical |
VirtualCoreCount | Sum of Cores perceived by the device (only populated when the device is Virtual or Logical) | Get this from the /devices/{Device_ID} RestAPI endpoint; Only available if device is virtual or logical |
VirtualRAM | Amount of perceived RAM by the device (only populated when the device is Virtual or Logical) | Get this from the /devices/{Device_ID} RestAPI endpoint; Only available if device is virtual or logical |
DeviceModel | Model of the device | Get this from the /devices RestAPI endpoint for a physical device. |
PhysicalModelSocketCount | Number of sockets that may be populated with physical CPUs on the Physical Device | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
PhysicalModelCoreCount | Maximum number of cores per CPU according to the model documentation | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
PhysicalDeviceManufacturer | Manufacturer of the Physical Device | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
PhysicalHostname | Hostname of the Physical Device | Get this from the /devices/{Device_ID} RestAPI endpoint for virtual devices; May not always be available |
PhysicalFQDN | Fully Qualified Domain Name of the Physical Device | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
IP Address |
| V4 also exposes IP6 addresses. |
PhysicalMACAddress | If more than 1, will be semi-colon separated. | |
VirtualMACAddress | If more than 1, will be semi-colon separated. | |
ClusterInformation | The virtualization cluster that the physical machine is part of | Only available if it is part of a cluster, and the cluster has been scanned |
ClusterName | Name of cluster | Only available if it is part of a cluster, and the cluster has been scanned |
PartitioningMethod | Virtualization Method (VMware, HyperV, LPAR etc.). If this field is null it indicates the device is physical. | |
DerivedCPU | Not directly available via RestAPI. Must be coded in the script. | |
DerivedCoresPerCPU | Not directly available via RestAPI. Must be coded in the script. | |
Bios | Concatenation of Device.BIOSName, DeviceBIOSManufacturer, Device.BIOSVersion separated by semi-colons. | Get this from the /devices/{Device_ID} RestAPI endpoint. |
LastScanDate | Last date the device was scanned | Get this from the /devices/{Device_ID} RestAPI endpoint. |
DeviceID | The unique identifier for this device | The Rest API gives unique identifiers in GUID format |
PhysicalDeviceID | The unique identifier of the Physical Device (where relevant) – used to map logical devices or Virtual machines back to the Physical Device which hosts them. | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
PhysicalCPUNotes | Notes that indicate CPU vs socket mismatches or CPU core values that don’t match the CPU model | This V3 data is not directly available via RestAPI. This functionality is part of DataHub for V4, and if required must be coded in the script. |
Notes | Notes related to the device model | This V3 data is not directly available via RestAPI. This functionality is part of DataHub for V4, and if required must be coded in the script. |
ExternalLink | Link to model documentation from the vendor | This V3 data is not available via RestAPI. |
DNSHostname | The hostname of the device as reported from DNS | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
DNSFQDN | The fully qualified hostname of the device as reported from DNS | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
PhysicalDNSHostname | The hostname of the physical device as reported from DNS | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
PhysicalDNSFQDN | The fully qualified hostname of the physical device as reported from DNS | Get this from the /devices/{Device_ID} RestAPI endpoint; May not always be available |
MeasurementComment | Will contain additional info such as “Believed to be: Oracle Linux Server release 5.7” where appropriate | This V3 data is not available via RestAPI. |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
else { # This is a virtual target if ( ($currDevice.cpu_count -eq 0) -or (!$currDevice.cpu_count) ) { # Physical CPU info not avialble $row | Add-Member -MemberType NoteProperty -Name "VirtualCPUCount" -Value "n/a" $row | Add-Member -MemberType NoteProperty -Name "VirtualCoreCount" -Value "n/a" $row | Add-Member -MemberType NoteProperty -Name "PhysicalCoresPerCPU" -Value "n/a" $row | Add-Member -MemberType NoteProperty -Name "PhysicalCPUManufacturer" -Value "n/a" $row | Add-Member -MemberType NoteProperty -Name "PhysicalCPUModel" -Value "n/a" $row | Add-Member -MemberType NoteProperty -Name "PhysicalCPUSpeed" -Value "n/a" } $row | Add-Member -MemberType NoteProperty -Name "VirtualCPUCount" -Value $currDevice.cpu_count $row | Add-Member -MemberType NoteProperty -Name "VirtualCoreCount" -Value $currDevice.core_count $row | Add-Member -MemberType NoteProperty -Name "VirtualRAM" -Value = $currDevice.total_memory_mb $row | Add-Member -MemberType NoteProperty -Name "DeviceModel" -Value $currDevice.model # Do something with MAC addresses for VMs # Now, if the VM host we're running on was scanned, we can do something with the following: if (!$currDevice.virtual_host.device_id) { # host not scanned, record an error by putting "n/a" in physical hostname, leave everything else blank $row | Add-Member -MemberType NoteProperty -Name "PhysicalHostname" -Value "n/a" } else { # host was scanned, so let's populate as many details as possible about the physical host $row | Add-Member -MemberType NoteProperty -Name "PhysicalCPUCount" -Value $currDevice.virtual_host.cpu_count $row | Add-Member -MemberType NoteProperty -Name "PhysicalCoreCount" -Value $currDevice.virtual_host.core_count if ( ($currDevice.virtual_host.cpu_count -ne 0) -and ($currDevice.virtual_host.core_count -ne 0)) { $cpcpu = $currDevice.virtual_host.core_count / $currDevice.virtual_host.cpu_count $row | Add-Member -MemberType NoteProperty -Name "PhysicalCoresPerCPU" -Value $cpcpu } # In order to get the CPU Manufacturer information, you need to follow the link to # $currDevice.virtual_host.self and parse the CPU info there. This is left as an exercise to the user $row | Add-Member -MemberType NoteProperty -Name "PhysicalCPUModel" -Value "n/a" $row | Add-Member -MemberType NoteProperty -Name "PhysicalCPUSpeed" -Value "n/a" $row | Add-Member -MemberType NoteProperty -Name "PhysicalRAM" -Value $currDevice.virtual_host.total_memory_mb $row | Add-Member -MemberType NoteProperty -Name "PhysicalDeviceManufacturer" -Value $currDevice.virtual_host.manufacturer $row | Add-Member -MemberType NoteProperty -Name "PhysicalHostname" -Value $currDevice.virtual_host.host_name # In order to get the MAC Address for the physical host, you need to follow the link to # $currDevice.virtual_host.self and parse the MAC info there. This is left as an exercise to the user $row | Add-Member -MemberType NoteProperty -Name "PhysicalMACAddress" -Value "n/a" } } |
But... we want all the
...
columns in the same order as the original report
The script above works to extract the data, but if you want to feed the CSV file to a data processing application which was written for a V3 datasource, you probably want to have the columns in the "correct" order (including empty columns) so that your third party application does not need to be reconfigured or re-written. So, to force all the columns to be saved, including the columns that are always empty, and to have the columns in the correct order corresponding to the original V3 file, we use the Select-Object powershell cmdlet, and pipe the results into the Export-CSV cmdlet.
This produces a very long line of code, so we use backticks to break it up for readibility
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
$csv | Select-Object Hostname, FQDN, OS, OS-Install-Date, Location, Serial-Number, PhysicalCPUCount, PhysicalCoreCount, PhysicalCoresPerCPU, ` PhysicalCPUManufacturer, PhysicalCPUModel, PhysicalCPUSpeed, PhysicalRAM, VirtualCPUCount, VirtualCoreCount, VirtualRAM, DeviceModel, ` PhysicalModelSocketCount, PhysicalModelCoreCount, PhysicalDeviceManufacturer, PhysicalHostname, PhysicalFQDN, IP-Address, ` PhysicalMACAddress, VirtualMACAddress, ClusterInformation, ClusterName, PartitioningMethod, DerivedCPU, DerivedCoresPerCPU, ` Bios, LastScanDate, DeviceID, PhysicalDeviceID, PhysicalCPUNotes, Notes, ExternalLink, DNSHostname, DNSFQDN, PhysicalDNSHostname, ` PhysicalDNSFQDN, MeasurementComment | Export-csv OutputDevices.csv -NoTypeInformation |
...