AppFabric Cache Cluster Discovery

Microsoft.DistributedCache.Cluster.Discovery (Discovery)

This discovery discovers cache clusters that have been deployed.

Knowledge Base article:

Summary

This discovery discovers cache clusters that have been deployed.

Element properties:

TargetMicrosoft.DistributedCache.ServerRole
EnabledTrue
Frequency14900
RemotableFalse

Object Discovery Details:

Discovered Classes and their attribuets:
Discovered relationships and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.CommandExecuterDiscoveryDataSource Microsoft.DistributedCache.CacheClusterAdminAccount

Source Code:

<Discovery ID="Microsoft.DistributedCache.Cluster.Discovery" Enabled="true" Target="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.ServerRole" ConfirmDelivery="true" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryClass TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Clusters">
<Property TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Clusters" PropertyID="ClustersName"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="MicrosoftApplicationServerLibrary!Microsoft.ApplicationServer.Service">
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cluster">
<Property TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cluster" PropertyID="ConnectionString"/>
<Property TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cluster" PropertyID="Provider"/>
<Property TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cluster" PropertyID="IsInitialized"/>
<Property TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cluster" PropertyID="Size"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.CacheAdmin">
<Property TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.CacheAdmin" PropertyID="CacheAdminName"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryClass TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache">
<Property TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache" PropertyID="CacheName"/>
<Property TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache" PropertyID="TimeToLive"/>
<Property TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache" PropertyID="CacheType"/>
<Property TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache" PropertyID="Secondaries"/>
<Property TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache" PropertyID="IsExpirable"/>
<Property TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache" PropertyID="EvictionType"/>
<Property TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache" PropertyID="NotificationsEnabled"/>
<Property TypeID="System!System.Entity" PropertyID="DisplayName"/>
</DiscoveryClass>
<DiscoveryRelationship TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.ServiceContainsClusters"/>
<DiscoveryRelationship TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.ClustersContainsCluster"/>
<DiscoveryRelationship TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.ClusterContainsServerRole"/>
<DiscoveryRelationship TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.ServerRoleHostsCacheAdmin"/>
<DiscoveryRelationship TypeID="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.CacheAdminHostsCache"/>
</DiscoveryTypes>
<DataSource ID="DS" RunAs="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.CacheClusterAdminAccount" TypeID="System!System.CommandExecuterDiscoveryDataSource">
<IntervalSeconds>14900</IntervalSeconds>
<ApplicationName>%windir%\system32\windowspowershell\v1.0\powershell.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>-Command ".\Create-Clusters.ps1"</CommandLine>
<TimeoutSeconds>600</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>Create-Clusters.ps1</Name>
<Contents><Script>


function Get-SHA1Hash
{
param([string]$stringValueToHash)
$hashAlgorithm = new-object System.Security.Cryptography.SHA1Managed
$computedHashBytes = $hashAlgorithm.ComputeHash($([Char[]]$stringValueToHash.ToUpperInvariant()));

$stringBuilder = New-Object System.Text.StringBuilder
$computedHashBytes | Foreach-Object { [void] $stringBuilder.Append($_.ToString("X2")) }
return $stringBuilder.ToString()
}

# Create a new discovery data packet -- this assumes that the client SDK is available, which it is on all OpsMgr agents
$Error.Clear()
$oAPI = new-object -comObject "MOM.ScriptAPI"
$Discovery = $oAPI.CreateDiscoveryData(0, '$MPElement$', '$Target/Id$')

#$oAPI.LogScriptEvent("Create-Clusters.ps1", 123, 4, "Init")

$connectionString = $null
$provider = $null

#Load module, cmdlets are used to get connection string and cluster information
if ((Get-Command -Module DistributedCacheConfiguration) -eq $null)
{
Import-Module DistributedCacheConfiguration #Distributed Cache Configuration PS module
}

$connectionString = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\AppFabric\v1.0\Configuration).ConnectionString
$provider = (Get-ItemProperty HKLM:\SOFTWARE\Microsoft\AppFabric\v1.0\Configuration).Provider

if ([string]::IsNullOrEmpty($connectionString) -or [string]::IsNullOrEmpty($provider))
{
$connectionStringInfo = $null
$connectionStringInfo = Get-CacheConnectionString -ErrorAction SilentlyContinue
if ($connectionStringInfo -ne $null)
{
$connectionString = $connectionStringInfo.ConnectionString
$provider = $connectionStringInfo.Provider
}
}

if ([string]::IsNullOrEmpty($connectionString) -or [string]::IsNullOrEmpty($provider))
{
throw "Unable to query connection string and provider information."
}

$hashedConnectionString = Get-SHA1Hash -stringValueToHash $connectionString

# Create Service contains Clusters relation
$sourceService = $Discovery.CreateClassInstance("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.ApplicationServer.Service']$")
$sourceClusters = $Discovery.CreateClassInstance("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Clusters']$")
$sourceClusters.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Clusters']/ClustersName$", 'Distributed Cache Clusters')
$Discovery.AddInstance($sourceClusters)

