# Setup variables for deserialization if output is too big
#
Add-Type -AssemblyName System.Web.Extensions
$javaScriptSerializer = New-Object System.Web.Script.Serialization.JavaScriptSerializer
$javaScriptSerializer.MaxJsonLength = [System.Int32]::MaxValue
$javaScriptSerializer.RecursionLimit = 99
# Common parameters used for the web service calls
$securePwd = ConvertTo-SecureString "rw" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential("rw", $securePwd)
# If the Powershell version is not >= 3.0, then skip everything else. We cannot get good data using Powershell 2.0
if ($v.Major -ge 3)
{
# Get all storage systems monitored by the agent
$allArrays = Invoke-RestMethod $baseUrl -Credential $cred
if ($allArrays.GetType().FullName -eq "System.String")
{
$allArrays = $javaScriptSerializer.DeserializeObject($allArrays)
}
# Create relationship between Array and the Proxy Agent
$relationshipInstance = $discoveryData.CreateRelationShipInstance("$MPElement[Name='NetAppSANtricity.ProxyArrayRelationship']$")
$relationshipInstance.Source = $proxyInstance
$relationshipInstance.Target = $arrayInstance
$discoveryData.AddInstance($relationshipInstance)
# Get StoragePool data for this array
$url = ""
$url = $baseUrl + $array.wwn + "/storage-pools/"
try
{
$allStoragePools = Invoke-RestMethod $url -Credential $cred
}
catch
{
# If the array is offline/unreachable then trying to get the storage-pools causes an error.
# The data in $allStoragePools will be leftover from the prior array, and using that is bad.
continue
}
if ($allStoragePools.GetType().FullName -eq "System.String")
{
$allStoragePools = $javaScriptSerializer.DeserializeObject($allStoragePools)
}
if ($allStoragePools)
{
# Create Storage Pools Group object to act as container for Storage Pools
$storagePoolGroupInstance = $discoveryData.CreateClassInstance("$MPElement[Name='NetAppSANtricity.StoragePoolsGroup']$")
# Adding properties that associate Storage Pools Group with its parent Storage Array
$storagePoolGroupInstance.AddProperty("$MPElement[Name='NetAppSANtricity.StoragePoolsGroup']/arrayWwn$", $array.wwn)
$storagePoolGroupInstance.AddProperty("$MPElement[Name='NetAppSANtricity.StoragePoolsGroup']/arrayName$", $friendlyName)
$storagePoolGroupInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Storage Pools")
# Create relationship between Storage Pool group and storage array
$relationshipInstance = $discoveryData.CreateRelationshipInstance("$MPElement[Name='NetAppSANtricity.StoragePoolsGroupRelationship']$")
$relationshipInstance.Source = $arrayInstance
$relationshipInstance.Target = $storagePoolGroupInstance
$discoveryData.AddInstance($relationshipInstance)
# Add storage pool to discovery data
$discoveryData.AddInstance($poolInstance)
# Create relationship between storage pool and storage pool group
$relationshipInstance = $discoveryData.CreateRelationshipInstance("$MPElement[Name='NetAppSANtricity.StoragePoolRelationship']$")
$relationshipInstance.Source = $storagePoolGroupInstance
$relationshipInstance.Target = $poolInstance
$discoveryData.AddInstance($relationshipInstance)
#Adding health monitoring to the storage pool
$hsvcManagesSSubsystemRel = $discoveryData.CreateRelationshipInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthServiceShouldManageEntity']$")
$hsvcManagesSSubsystemRel.Source = $healthSvc
$hsvcManagesSSubsystemRel.Target = $poolInstance
$discoveryData.AddInstance($hsvcManagesSSubsystemRel)
} # foreach ($storagePool in $allStoragePools)
} # if ($allStoragePools)
} # foreach ($array in $allArrays)
$arraysProcessed = $allArrays.Count
}
$logString = "Storage Array and Storage Pool Discovery Completed. Arrays processed: " + $arraysProcessed
$api.LogScriptEvent($ScriptName, $E_NBR_TRACE, $E_LVL_INFO, $logString)