# 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
##############################################################################
<#
Target here will be StorageArray
#>
# Common parameters used for the web service calls
$securePwd = ConvertTo-SecureString "rw" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential("rw", $securePwd)
if ($allCgs)
{
# Create Consistency Group group object to act as container for CGs
$cgGroupInstance = $discoveryData.CreateClassInstance("$MPElement[Name='NetAppSANtricity.CGsGroup']$")
# Adding properties of the CG group class
$cgGroupInstance.AddProperty("$MPElement[Name='NetAppSANtricity.CGsGroup']/arrayWwn$", $arrayWWN)
$cgGroupInstance.AddProperty("$MPElement[Name='NetAppSANtricity.CGsGroup']/arrayName$", $arrayName)
$cgGroupInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Consistency Groups")
# Add consistency group to discovery data
$discoveryData.AddInstance($cgInstance)
# Create relationship between consistency group and CGGroup
$relationshipInstance = $discoveryData.CreateRelationshipInstance("$MPElement[Name='NetAppSANtricity.ConsistencyGroupRelationship']$")
$relationshipInstance.Source = $cgGroupInstance
$relationshipInstance.Target = $cgInstance
$discoveryData.AddInstance($relationshipInstance)
#Create health service associated with consistency group
$hsvcManagesSSubsystemRel = $discoveryData.CreateRelationshipInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthServiceShouldManageEntity']$")
$hsvcManagesSSubsystemRel.Source = $healthSvc
$hsvcManagesSSubsystemRel.Target = $cgInstance
$discoveryData.AddInstance($hsvcManagesSSubsystemRel)
# Get the consistency group volumes that are associated with this consistency group
$url = ""
$url = $baseUrl + $arrayWWN + "/consistency-groups/" + $cg.cgRef + "/member-volumes/"
$cgVolumes = Invoke-RestMethod $url -Credential $cred
foreach ($cgv in $cgVolumes)
{
# Create consistency group volume
$cgvInstance = $discoveryData.CreateClassInstance("$MPElement[Name='NetAppSANtricity.ConsistencyGroupVolume']$")
$cgvInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $cgv.baseVolumeName)
$cgvInstance.AddProperty("$MPElement[Name='NetAppSANtricity.ConsistencyGroupVolume']/volumeWwn$", $cgv.volumeWwn)
$cgvInstance.AddProperty("$MPElement[Name='NetAppSANtricity.ConsistencyGroupVolume']/totalRepositoryVolumes$", $cgv.totalRepositoryVolumes)
$cgvInstance.AddProperty("$MPElement[Name='NetAppSANtricity.ConsistencyGroupVolume']/totalRepositoryCapacity$", (GetFormattedSize $cgv.totalRepositoryCapacity))
$cgvInstance.AddProperty("$MPElement[Name='NetAppSANtricity.ConsistencyGroupVolume']/usedRepositoryCapacity$", (GetFormattedSize $cgv.usedRepositoryCapacity))
$cgvInstance.AddProperty("$MPElement[Name='NetAppSANtricity.ConsistencyGroupVolume']/totalSnapshotImages$", $cgv.totalSnapshotImages)
$cgvInstance.AddProperty("$MPElement[Name='NetAppSANtricity.ConsistencyGroupVolume']/autoDeleteSnapshots$", (GetTrueFalseString $cgv.autoDeleteSnapshots))
$cgvInstance.AddProperty("$MPElement[Name='NetAppSANtricity.ConsistencyGroupVolume']/autoDeleteLimit$", $cgv.autoDeleteLimit)
$cgvInstance.AddProperty("$MPElement[Name='NetAppSANtricity.ConsistencyGroupVolume']/storageArrayName$", $arrayName)
# Adding properties that associate this ConsistencyGroupVolume with its parent ConsistencyGroup
$cgvInstance.AddProperty("$MPElement[Name='NetAppSANtricity.ConsistencyGroup']/cgRef$", $cg.cgRef)
$discoveryData.AddInstance($cgvInstance)
#Create health service associated to CGV
$hsvcManagesSSubsystemRel = $discoveryData.CreateRelationshipInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthServiceShouldManageEntity']$")
$hsvcManagesSSubsystemRel.Source = $healthSvc
$hsvcManagesSSubsystemRel.Target = $cgvInstance
$discoveryData.AddInstance($hsvcManagesSSubsystemRel)
} # foreach ($cgv in $cgVolumes)
} # foreach ($cg in $cgs)
} # if ($cgs)
}
catch
{
# If the array is offline/unreachable then trying to get the CGs causes an error.
}
if ( $Trace )
{
$logString = "CGs and CGVs Discovery for array: " + $arrayName + " Completed. CGs processed: " + $cgs.Count
$api.LogScriptEvent($ScriptName, $E_NBR_TRACE, $E_LVL_INFO, $logString)
}