# # Name: WFA Data Source for OCI # Vers: 2.0.0 # From: NetApp # Desc: Reads in data source information from an OnCommand Insight 7.0(+) # environment and saves results to the WFA database. # Revision History # 1.0.0 = Initial Version # 1.1.0 = Added new dictionary annotation_enum_value to take care of enum value separately. # 1.2.0 = Added code to handle non-US numbers and validating minimum Powershell version required for OCI data source script. # 2.0.0 = Improved code scalability by more than 500x # Added Host-specific Logger for easy execution trace. # Removed Get-WfaLogger and the unnecessary REST calls it was making. This should speed of code execution # Support for TLSv1.2 needed for OCI7.2 # # Author : Abhishek Sinha # Email : sinhaa@netapp.com [System.Threading.Thread]::CurrentThread.CurrentCulture="en-US" if ($PSVersionTable.PSVersion.Major -le '2') { throw("Minimum PowerShell version required is 3.0") } ###### Create the Logger Configuration WFA ###### #Load the assembley from your dll location $PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent $dllLocation=$PSScriptRoot.Substring(0, $($PSScriptRoot.Length - 24)) + "PoSH\Modules\DataONTAP\log4net.dll" [void][Reflection.Assembly]::LoadFrom($dllLocation) #Define your logging pattern. See more about it here: http://logging.apache.org/log4net/release/sdk/log4net.Layout.PatternLayout.html $pattern="%d %w %-5p %c : %m%n" #Reset the log4net configuration [log4net.LogManager]::ResetConfiguration() #Create the Logging file for every single Datasource based on the Hostname. $DSHostName = Get-WfaRestParameter "host" $logFile=$PSScriptRoot.Substring(0, $($PSScriptRoot.Length - 8)) + "\log\" + $DSHostName +".log" New-Item -Path $logFile -type file -Force #Create the log4net config Appender $Appender = new-object log4net.Appender.FileAppender $Appender.File = $logFile $Appender.Layout = new-object log4net.Layout.PatternLayout($pattern) $Appender.Threshold = [log4net.Core.Level]::All $Appender.ActivateOptions() [log4net.Config.BasicConfigurator]::Configure($Appender) #Create Logger for the DataSource Type Name. You can actually put anything $logg = [log4net.LogManager]::GetLogger("[OnCommand Insight 7.x]") ###### Logger is ready ##### $logg.Info("====== Data Source acquisition begins now =======") # Global hash tables $APIVersion = 1.0 # Global Annotation and Applications $AnnotationsData = @{} $AnnotationIdByLabel = @{} $ApplicationsData = @{} $ApplicationIdByName = @{} # Storage resources $StorageArraysData = @{} $StorageNodesData = @{} $StoragePoolsData = @{} $DisksData = @{} $InternalVolumesData = @{} $VolumesData = @{} # Annotation associations $StorageArrayAnnotationsData = @{} $StorageNodeAnnotationsData = @{} $StoragePoolAnnotationsData = @{} $InternalVolumeAnnotationsData = @{} $VolumeAnnotationsData = @{} $HostAnnotationsData = @{} $SwitchAnnotationsData = @{} $DataStoreAnnotationsData = @{} $AnnotationEnumValuesData = @{} # Application associations $VolumesApplicationsData = @{} $InternalVolumesApplicationsData = @{} $HostsApplicationsData = @{} $VirtualMachinesApplicationsData = @{} # Connectivity $FabricsData = @{} $PortsData = @{} $SwitchesData = @{} # Virtualization $HostsData = @{} $DataStoresData = @{} $VirtualMachinesData = @{} $VMDKsData = @{} $DataStoreHostsData = @{} # Performance $StorageArrayPerformanceData = @{} $StorageNodePerformanceData = @{} $StoragePoolPerformanceData = @{} $DataStorePerformanceData = @{} # Global counter to generate identifiers $global:CommonCounter = 1 $global:DataStoreIdCounter = 1 $DataStoreGeneratedIdByLongId = @{} $global:VirtualMachineIdCounter = 1 $VirtualMachineGeneratedIdByLongId = @{} $global:SpecialCharacterData = @() ############################################################################## # Utility functions ############################################################################## Function ConvertToMb { Param( [parameter(Mandatory=$true)] [long] $value, [parameter(Mandatory=$true)] [string] $unit ) [long]$unitInMb = 0 if ($unit -eq "KiB") { $unitInMb = $value * 0.001024 } if ($unit -eq "MiB") { $unitInMb = $value * 1.05 } if ($unit -eq "TiB") { $unitInMb = $value * 1099511 } if ($unit -eq "KB") { $unitInMb = $value / 1000 } if ($unit -eq "MB") { $unitInMb = $value } if ($unit -eq "GB") { $unitInMb = $value * 1000 } if ($unit -eq "TB") { $unitInMb = $value * 1000 * 1000 } return $unitInMb } Function ConvertToMhz { Param( [parameter(Mandatory=$true)] [long] $value, [parameter(Mandatory=$true)] [string] $unit ) [long]$unitInMhz = 0 if ($unit -eq "Mhz") { $unitInMhz = $value } if ($unit -eq "Ghz") { $unitInMhz = $value * 1024 } return $unitInMhz } # # Name: Output-Data # Func: Write the inventory output. # function Output-Data( $FileName, $HashTable ) { try { New-Item -Path $FileName -Type file -Force | Out-Null } catch [System.Exception] { throw $( "ERROR: Could not create CSV file for dictionary entry " + $FileName) } $HashTable.GetEnumerator() | Sort Name |% { AddRowToFile -File $FileName -Values $_.Value } foreach ($row in $global:SpecialCharacterData) { AddSpecialCharacterRowToFile -File $FileName -Values $row } $global:SpecialCharacterData = @() } # Name: AddSpecialCharacterRowToFile # Func: Adds one row to the CSV file with proper tabs and \N for null columns function AddSpecialCharacterRowToFile { param( [string]$File, [array]$Values ) Add-Content $File ($Values) -Encoding UTF8 } function AddRowToFile { param( [string]$File, [array]$Values ) $nullFreeValues=@() foreach ($val in $Values) { if ($val -eq $null) { $nullFreeValues += "\N" } else { $nullFreeValues += $val } } $rowStr = ($nullFreeValues -join "`t") + "`n" try{ Add-Content $File ([byte[]][char[]] $rowStr) -Encoding Byte } catch { $global:SpecialCharacterData +=$rowStr } } # # Name: New-OCIConnection # Func: Get the paramters for login (WFA or command line) to an OCI # server, creates the # function New-OCIConnection( [parameter(mandatory=$false, position=0)][string]$Hostname, [parameter(mandatory=$false, position=1)][string]$Port, [parameter(mandatory=$false, position=2)][string]$Username, [parameter(mandatory=$false, position=3)][string]$Password ) { # use command line paramters if specified if ( $Username -and $Password ) { $AuthInfo = ( "{0}:{1}" -f $Username, $Password ) } else { try { $Hostname = Get-WfaRestParameter "host" $Port = Get-WfaRestParameter "port" $Credentials = Get-WfaCredentials } catch { throw $("ERROR: Data source credentials could not be obtained. " + $_) } $AuthInfo = ( "{0}:{1}" -f $Credentials.Username, $Credentials.Password ) } # Build authentication header $AuthInfo = [System.Text.Encoding]::UTF8.GetBytes( $AuthInfo ) $AuthInfo = [System.Convert]::ToBase64String( $AuthInfo ) $Headers = @{ Authorization=( "Basic {0}" -f $AuthInfo ) } # ignore not trusted certificate - from OCI PS samples add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class OCIDontCarePolicy : ICertificatePolicy { public OCIDontCarePolicy() {} public bool CheckValidationResult( ServicePoint sPoint, X509Certificate cert, WebRequest wRequest, int certProb) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object OCIDontCarePolicy #Set security protocol as TLSv1.2 [System.Net.ServicePointManager]::SecurityProtocol = "Tls12" $BaseUri = $( "https://" + $Hostname + ":" + $Port ) if ( $Port -eq 80 -or $Port -eq 8080 ) { $BaseUri = $( "http://" + $Hostname + ":" + $Port ) } # return the values $BaseUri, $Headers } # # Name: ConvertFrom-StringToPSObjects # Func: Convert String json data into PSObject[] # function ConvertFrom-StringToPSObjects( $stringData ) { if(([appdomain]::currentdomain.getassemblies() | Where {$_ -match "System.Web.Extensions"}) -eq $null) { #Assembly is not loaded. Load it now $logg.Info("Assembly System.Web.Extensions not loaded. Loading it now") [void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions") } $jsonSerialObj= New-Object -TypeName System.Web.Script.Serialization.JavaScriptSerializer $jsonSerialObj.MaxJsonLength = 2147483647 $PsObjects = $jsonSerialObj.DeserializeObject($stringData) $PsObjects } # # Name: CheckFor-PSObject # Func: Checks if the result returned by Invoke-RestMethod is a PSObject[] or a string # function CheckFor-PSObject ( $Data ) { if( ($Data.GetType()).name -eq "String" ) { $false } else { $true } } # Set of functions that retrieve data from OCI through REST calls # # Name: Get-Annotations # Func: Get the Annotation data from the OCI database via REST. # function Get-Annotations( [parameter(Mandatory=$True, Position=0)]$BaseUri, [parameter(Mandatory=$True, Position=1)]$Headers ) { try { $Uri = $BaseUri + "/rest/v1/assets/annotations" $logg.Info("Retrieving annotations with URI: " + $Uri) $Annotations = Invoke-RestMethod -Uri $Uri -Headers $Headers if( !(CheckFor-PSObject($Annotations)) ) { $logg.Error("Annotations is not returned as PSObject[].Converting it to PSObject[]") $Annotations = ConvertFrom-StringToPSObjects($Annotations) } $logg.Info("Retrieved annotations. Annotations count: " + $Annotations.Count) } catch { throw $( "ERROR: Could not get annotation information from OCI server: " + $_ ) } Save-Annotations $Annotations } # # Name: Get-Fabrics # Func: Get the Fabrics data from the OCI database via REST. # function Get-Fabrics( [parameter(Mandatory=$True, Position=0)]$BaseUri, [parameter(Mandatory=$True, Position=1)]$Headers ) { try { $Uri = $BaseUri + "/rest/v1/assets/fabrics" $logg.Info("Retrieving fabrics with URI: " + $Uri) $Fabrics = Invoke-RestMethod -Uri $Uri -Headers $Headers if( !(CheckFor-PSObject($Fabrics)) ) { $logg.Error("Fabrics is not returned as PSObject[].Converting it to PSObject[]") $Fabrics = ConvertFrom-StringToPSObjects($Fabrics) } $logg.Info("Retrieved fabrics. Fabrics count: " + $Fabrics.count) } catch { throw $( "ERROR: Could not get fabric information from OCI server: " + $_ ) } Save-Fabrics $Fabrics # Iterate each fabric and get expanded data for ( $i = 0; $i -lt $Fabrics.count; $i++ ) { try { $Uri = $($BaseUri + "/rest/v1/assets/fabrics/" + $Fabrics[$i].id + "?expand=switches.ports,switches.annotations") $ExpandedFabric = Invoke-RestMethod -Uri $Uri -Headers $Headers } catch { throw $( "ERROR: Could not get expanded fabric information from OCI server: " + $_ ) } if( !(CheckFor-PSObject($ExpandedFabric)) ) { $logg.Error("ExpandedFabric is not returned as PSObject[].Converting it to PSObject[]") $ExpandedFabric = ConvertFrom-StringToPSObjects($ExpandedFabric) } if ( $ExpandedFabric.switches ) { $Switches = $ExpandedFabric.switches Save-Switches $Fabrics[$i].id $Switches for ($j = 0; $j -lt $Switches.count; $j++) { if ($Switches[$j].ports) { Save-Ports $Switches[$j].id $Switches[$j].ports } if ($Switches[$j].annotations -and $APIVersion -ge 1.2) { Save-ObjectAnnotations $SwitchAnnotationsData $Switches[$j].id $Switches[$j].annotations } } } } $logg.Info("Invoked all fabric details") } # # Name: Get-DataStores # Func: Get the DataStores data from the OCI database via REST. # function Get-DataStores( [parameter(Mandatory=$True, Position=0)]$BaseUri, [parameter(Mandatory=$True, Position=1)]$Headers ) { try { $Uri = $BaseUri + "/rest/v1/assets/dataStores" $logg.Info("Retrieving datastores with URI: " + $Uri) $DataStores = Invoke-RestMethod -Uri $Uri -Headers $Headers if( !(CheckFor-PSObject($DataStores)) ) { $logg.Error("DataStores is not returned as PSObject[].Converting it to PSObject[]") $DataStores = ConvertFrom-StringToPSObjects($DataStores) } $logg.Info("Retrieved datastores. DataStores count: " + $DataStores.count) } catch { $logg.Error("ERROR: Could not get datastore asset information from OCI server: " + $_) throw $( "ERROR: Could not get datastore asset information from OCI server: " + $_ ) } # Iterate each datastore and get expanded data for ( $i = 0; $i -lt $DataStores.count; $i++ ) { try { $EpochStart = new-object DateTime 1970,1,1,0,0,0,([DateTimeKind]::Utc) [long]$Totime = [long]([DateTime]::UtcNow - $EpochStart).TotalSeconds * 1000 [long]$FromTime = $Totime - 1296000000 # 1296000000 is Number of milliseconds for 15 days $Uri = $($BaseUri + "/rest/v1/assets/dataStores/" + $DataStores[$i].id + "?expand=storageResources,annotations,vmdks.virtualMachine,hosts,performance&fromTime=" + $FromTime + "&toTime=" + $Totime ) $ExpandedDataStore = Invoke-RestMethod -Uri $Uri -Headers $Headers if( !(CheckFor-PSObject($ExpandedDataStore)) ) { $logg.Error("ExpandedDataStore is not returned as Object[].Converting it to PSObject[] : " + $Uri) $ExpandedDataStore = ConvertFrom-StringToPSObjects($ExpandedDataStore) } } catch { $logg.Error("ERROR: Could not get expanded data for datastores from OCI server: " + $_) throw $( "ERROR: Could not get expanded data for datastores from OCI server: " + $_ ) } Save-DataStore $ExpandedDataStore $DataStoreGeneratedId = $DataStoreGeneratedIdByLongId[$ExpandedDataStore.id] if ( $ExpandedDataStore.vmdks ) { Save-VMDKs $DataStoreGeneratedId $ExpandedDataStore.vmdks } if ( $ExpandedDataStore.annotations -and $APIVersion -ge 1.2 ) { Save-ObjectAnnotations $DataStoreAnnotationsData $DataStoreGeneratedId $ExpandedDataStore.annotations } if ( $ExpandedDataStore.hosts ) { $hosts = $ExpandedDataStore.hosts for ($j = 0; $j -lt $hosts.count; $j++) { $rowValues = $null,$DataStoreGeneratedId,$hosts[$j].id $DataStoreHostsData.Add($global:CommonCounter,$rowValues) $global:CommonCounter++ } } if ( $ExpandedDataStore.performance ) { Save-DataStorePerformance $DataStoreGeneratedId $ExpandedDataStore.performance } } $logg.Info("Invoked all datastore details") } # # Name: Get-StorageArrays # Func: Get the Storage data and related object types like nodes, pools, volumes from the OCI database via REST. # function Get-StorageArrays( [parameter(Mandatory=$True, Position=0)]$BaseUri, [parameter(Mandatory=$True, Position=1)]$Headers ) { try { $Uri = $BaseUri + "/rest/v1/assets/storages" $logg.Info("Retrieving storage arrays with URI: " + $Uri) $StorageArrays = Invoke-RestMethod -Uri $Uri -Headers $Headers if( !(CheckFor-PSObject($StorageArrays)) ) { $logg.Error("StorageArrays is not returned as PSObject[].Converting it to PSObject[]") $StorageArrays = ConvertFrom-StringToPSObjects($StorageArrays) } $logg.Info("Retrieved storage arrays. Storage arrays count: " + $StorageArrays.count) } catch { $logg.Error("ERROR: Could not get storage array information from OCI server: " + $_ ) throw $( "ERROR: Could not get storage array information from OCI server: " + $_ ) } Save-StorageArrays $StorageArrays # Iterate each storage array and get expanded data for ( $i = 0; $i -lt $StorageArrays.count; $i++ ) { try { $EpochStart = new-object DateTime 1970,1,1,0,0,0,([DateTimeKind]::Utc) [long]$Totime = [long]([DateTime]::UtcNow - $EpochStart).TotalSeconds * 1000 [long]$FromTime = $Totime - 1296000000 # 1296000000 is Number of milliseconds for 15 days $Uri = $( $BaseUri + "/rest/v1/assets/storages/" + $StorageArrays[$i].id + "?expand=storageNodes.storagePools.disks,annotations,storageNodes.storagePools.annotations,storageNodes.storagePools.volumes.annotations,storageNodes.storagePools.internalVolumes.annotations,storageNodes.annotations,performance,storageNodes.performance,storageNodes.storagePools.performance&fromTime=" + $FromTime + "&toTime=" + $Totime ) $ExpandedStorageArray = Invoke-RestMethod -Uri $Uri -Headers $Headers if( !(CheckFor-PSObject($ExpandedStorageArray)) ) { $logg.Error("ExpandedStorageArray is not returned as Object[].Converting it to PSObject[] : " + $Uri) $ExpandedStorageArray = ConvertFrom-StringToPSObjects($ExpandedStorageArray) } $logg.Info("Invoked " + $Uri) } catch { $logg.Error("ERROR: Could not get expanded storage array information from OCI server: " + $_) throw $( "ERROR: Could not get expanded storage array information from OCI server: " + $_ ) } # now we have to parse the expanded data accordingly if ( $ExpandedStorageArray.performance ) { Save-StorageArrayPerformance $StorageArrays[$i].id $ExpandedStorageArray.performance } if ( $ExpandedStorageArray.storageNodes ) { # This will save storage nodes, pools, internal volumes and volumes Save-StorageNodes $StorageArrays[$i].id $ExpandedStorageArray.storageNodes } if ( $ExpandedStorageArray.annotations -and $APIVersion -ge 1.1 ) { Save-ObjectAnnotations $StorageArrayAnnotationsData $StorageArrays[$i].id $ExpandedStorageArray.annotations } } $logg.Info("Invoked all storage array details") } # # Name: Get-Hosts # Func: Get the Host data and related objects from the OCI database via REST. # function Get-Hosts( [parameter(Mandatory=$True, Position=0)]$BaseUri, [parameter(Mandatory=$True, Position=1)]$Headers ) { try { $Uri = $BaseUri + "/rest/v1/assets/hosts" $logg.Info("Retrieving hosts with URI: " + $Uri) $Hosts = Invoke-RestMethod -Uri $Uri -Headers $Headers if( !(CheckFor-PSObject($Hosts)) ) { $logg.Error("Hosts is not returned as PSObject[].Converting it to PSObject[]") $Hosts = ConvertFrom-StringToPSObjects($Hosts) } $logg.Info("Invoked " + $Uri + " Hosts count: " + $Hosts.count) } catch { $logg.Error("ERROR: Could not get Hosts information from OCI server: " + $_) throw $( "ERROR: Could not get Hosts information from OCI server: " + $_ ) } Save-Hosts $Hosts # Iterate each host and get expanded data for ( $i = 0; $i -lt $Hosts.count; $i++ ) { if ($Hosts[$i].isHypervisor) { try { $Uri = $( $BaseUri + "/rest/v1/assets/hosts/" + $Hosts[$i].id + "?expand=annotations,virtualMachines.dataStore" ) $ExpandedHost = Invoke-RestMethod -Uri $Uri -Headers $Headers if( !(CheckFor-PSObject($ExpandedHost)) ) { $logg.Error("ExpandedHost is not returned as Object[].Converting it to PSObject[] : " + $Uri) $ExpandedHost = ConvertFrom-StringToPSObjects($ExpandedHost) } } catch { $logg.Error("ERROR: Could not get expanded Hosts information from OCI server: " + $_) throw $( "ERROR: Could not get expanded Hosts information from OCI server: " + $_ ) } if ( $ExpandedHost.virtualMachines ) { Save-VirtualMachines $Hosts[$i].id $ExpandedHost.virtualMachines } if ( $ExpandedHost.annotations -and $APIVersion -ge 1.1 ) { Save-ObjectAnnotations $HostAnnotationsData $Hosts[$i].id $ExpandedHost.annotations } } } $logg.Info("Invoked all host details") } # # Name: Get-Applications # Func: Get the Application data from the OCI database via REST. # Also, gets the associations of applications to storage and compute resources # function Get-Applications( [parameter(Mandatory=$True, Position=0)]$BaseUri, [parameter(Mandatory=$True, Position=1)]$Headers ) { try { $Uri = $BaseUri + "/rest/v1/assets/applications" $logg.Info("Retrieving applications with URI: " + $Uri) $Applications = Invoke-RestMethod -Uri $Uri -Headers $Headers if( !(CheckFor-PSObject($Applications)) ) { $logg.Error("Applications is not returned as PSObject[].Converting it to PSObject[]") $Applications = ConvertFrom-StringToPSObjects($Applications) } $logg.Info("Retrieved applications. Applications count:" + $Applications.count) } catch { $logg.Error("ERROR: Could not get application information from OCI server: " + $_) throw $( "ERROR: Could not get application information from OCI server: " + $_ ) } Save-Applications $Applications # Iterate each application object and get expanded data for ( $i = 0; $i -lt $Applications.count; $i++ ) { try { $Uri = $($BaseUri + "/rest/v1/assets/applications/" + $Applications[$i].id + "?expand=storageResources,computeResources") $ExpandedApplication = Invoke-RestMethod -Uri $Uri -Headers $Headers if( !(CheckFor-PSObject($ExpandedApplication)) ) { $logg.Error("ExpandedApplication is not returned as Object[].Converting it to PSObject[] : " + $Uri) $ExpandedApplication = ConvertFrom-StringToPSObjects($ExpandedApplication) } } catch { throw $( "ERROR: Could not get expanded application information from OCI server: " + $_ ) } if ( $ExpandedApplication.storageResources) { $StorageResources = $ExpandedApplication.storageResources for ($j = 0; $j -lt $StorageResources.count; $j++) { if ($StorageResources[$j].resourceType -eq "Volume") { $rowValues = $null,$StorageResources[$j].id,$Applications[$i].id $VolumesApplicationsData.Add($global:CommonCounter,$rowValues) $global:CommonCounter++ } if ($StorageResources[$j].resourceType -eq "InternalVolume") { $rowValues = $null,$StorageResources[$j].id,$Applications[$i].id $InternalVolumesApplicationsData.Add($global:CommonCounter,$rowValues) $global:CommonCounter++ } } } if ( $ExpandedApplication.computeResources) { $computeResources = $ExpandedApplication.computeResources for ($j = 0; $j -lt $computeResources.count; $j++) { if ($computeResources[$j].resourceType -eq "host") { $rowValues = $null,$computeResources[$j].id,$Applications[$i].id $HostsApplicationsData.Add($global:CommonCounter,$rowValues) $global:CommonCounter++ } if ($computeResources[$j].resourceType -eq "virtualmachine") { $virtualMachineId = $VirtualMachineGeneratedIdByLongId[$computeResources[$j].id] $rowValues = $null,$virtualMachineId,$Applications[$i].id $VirtualMachinesApplicationsData.Add($global:CommonCounter,$rowValues) $global:CommonCounter++ } } } } $logg.Info("Invoked all application details") } # Set of functions to save the performance data from OCI into global hash tables # # Name: Save-StorageArrayPerformance # Func: Save the storage array performance data into a hash table. # function Save-StorageArrayPerformance( $StorageId , $PerformanceData ) { [double]$iops_read_avg = "{0:N3}" -f $PerformanceData.iops.read.avg [double]$iops_write_avg = "{0:N3}" -f $PerformanceData.iops.write.avg [double]$iops_total_avg = "{0:N3}" -f $PerformanceData.iops.total.avg [double]$latency_read_avg = "{0:N3}" -f $PerformanceData.latency.read.avg [double]$latency_write_avg = "{0:N3}" -f $PerformanceData.latency.write.avg [double]$latency_total_avg = "{0:N3}" -f $PerformanceData.latency.total.avg [double]$cacheutilization_total_avg = "{0:N3}" -f $PerformanceData.cacheUtilization.total.avg [double]$throughput_read_avg = "{0:N3}" -f $PerformanceData.throughput.read.avg [double]$throughput_write_avg = "{0:N3}" -f $PerformanceData.throughput.write.avg [double]$throughput_total_avg = "{0:N3}" -f $PerformanceData.throughput.total.avg $rowValues = $null,$iops_read_avg,$iops_write_avg,$iops_total_avg,$latency_read_avg,$latency_write_avg,$latency_total_avg,$cacheutilization_total_avg,$throughput_read_avg,$throughput_write_avg,$throughput_total_avg,$StorageId $StorageArrayPerformanceData.Add($global:CommonCounter, $rowValues) $global:CommonCounter++ } # Name: Save-StorageNodePerformance # Func: Save the storage node performance data into a hash table. # function Save-StorageNodePerformance( $StorageNodeId , $PerformanceData ) { [double]$iops_read_avg = "{0:N3}" -f $PerformanceData.iops.read.avg [double]$iops_write_avg = "{0:N3}" -f $PerformanceData.iops.write.avg [double]$iops_total_avg = "{0:N3}" -f $PerformanceData.iops.total.avg [double]$latency_read_avg = "{0:N3}" -f $PerformanceData.latency.read.avg [double]$latency_write_avg = "{0:N3}" -f $PerformanceData.latency.write.avg [double]$latency_total_avg = "{0:N3}" -f $PerformanceData.latency.total.avg [double]$utilization_total_avg = "{0:N3}" -f $PerformanceData.utilization.total.avg [double]$throughput_read_avg = "{0:N3}" -f $PerformanceData.throughput.read.avg [double]$throughput_write_avg = "{0:N3}" -f $PerformanceData.throughput.write.avg [double]$throughput_total_avg = "{0:N3}" -f $PerformanceData.throughput.total.avg $rowValues = $null,$iops_read_avg,$iops_write_avg,$iops_total_avg,$latency_read_avg,$latency_write_avg,$latency_total_avg,$utilization_total_avg,$throughput_read_avg,$throughput_write_avg,$throughput_total_avg,$StorageNodeId $StorageNodePerformanceData.Add($global:CommonCounter, $rowValues) $global:CommonCounter++ } # Name: Save-StoragePoolPerformance # Func: Save the storage node performance data into a hash table. # function Save-StoragePoolPerformance( $StoragePoolId , $PerformanceData ) { [double]$iops_read_avg = "{0:N3}" -f $PerformanceData.iops.read.avg [double]$iops_write_avg = "{0:N3}" -f $PerformanceData.iops.write.avg [double]$iops_total_avg = "{0:N3}" -f $PerformanceData.iops.total.avg [double]$utilization_read_avg = "{0:N3}" -f $PerformanceData.utilization.read.avg [double]$utilization_write_avg = "{0:N3}" -f $PerformanceData.utilization.write.avg [double]$utilization_total_avg = "{0:N3}" -f $PerformanceData.utilization.total.avg [double]$throughput_read_avg = "{0:N3}" -f $PerformanceData.throughput.read.avg [double]$throughput_write_avg = "{0:N3}" -f $PerformanceData.throughput.write.avg [double]$throughput_total_avg = "{0:N3}" -f $PerformanceData.throughput.total.avg $rowValues = $null,$iops_read_avg,$iops_write_avg,$iops_total_avg,$utilization_read_avg,$utilization_write_avg,$utilization_total_avg,$throughput_read_avg,$throughput_write_avg,$throughput_total_avg,$StoragePoolId $StoragePoolPerformanceData.Add($global:CommonCounter, $rowValues) $global:CommonCounter++ } # Name: Save-DataStorePerformance # Func: Save the storage node performance data into a hash table. # function Save-DataStorePerformance( $DataStoreId , $PerformanceData ) { [double]$iops_read_avg = "{0:N3}" -f $PerformanceData.iops.read.avg [double]$iops_write_avg = "{0:N3}" -f $PerformanceData.iops.write.avg [double]$iops_total_avg = "{0:N3}" -f $PerformanceData.iops.total.avg [double]$latency_read_avg = "{0:N3}" -f $PerformanceData.latency.read.avg [double]$latency_write_avg = "{0:N3}" -f $PerformanceData.latency.write.avg [double]$latency_total_avg = "{0:N3}" -f $PerformanceData.latency.total.avg [double]$throughput_read_avg = "{0:N3}" -f $PerformanceData.throughput.read.avg [double]$throughput_write_avg = "{0:N3}" -f $PerformanceData.throughput.write.avg [double]$throughput_total_avg = "{0:N3}" -f $PerformanceData.throughput.total.avg $rowValues = $null,$iops_read_avg,$iops_write_avg,$iops_total_avg,$latency_read_avg,$latency_write_avg,$latency_total_avg,$throughput_read_avg,$throughput_write_avg,$throughput_total_avg,$DataStoreId $DataStorePerformanceData.Add($global:CommonCounter, $rowValues) $global:CommonCounter++ } # Set of functions to save the collected data from OCI into global hash tables # # Name: Save-Annotations # Func: Save the annotation data into a hash table. # function Save-Annotations( $Annotations ) { for ( $i = 0; $i -lt $Annotations.count; $i++ ) { $enumCount = $Annotations[$i].enumValues.count $enumValues = $null If ($enumCount -gt 0 ) { $enumValues = $Annotations[$i].enumValues.name -join ',' for ( $j = 0; $j -lt $enumCount; $j++ ) { $AnnotationEnumRow = $null $Label = $null $Description = $null if ($Annotations[$i].enumValues[$j].label) { $Label = $Annotations[$i].enumValues[$j].label } if ($Annotations[$i].enumValues[$j].description) { $Description = $Annotations[$i].enumValues[$j].description } $AnnotationEnumRow = $null,$Annotations[$i].id,$Annotations[$i].enumValues[$j].name,$Label,$Description,[int]$Annotations[$i].enumValues[$j].isUserDefined,$Annotations[$i].enumValues[$j].cost $AnnotationEnumValuesData.add($global:CommonCounter,$AnnotationEnumRow) $global:CommonCounter++ } } $supportedObjectTypes = $Annotations[$i].supportedObjectTypes -join ',' $selfUri = "/rest/v1/assets/annotations/" + $Annotations[$i].id $rowValues = $Annotations[$i].id,$Annotations[$i].name,$Annotations[$i].type,$Annotations[$i].label,$enumValues,[int]$Annotations[$i].isUserDefined,$supportedObjectTypes,$selfUri $AnnotationsData.Add( $Annotations[$i].id, $rowValues ) $AnnotationIdByLabel.Add($Annotations[$i].label, $Annotations[$i].id) } } # # Name: Save-ObjectAnnotations # Func: Save the association of annotations to objects of a specific type # function Save-ObjectAnnotations( $ObjectAnnotationData, $ObjectId, $ObjectAnnotationEntries ) { for ( $i = 0; $i -lt $ObjectAnnotationEntries.count; $i++ ) { $annotationId = $AnnotationIdByLabel[$ObjectAnnotationEntries[$i].label] $rowValues = $null,$ObjectAnnotationEntries[$i].displayValue,[int]$ObjectAnnotationEntries[$i].isDerived,$ObjectAnnotationEntries[$i].rawValue,$ObjectId,$annotationId $ObjectAnnotationData.Add( $global:CommonCounter, $rowValues ) $global:CommonCounter++ } } # # Name: Save-StorageArrays # Func: Save the storage data into a hash table. # function Save-StorageArrays( $StorageArrays ) { for ( $i = 0; $i -lt $StorageArrays.count; $i++ ) { [long]$capacityInMb = $null if ( $StorageArrays[$i].capacity ) { if ($StorageArrays[$i].capacity.total) { $capacityInMb = ConvertToMb -value $StorageArrays[$i].capacity.total.value -unit $StorageArrays[$i].capacity.unitType } } $rowValues = $StorageArrays[$i].id,$capacityInMb,$StorageArrays[$i].family,$StorageArrays[$i].ip,[int]$StorageArrays[$i].isActive,$StorageArrays[$i].managementUrl,$StorageArrays[$i].microcodeVersion,$StorageArrays[$i].model,$StorageArrays[$i].name,$StorageArrays[$i].naturalKey,$StorageArrays[$i].self,$StorageArrays[$i].serialNumber,$StorageArrays[$i].simpleName,$StorageArrays[$i].vendor $StorageArraysData.Add( $StorageArrays[$i].id, $rowValues ) } } # # Name: Save-StorageNodes # Func: Save the storageNodes data into a hash table. # function Save-StorageNodes( $StorageId, $StorageNodes ) { for ( $i = 0; $i -lt $StorageNodes.count; $i++ ) { if ( !$StorageNodesData.Item( $StorageNodes[$i].id ) ) { [long]$cacheCapacityInMb = $null [long]$memoryValueInMb = $null if ( $StorageNodes[$i].cache ) { $cacheCapacityInMb = ConvertToMb -value $StorageNodes[$i].cache.value -unit $StorageNodes[$i].cache.unitType } if ( $StorageNodes[$i].memory ) { $memoryValueInMb = ConvertToMb -value $StorageNodes[$i].memory.value -unit $StorageNodes[$i].memory.unitType } $rowValues = $StorageNodes[$i].id,$cacheCapacityInMb,$memoryValueInMb,$StorageNodes[$i].model,$StorageNodes[$i].name,$StorageNodes[$i].nodeVersion,$StorageNodes[$i].numberOfProcessors,$StorageNodes[$i].self,$StorageNodes[$i].serialNumber,$StorageNodes[$i].simpleName, $StorageNodes[$i].state,$StorageNodes[$i].uuid,$StorageId $StorageNodesData.Add( $StorageNodes[$i].id, $rowValues ) if ( $StorageNodes[$i].performance ) { Save-StorageNodePerformance $StorageNodes[$i].id $StorageNodes[$i].performance } } if ( $StorageNodes[$i].annotations -and $APIVersion -ge 1.1 ) { Save-ObjectAnnotations $StorageNodeAnnotationsData $StorageNodes[$i].id $StorageNodes[$i].annotations } if ( $StorageNodes[$i].storagePools ) { Save-StoragePools $StorageId $StorageNodes[$i].id $StorageNodes[$i].storagePools } } } # # Name: Save-StoragePools # Func: Save the storagePools data into a hash table. # function Save-StoragePools( $StorageId, $StorageNodeId, $StoragePools ) { for ( $i = 0; $i -lt $StoragePools.count; $i++ ) { if ( !$StoragePoolsData.Item( $StoragePools[$i].id ) ) { $rawToUsableRatio = $null $isDedupeEnabled = $null $isThinProvisioningSupported = $null [long]$breakdownsData = $null [long]$breakdownsSnapshot = $null [long]$capacityTotal = $null [long]$usedBreakdownsData = $null [long]$usedBreakdownsSnapshot = $null [long]$capacityUsed = $null if ( $StoragePools[$i].capacity ) { $rawToUsableRatio = "{0:N3}" -f $StoragePools[$i].capacity.rawToUsableRatio $isDedupeEnabled = $StoragePools[$i].capacity.isDedupeEnabled $isThinProvisioningSupported = $StoragePools[$i].capacity.isThinProvisioningSupported if ($StoragePools[$i].capacity.total.breakdowns) { $breakdownsData = ConvertToMb -value $StoragePools[$i].capacity.total.breakdowns.data -unit $StoragePools[$i].capacity.unitType $breakdownsSnapshot = ConvertToMb -value $StoragePools[$i].capacity.total.breakdowns.snapshot -unit $StoragePools[$i].capacity.unitType } if ($StoragePools[$i].capacity.total) { $capacityTotal = ConvertToMb -value $StoragePools[$i].capacity.total.value -unit $StoragePools[$i].capacity.unitType } if ($StoragePools[$i].capacity.used.breakdowns) { $usedBreakdownsData = ConvertToMb -value $StoragePools[$i].capacity.used.breakdowns.data -unit $StoragePools[$i].capacity.unitType $usedBreakdownsSnapshot = ConvertToMb -value $StoragePools[$i].capacity.used.breakdowns.snapshot -unit $StoragePools[$i].capacity.unitType } if ($StoragePools[$i].capacity.used) { $capacityUsed = ConvertToMb -value $StoragePools[$i].capacity.used.value -unit $StoragePools[$i].capacity.unitType } } $rowValues = $StoragePools[$i].id,[int]$isDedupeEnabled,[int]$isThinProvisioningSupported,$rawToUsableRatio,$breakdownsData,$breakdownsSnapshot,$capacityTotal,$StoragePools[$i].capacity.unitType,$usedBreakdownsData,$usedBreakdownsSnapshot,[int]$StoragePools[$i].capacity.used.highThreshold,$capacityUsed,[int]$StoragePools[$i].isAutoTiering,[int]$StoragePools[$i].isRaidGroup,[int]$StoragePools[$i].isVirtual,$StoragePools[$i].name,$StoragePools[$i].redundancy,$StoragePools[$i].self,$StoragePools[$i].simpleName,$StoragePools[$i].type,[int]$StoragePools[$i].usesFlashPools,$StoragePools[$i].vendorTier,$StorageId,$StorageNodeId $StoragePoolsData.Add( $StoragePools[$i].id, $rowValues ) if ( $StoragePools[$i].disks ) { Save-Disks $StoragePools[$i].id $StoragePools[$i].disks } if ( $StoragePools[$i].performance ) { Save-StoragePoolPerformance $StoragePools[$i].id $StoragePools[$i].performance } if ( $StoragePools[$i].annotations -and $APIVersion -ge 1.1 ) { Save-ObjectAnnotations $StoragePoolAnnotationsData $StoragePools[$i].id $StoragePools[$i].annotations } if ( $StoragePools[$i].internalVolumes ) { Save-InternalVolumes $StoragePools[$i].id $StoragePools[$i].internalVolumes } if ( $StoragePools[$i].volumes ) { Save-Volumes $StoragePools[$i].id $StoragePools[$i].volumes } } } } # # Name: Save-InternalVolumes # Func: Save the internalVolumes data into a hash table. # function Save-InternalVolumes( $StoragePoolId, $InternalVolumes ) { for ( $i = 0; $i -lt $InternalVolumes.count; $i++ ) { if ( !$InternalVolumesData.Item( $InternalVolumes[$i].id ) ) { [long]$capacityTotalBreakdown = $null [long]$capacityTotalValue = $null [long]$capacityUsedBreakdown = $null [long]$capacityUsedValue = $null [double]$rawToUsableRatio = $null if ( $InternalVolumes[$i].capacity ) { if ($InternalVolumes[$i].capacity.total.breakdowns) { $capacityTotalBreakdown = ConvertToMb -value $InternalVolumes[$i].capacity.total.breakdowns.snapshot -unit $InternalVolumes[$i].capacity.unitType } if ($InternalVolumes[$i].capacity.total) { $capacityTotalValue = ConvertToMb -value $InternalVolumes[$i].capacity.total.value -unit $InternalVolumes[$i].capacity.unitType } if ($InternalVolumes[$i].capacity.used.breakdowns) { $capacityUsedBreakdown = ConvertToMb -value $InternalVolumes[$i].capacity.used.breakdowns.snapshot -unit $InternalVolumes[$i].capacity.unitType } if ($InternalVolumes[$i].capacity.used) { $capacityUsedValue = ConvertToMb -value $InternalVolumes[$i].capacity.used.value -unit $InternalVolumes[$i].capacity.unitType } $rawToUsableRatio = "{0:N3}" -f $InternalVolumes[$i].capacity.rawToUsableRatio } $rowValues = $InternalVolumes[$i].id,[int]$InternalVolumes[$i].capacity.isDedupeEnabled,[int]$InternalVolumes[$i].capacity.isThinProvisioned,[int]$InternalVolumes[$i].capacity.isThinProvisioningSupported,$rawToUsableRatio,$capacityTotalBreakdown,$capacityTotalValue,$capacityUsedBreakdown,[int]$InternalVolumes[$i].capacity.used.highThreshold,$capacityUsedValue,$InternalVolumes[$i].flashPoolEligibility,$InternalVolumes[$i].name,$InternalVolumes[$i].self,$InternalVolumes[$i].simpleName,$InternalVolumes[$i].spaceGuarantee,$InternalVolumes[$i].status,$InternalVolumes[$i].type,$InternalVolumes[$i].virtualStorage,$StoragePoolId $InternalVolumesData.Add( $InternalVolumes[$i].id, $rowValues ) if ( $InternalVolumes[$i].annotations -and $APIVersion -ge 1.1 ) { Save-ObjectAnnotations $InternalVolumeAnnotationsData $InternalVolumes[$i].id $InternalVolumes[$i].annotations } } } } # # Name: Save-Volumes # Func: Save the volumes data into a hash table. # function Save-Volumes( $StoragePoolId, $Volumes ) { for ( $i = 0; $i -lt $Volumes.count; $i++ ) { if ( !$VolumesData.Item( $Volumes[$i].id ) ) { [long]$capacityTotalValue = $null [long]$capacityUsedValue = $null if ( $Volumes[$i].capacity.total ) { $capacityTotalValue = ConvertToMb -value $Volumes[$i].capacity.total.value -unit $Volumes[$i].capacity.unitType } if ($Volumes[$i].capacity.used) { $capacityUsedValue = ConvertToMb -value $Volumes[$i].capacity.used.value -unit $Volumes[$i].capacity.unitType } $rowValues = $Volumes[$i].id,$capacityTotalValue,[int]$Volumes[$i].capacity.used.highThreshold,$capacityUsedValue,$Volumes[$i].diskGroup,[int]$Volumes[$i].isAutoTiering,[int]$Volumes[$i].isMeta,[int]$Volumes[$i].isReplicaSource,[int]$Volumes[$i].isReplicaTarget,[int]$Volumes[$i].isSnapshot,[int]$Volumes[$i].isThinProvisioned,[int]$Volumes[$i].isVirtual,$Volumes[$i].label,$Volumes[$i].name,$Volumes[$i].protectionType,$Volumes[$i].self,$Volumes[$i].simpleName,$Volumes[$i].type,$Volumes[$i].uuid,$StoragePoolId $VolumesData.Add( $Volumes[$i].id, $rowValues ) if ( $Volumes[$i].annotations -and $APIVersion -ge 1.1 ) { Save-ObjectAnnotations $VolumeAnnotationsData $Volumes[$i].id $Volumes[$i].annotations } } } } # # Name: Save-Disks # Func: Save the disks data into a hash table. # function Save-Disks( $StoragePoolId, $Disks ) { for ( $i = 0; $i -lt $Disks.count; $i++ ) { if ( !$DisksData.Item( $Disks[$i].id ) ) { [long]$diskSizeTotalValue = $null if ( $Disks[$i].diskSize.total ) { $diskSizeTotalValue = ConvertToMb -value $Disks[$i].diskSize.total.value -unit $Disks[$i].diskSize.unitType } $rowValues = $Disks[$i].id,$Disks[$i].diskGroup,$diskSizeTotalValue,[int]$Disks[$i].isVirtual,$Disks[$i].location,$Disks[$i].model,$Disks[$i].name,$Disks[$i].role,$Disks[$i].self,$Disks[$i].serialNumber,$Disks[$i].simpleName,$Disks[$i].speed.value,$Disks[$i].status,$Disks[$i].type,$Disks[$i].vendor,$StoragePoolId $DisksData.Add( $Disks[$i].id, $rowValues ) } } } # # Name: Save-Hosts # Func: Save the hosts data into a hash table. # function Save-Hosts( $Hosts ) { for ( $i = 0; $i -lt $Hosts.count; $i++ ) { [long]$memoryValue = $null if ($Hosts[$i].memory) { $memoryValue = ConvertToMb -value $Hosts[$i].memory.value -unit $Hosts[$i].memory.unitType } [long]$cpuValue = $null if ( $Hosts[$i].cpu ) { $cpuValue = ConvertToMhz -value $Hosts[$i].cpu.value -unit $Hosts[$i].cpu.unitType } $rowValues = $Hosts[$i].id,$Hosts[$i].clusterName,$cpuValue,[int]$Hosts[$i].cpuCount,$Hosts[$i].ip,[int]$Hosts[$i].isActive,[int]$Hosts[$i].isHypervi,$Hosts[$i].manufacturer,$memoryValue,$Hosts[$i].model,$Hosts[$i].name,$Hosts[$i].os,$Hosts[$i].self,$Hosts[$i].simpleName $HostsData.Add( $Hosts[$i].id, $rowValues ) } } # # Name: Save-DataStore # Func: Save the datastore data into a hash table # function Save-DataStore( $DataStore ) { $internalVolumeId = $null $volumeId = $null if ( $DataStore.storageResources -and $DataStore.storageResources.count -ge 1) { if ( $DataStore.storageResources[0].resourceType -eq "InternalVolume" ) { [long]$internalVolumeId = $DataStore.storageResources[0].id } else { [long]$volumeId = $DataStore.storageResources[0].id } } [long]$capacityTotalValue = $null [long]$capacityUsedValue = $null [int]$threshold = $null if ( $DataStore.capacity ) { if ($DataStore.capacity.total) { $capacityTotalValue = ConvertToMb -value $DataStore.capacity.total.value -unit $DataStore.capacity.unitType } if ( $DataStore.capacity.used ) { $threshold = $DataStore.capacity.used.highThreshold $capacityUsedValue = ConvertToMb -value $DataStore.capacity.used.value -unit $DataStore.capacity.unitType } } [long]$dataStoreId = $null if ($DataStoreGeneratedIdByLongId.ContainsKey($DataStore.id)) { $dataStoreId = $DataStoreGeneratedIdByLongId[$DataStore.id] } else { $dataStoreId = $global:DataStoreIdCounter $DataStoreGeneratedIdByLongId.Set_Item($DataStore.id, $dataStoreId) $global:DataStoreIdCounter++ } $rowValues = [long]$dataStoreId,$capacityTotalValue,$threshold,$capacityUsedValue,$DataStore.name,$DataStore.self,$DataStore.simpleName, $DataStore.virtualCenterIp,$DataStore.id,$internalVolumeId,$volumeId $DataStoresData.Add( $dataStoreId, $rowValues ) } # # Name: Save-VirtualMachines # Func: Save the virtual machine data into a hash table. # function Save-VirtualMachines( $HostId, $VirtualMachines ) { for ( $i = 0; $i -lt $VirtualMachines.count; $i++ ) { if ( !$VirtualMachinesData.Item( $VirtualMachines[$i].id ) ) { [long]$capacityTotalValueInMb = $null [long]$capacityUsedValueInMb = $null [long]$capacityUsedHighThreshold = $null [long]$memoryValueInMb = $null [long]$dataStoreId = $null if ($VirtualMachines[$i].capacity) { if ($VirtualMachines[$i].capacity.total) { $capacityTotalValueInMb = ConvertToMb -value $VirtualMachines[$i].capacity.total.value -unit $VirtualMachines[$i].capacity.unitType } if ( $VirtualMachines[$i].capacity.used ) { $capacityUsedValueInMb = ConvertToMb -value $VirtualMachines[$i].capacity.used.value -unit $VirtualMachines[$i].capacity.unitType $capacityUsedHighThreshold = $VirtualMachines[$i].capacity.used.highThreshold } } if ($VirtualMachines[$i].memory) { $memoryValueInMb = ConvertToMb -value $VirtualMachines[$i].memory.value -unit $VirtualMachines[$i].memory.unitType } if ( $VirtualMachines[$i].dataStore ) { if ($DataStoreGeneratedIdByLongId.ContainsKey($VirtualMachines[$i].dataStore.id)) { $dataStoreId = $DataStoreGeneratedIdByLongId[$VirtualMachines[$i].dataStore.id] } else { $dataStoreId = $global:DataStoreIdCounter $DataStoreGeneratedIdByLongId.Set_Item($VirtualMachines[$i].dataStore.id, $dataStoreId) $global:DataStoreIdCounter++ } } [long]$virtualMachineId = $null if ($VirtualMachineGeneratedIdByLongId.ContainsKey($VirtualMachines[$i].id)) { $virtualMachineId = $VirtualMachineGeneratedIdByLongId[$VirtualMachines[$i].id] } else { $virtualMachineId = $global:VirtualMachineIdCounter $VirtualMachineGeneratedIdByLongId.Set_Item($VirtualMachines[$i].id, $virtualMachineId) $global:VirtualMachineIdCounter++ } $rowValues = [long]$virtualMachineId,$capacityTotalValueInMb,[int]$capacityUsedHighThreshold,$capacityUsedValueInMb,$VirtualMachines[$i].dnsName,$VirtualMachines[$i].guestState,$VirtualMachines[$i].ip,$memoryValueInMb,$VirtualMachines[$i].name,$VirtualMachines[$i].os,$VirtualMachines[$i].powerState,[int]$VirtualMachines[$i].processors,$VirtualMachines[$i].self,$VirtualMachines[$i].simpleName,$VirtualMachines[$i].id,[long]$HostId,[long]$dataStoreId $VirtualMachinesData.Add($VirtualMachines[$i].id, $rowValues) } } } # # Name: Save-VMDKs # Func: Save the VMDK data into a hash table. # function Save-VMDKs( $DataStoreId, $Vmdks ) { for ( $i = 0; $i -lt $Vmdks.count; $i++ ) { if ( !$VMDKsData.Item( $Vmdks[$i].id ) ) { [long]$capacityTotal = $null [long]$capacityUsed = $null [long]$virtualMachineId = $null if ($Vmdks[$i].capacity.total ) { $capacityTotal = ConvertToMb -value $Vmdks[$i].capacity.total.value -unit $Vmdks[$i].capacity.unitType } if ($Vmdks[$i].capacity.used) { $capacityUsed = ConvertToMb -value $Vmdks[$i].capacity.used.value -unit $Vmdks[$i].capacity.unitType } if ($Vmdks[$i].virtualMachine) { $virtualMachineId = $VirtualMachineGeneratedIdByLongId[$Vmdks[$i].virtualMachine.id] } $rowValues = $null,$capacityTotal,[int]$Vmdks[$i].capacity.used.highThreshold,$capacityUsed,$Vmdks[$i].name,$Vmdks[$i].self,$Vmdks[$i].simpleName,$DataStoreId,$VirtualMachineId,$Vmdks[$i].id $VMDKsData.Add( $Vmdks[$i].id, $rowValues ) } } } # # Name: Save-Fabric # Func: Save the fabric data into a hash table. # function Save-Fabrics( $Fabrics ) { for ( $i = 0; $i -lt $Fabrics.count; $i++ ) { $rowValues = $Fabrics[$i].id,$Fabrics[$i].name,$Fabrics[$i].simpleName,$Fabrics[$i].wwn,$Fabrics[$i].vsanId,[int]$Fabrics[$i].isVsanEnabled,[int]$Fabrics[$i].isZoningEnabled,$Fabrics[$i].activeZoneSet,[int]$Fabrics[$i].isActive,$Fabrics[$i].switchesCount $FabricsData.Add( $Fabrics[$i].id, $rowValues ) } } # # Name: Save-Switches # Func: Save the switch data into a hash table. # function Save-Switches( $FabricId, $Switches ) { for ( $i = 0; $i -lt $Switches.count; $i++ ) { if ( !$SwitchesData.Item( $Switches[$i].id ) ) { $rowValues = $Switches[$i].id,$Switches[$i].domainId,$Switches[$i].domainIdType,$Switches[$i].firmware,$Switches[$i].ip,[int]$Switches[$i].isActive,[int]$Switches[$i].isNpv,[int]$Switches[$i].isSanRouteEnabled,[int]$Switches[$i].isVsanEnabled,$Switches[$i].model,$Switches[$i].name,$Switches[$i].priority,$Switches[$i].self, $Switches[$i].serialNumber,$Switches[$i].simpleName,$Switches[$i].switchRole,$Switches[$i].switchStatus,$Switches[$i].switchType,$Switches[$i].vendor,$Switches[$i].wwn,$FabricId $SwitchesData.Add( $Switches[$i].id, $rowValues ) } } } # # Name: Save-Ports # Func: Save the ports data into a hash table. # function Save-Ports($SwitchId, $Ports ) { for ( $i = 0; $i -lt $Ports.count; $i++ ) { if ( !$PortsData.Item( $Ports[$i].id ) ) { $rowValues = $Ports[$i].id,[int]$Ports[$i].blade,$Ports[$i].classOfService,$Ports[$i].controller,$Ports[$i].deviceName,$Ports[$i].deviceType,$Ports[$i].fc4Protocol,$Ports[$i].gbicType,[int]$Ports[$i].isActive,[int]$Ports[$i].isGenerated,$Ports[$i].name,$Ports[$i].nodeWwn,$Ports[$i].portIndex,$Ports[$i].portState,$Ports[$i].portStatus,$Ports[$i].role,$Ports[$i].self,$Ports[$i].simpleName,$Ports[$i].speed,$Ports[$i].type,$Ports[$i].wwn,$SwitchId $PortsData.Add( $Ports[$i].id, $rowValues ) } } } # # Name: Save-Applications # Func: Save the application data into a hash table. # function Save-Applications( $Applications ) { for ( $i = 0; $i -lt $Applications.count; $i++ ) { $businessEntityTenant = $null $businessEntityLoB = $null $businessEntityUnit = $null $businessEntityProject = $null if ($Applications[$i].businessEntity) { $businessEntityTenant = $Applications[$i].businessEntity.tenant $businessEntityLoB = $Applications[$i].businessEntity.lob $businessEntityUnit = $Applications[$i].businessEntity.businessUnit $businessEntityProject = $Applications[$i].businessEntity.project } $selfUri = "/rest/v1/assets/applications/" + $Applications[$i].id $rowValues = $Applications[$i].id,$Applications[$i].name,$Applications[$i].priority,$businessEntityTenant,$businessEntityLoB,$businessEntityUnit,$businessEntityProject,$selfUri $ApplicationsData.Add( $Applications[$i].id, $rowValues ) $ApplicationIdByName.Add($Applications[$i].name, $Applications[$i].id) } } # # Name: Get-DataFromOci # Func: Invoke different REST APIs, save the data in hash tables, arrays # function Get-DataFromOci() { if ($APIVersion -ge 1.1) { Get-Annotations $BaseUri $Headers } Get-StorageArrays $BaseUri $Headers Get-Hosts $BaseUri $Headers Get-DataStores $BaseUri $Headers if ($APIVersion -ge 1.2) { Get-Fabrics $BaseUri $Headers } Get-Applications $BaseUri $Headers } # # Name: Save-DataInCsv # Func: Save all the data in csv files # function Save-DataInCsv() { Output-Data "./Storage_Array.csv" $StorageArraysData Output-Data "./Storage_Node.csv" $StorageNodesData Output-Data "./Storage_Pool.csv" $StoragePoolsData Output-Data "./Disk.csv" $DisksData Output-Data "./Internal_Volume.csv" $InternalVolumesData Output-Data "./Volume.csv" $VolumesData Output-Data "./Host.csv" $HostsData Output-Data "./Virtual_Machine.csv" $VirtualMachinesData Output-Data "./DataStore.csv" $DataStoresData Output-Data "./Vmdk.csv" $VMDKsData Output-Data "./DataStore_Host.csv" $DataStoreHostsData Output-Data "./Fabric.csv" $FabricsData Output-Data "./Switch.csv" $SwitchesData Output-Data "./Port.csv" $PortsData Output-Data "./Annotation.csv" $AnnotationsData Output-Data "./Annotation_Enum_Value.csv" $AnnotationEnumValuesData Output-Data "./Storage_Array_Annotation.csv" $StorageArrayAnnotationsData Output-Data "./Storage_Node_Annotation.csv" $StorageNodeAnnotationsData Output-Data "./Storage_Pool_Annotation.csv" $StoragePoolAnnotationsData Output-Data "./Internal_Volume_Annotation.csv" $InternalVolumeAnnotationsData Output-Data "./Volume_Annotation.csv" $VolumeAnnotationsData Output-Data "./DataStore_Annotation.csv" $DataStoreAnnotationsData Output-Data "./Host_Annotation.csv" $HostAnnotationsData Output-Data "./Switch_Annotation.csv" $SwitchAnnotationsData Output-Data "./Application.csv" $ApplicationsData Output-Data "./Volume_Application.csv" $VolumesApplicationsData Output-Data "./Internal_Volume_Application.csv" $InternalVolumesApplicationsData Output-Data "./Host_Application.csv" $HostsApplicationsData Output-Data "./Virtual_Machine_Application.csv" $VirtualMachinesApplicationsData Output-Data "./Storage_Array_Performance.csv" $StorageArrayPerformanceData Output-Data "./Storage_Node_Performance.csv" $StorageNodePerformanceData Output-Data "./Storage_Pool_Performance.csv" $StoragePoolPerformanceData Output-Data "./DataStore_Performance.csv" $DataStorePerformanceData } ############################################################################## # MAIN CODE ############################################################################## # Some of this in the New-OCIConnection, however getting it early too try { $Hostname = Get-WfaRestParameter "host" $Port = Get-WfaRestParameter "port" $Credentials = Get-WfaCredentials $Username = $Credentials.Username $Password = ConvertFromSecureToPlain -SecurePassword $Credentials.Password } catch { throw $("ERROR: Data source credentials could not be obtained: " + $_) } # Create our initial connection ( $BaseUri, $Headers ) = New-OCIConnection $Hostname $Port $Username $Password $logg.Info("Obtained credentials of OCI system.") # Retrieve the API version try { $Uri = $BaseUri + "/rest/v1/login" $Login = Invoke-RestMethod -Method POST -Uri $Uri -Headers $Headers } catch { throw $( "ERROR: Could not get API login information from OCI server: " + $_ ) } # save it as a double so we get the minor version $APIVersion = [double]$Login.apiVersion $logg.Info("Authenticated to OCI server. API Version is " + $APIVersion) # Retrieve data from OCI using REST calls Get-DataFromOci $logg.Info("Retrieved all data from OCI.") # Store all the collected data in CSV files for WFA to load into cache tables Save-DataInCsv $logg.Info("Data retrieved from OCI copied to CSV files.")