$relation = $Discovery.CreateRelationshipInstance("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.ServiceContainsClusters']$")
$relation.Source = $sourceService
$relation.Target = $sourceClusters
$Discovery.AddInstance($relation)

# Create Clusters contains Cluster relation
$cluster = $Discovery.CreateClassInstance("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cluster']$")
$cluster.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cluster']/ConnectionString$", $hashedConnectionString)
$cluster.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cluster']/Provider$", $provider)
$cluster.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", 'Distributed Cache Cluster -' + $hashedConnectionString)

$clusterInfo = $null
if ($provider.CompareTo("xml") -eq 0)
{
$connectionStringDir = (Get-Item $connectionString).Directory.FullName
$clusterInfo = Get-CacheClusterInfo -Provider $provider -ConnectionString $connectionStringDir -ErrorAction SilentlyContinue
}
else
{
$clusterInfo = Get-CacheClusterInfo -Provider $provider -ConnectionString $connectionString -ErrorAction SilentlyContinue
}

if ($clusterInfo -ne $null)
{
$cluster.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cluster']/IsInitialized$", $clusterInfo.IsInitialized)
$cluster.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cluster']/Size$", $clusterInfo.Size)
}

$Discovery.AddInstance($cluster)

$relation = $Discovery.CreateRelationshipInstance("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.ClustersContainsCluster']$")
$relation.Source = $sourceClusters
$relation.Target = $cluster
$Discovery.AddInstance($relation)

# Create Cluster contains ServerRole relation
$serverRole = $Discovery.CreateClassInstance("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.ServerRole']$")
$serverRole.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", '$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$')

$relation = $Discovery.CreateRelationshipInstance("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.ClusterContainsServerRole']$")
$relation.Source = $cluster
$relation.Target = $serverRole

$Discovery.AddInstance($relation)

#if Admin tools are installed then discover cache objects
$isAdminConfigured = $Target/Property[Type="MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.ServerRole"]/AdminConfigured$
if ($isAdminConfigured -eq 1)
{
if ((Get-Command -Module DistributedCacheAdministration) -eq $null)
{
Import-Module DistributedCacheAdministration #Distributed Cache Admin PS module
Use-CacheCluster
}

# Create CacheAdmin and ServerRole contains CacheAdmin relation
$cacheAdmin = $Discovery.CreateClassInstance("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.CacheAdmin']$")
$cacheAdmin.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.CacheAdmin']/CacheAdminName$", 'Distributed Cache Cluster Admin')
$cacheAdmin.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", '$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$')
$Discovery.AddInstance($cacheAdmin)

$relation = $Discovery.CreateRelationshipInstance("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.ServerRoleHostsCacheAdmin']$")
$relation.Source = $serverRole
$relation.Target = $cacheAdmin
$Discovery.AddInstance($relation)

$cacheObjects = $null
$cacheObjects = Get-Cache -ErrorAction SilentlyContinue
if ($cacheObjects -ne $null)
{
foreach ($cacheObject in $cacheObjects)
{
$cacheInfo = $null
$cacheInfo = Get-CacheConfig -CacheName $cacheObject.CacheName -ErrorAction SilentlyContinue

if ($cacheInfo -ne $null)
{
# Create Cache and CacheAdmin contains Cache relation
$target = $Discovery.CreateClassInstance("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache']$")
$target.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache']/CacheName$", $cacheInfo.CacheName)
$target.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache']/TimeToLive$", $cacheInfo.TimeToLive)
$target.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache']/CacheType$", $cacheInfo.CacheType)
$target.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache']/Secondaries$", $cacheInfo.Secondaries)
$target.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache']/IsExpirable$", $cacheInfo.IsExpirable)
$target.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache']/EvictionType$", $cacheInfo.EvictionType)
$target.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.Cache']/NotificationsEnabled$", $cacheInfo.NotificationsEnabled)

$target.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", '$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$')
$target.AddProperty("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.CacheAdmin']/CacheAdminName$", 'Distributed Cache Cluster Admin')
$Discovery.AddInstance($target)

$relation = $Discovery.CreateRelationshipInstance("$MPElement[Name='MicrosoftApplicationServerLibrary!Microsoft.DistributedCache.CacheAdminHostsCache']$")
$relation.Source = $cacheAdmin
$relation.Target = $target

$Discovery.AddInstance($relation)
}
}
}
}

# Return the discovery data by calling the variable
$oAPI.Return($Discovery)
return

trap
{
if ($oAPI -ne $null)
{
foreach($errorDetail in $Error)
{
$oAPI.LogScriptEvent("Create-Clusters.ps1", 100, 1, $errorDetail.Exception)
}

$Discovery.IsSnapshot = $false
$oAPI.Return($Discovery)
}

return
}

</Script></Contents>
<Unicode>1</Unicode>
</File>
</Files>
</DataSource>
</Discovery>