Answered by:
Third Level host discovery is not working

Question
-
Hi,
I have 3 discovery classes A-(hosts)->B-(Hosts)->C.
Class A targets windows Computer
Class B targets A
Class C Targets B
I can see A and B discovered and associated to each other in OpsManager but class C is not discovered. The discovery is done using PowerShell scripts and I can see the scripts running on the client machines.
There are no errors in PowerShell and OpsManager logs.
<TypeDefinitions> <EntityTypes> <ClassTypes> <ClassType ID="Hierarchy.Class.A" Accessibility="Public" Abstract="false" Base="System!System.LogicalEntity" Hosted="false" Singleton="false"> <Property ID="A" Type="string" Key="true" CaseSensitive="false" Length="256" MinLength="0" /> </ClassType> <ClassType ID="Hierarchy.Class.B" Accessibility="Public" Abstract="false" Base="System!System.LogicalEntity" Hosted="true" Singleton="false"> <Property ID="B" Type="string" Key="true" CaseSensitive="false" Length="256" MinLength="0" /> </ClassType> <ClassType ID="Hierarchy.Class.C" Accessibility="Public" Abstract="false" Base="System!System.LogicalEntity" Hosted="true" Singleton="false"> <Property ID="C" Type="string" Key="true" CaseSensitive="false" Length="256" MinLength="0" /> </ClassType> </ClassTypes> <RelationshipTypes> <RelationshipType ID="Hierarchy.Relationship.AHostsB" Accessibility="Public" Abstract="false" Base="System!System.Hosting"> <Source>Hierarchy.Class.A</Source> <Target>Hierarchy.Class.B</Target> </RelationshipType> <RelationshipType ID="Hierarchy.Relationship.BHostsC" Accessibility="Public" Abstract="false" Base="System!System.Hosting"> <Source>Hierarchy.Class.B</Source> <Target>Hierarchy.Class.C</Target> </RelationshipType> </RelationshipTypes> </EntityTypes> </TypeDefinitions> <Monitoring> <Discoveries> <Discovery ID="Hierarchy.Discovery.A" Enabled="true" Target="Windows!Microsoft.Windows.Computer" ConfirmDelivery="true" Remotable="true" Priority="Normal"> <Category>Discovery</Category> <DiscoveryTypes> <DiscoveryClass TypeID="Hierarchy.Class.A"> <Property TypeID="Hierarchy.Class.A" PropertyID="A" /> <Property TypeID="System!System.Entity" PropertyID="DisplayName" /> </DiscoveryClass> <DiscoveryRelationship TypeID="SC!Microsoft.SystemCenter.HealthServiceShouldManageEntity" /> <DiscoveryRelationship TypeID="Hierarchy.Relationship.AHostsB" /> </DiscoveryTypes> <DataSource ID="PSDiscoveryA" TypeID="System!System.CommandExecuterDiscoveryDataSource"> <IntervalSeconds>180</IntervalSeconds> <ApplicationName><![CDATA[%windir%\system32\windowspowershell\v1.0\powershell.exe]]></ApplicationName> <WorkingDirectory /> <CommandLine>.\ADiscovery.ps1</CommandLine> <TimeoutSeconds>170</TimeoutSeconds> <RequireOutput>true</RequireOutput> <Files> <File> <Name>ADiscovery.ps1</Name> <Contents><![CDATA[ $SourceId = "$MPElement$" $ManagedEntityId = "$Target/Id$" $PrincipalName = "$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$" Set-ExecutionPolicy Unrestricted $snapIns = Get-PSSnapin $api = New-Object -ComObject 'MOM.ScriptAPI' $oDiscoveryData = $api.CreateDiscoveryData(0, $SourceId, $ManagedEntityId) $EventLog = new-object System.Diagnostics.EventLog('Application') $EventLog.MachineName = "." $EventLog.Source = "A" $EventLog.WriteEntry("A Starting ... $PrincipalName") $error.clear() $DateTime = [System.DateTime]::Now $Millisecond = $DateTime.Millisecond $Time = "$DateTime$Millisecond" $CurrentTime = $Time.ToString() $Inst = $oDiscoveryData.CreateClassInstance("$MPElement[Name='Hierarchy.Class.A']$") $Inst.AddProperty("$MPElement[Name='Hierarchy.Class.A']/A$", "A on $PrincipalName") $Inst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "$PrincipalName") $oDiscoveryData.AddInstance($Inst) $oHealthServiceInstance = $oDiscoveryData.CreateClassInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthService']$") $oHealthServiceInstance.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$",$PrincipalName ) $oRel = $oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='SC!Microsoft.SystemCenter.HealthServiceShouldManageEntity']$") $oRel.Source = $oHealthServiceInstance $oRel.Target = $Inst $oDiscoveryData.AddInstance($oRel) $EventLog.WriteEntry("A Ending ... : $error") $api.Return($oDiscoveryData) ]]></Contents> </File> </Files> </DataSource> </Discovery> <Discovery ID="Hierarchy.Discovery.B" Enabled="true" Target="Hierarchy.Class.A" ConfirmDelivery="true" Remotable="true" Priority="Normal"> <Category>Discovery</Category> <DiscoveryTypes> <DiscoveryClass TypeID="Hierarchy.Class.B"> <Property TypeID="Hierarchy.Class.B" PropertyID="B" /> <Property TypeID="System!System.Entity" PropertyID="DisplayName" /> </DiscoveryClass> <DiscoveryRelationship TypeID="Hierarchy.Relationship.BHostsC" /> </DiscoveryTypes> <DataSource ID="PSDiscoveryB" TypeID="System!System.CommandExecuterDiscoveryDataSource"> <IntervalSeconds>150</IntervalSeconds> <ApplicationName><![CDATA[%windir%\system32\windowspowershell\v1.0\powershell.exe]]></ApplicationName> <WorkingDirectory /> <CommandLine>.\BDiscovery.ps1</CommandLine> <TimeoutSeconds>140</TimeoutSeconds> <RequireOutput>true</RequireOutput> <Files> <File> <Name>BDiscovery.ps1</Name> <Contents><![CDATA[ $SourceId = "$MPElement$" $ManagedEntityId = "$Target/Id$" $A = "$Target/Property[Type="Hierarchy.Class.A"]/A$" Set-ExecutionPolicy Unrestricted $snapIns = Get-PSSnapin $api = New-Object -ComObject 'MOM.ScriptAPI' $oDiscoveryData = $api.CreateDiscoveryData(0, $SourceId, $ManagedEntityId) $Inst = $oDiscoveryData.CreateClassInstance("$MPElement[Name='Hierarchy.Class.B']$") $Inst.AddProperty("$MPElement[Name='Hierarchy.Class.B']/B$", "AB on $A") $Inst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "AB") $Inst.AddProperty("$MPElement[Name='Hierarchy.Class.A']/A$", $A) $oDiscoveryData.AddInstance($Inst) $api.Return($oDiscoveryData) ]]></Contents> </File> </Files> </DataSource> </Discovery> <Discovery ID="Hierarchy.Discovery.C" Enabled="true" Target="Hierarchy.Class.B" ConfirmDelivery="true" Remotable="true" Priority="Normal"> <Category>Discovery</Category> <DiscoveryTypes> <DiscoveryClass TypeID="Hierarchy.Class.C"> <Property TypeID="Hierarchy.Class.C" PropertyID="C" /> <Property TypeID="System!System.Entity" PropertyID="DisplayName" /> </DiscoveryClass> </DiscoveryTypes> <DataSource ID="PSDiscoveryC" TypeID="System!System.CommandExecuterDiscoveryDataSource"> <IntervalSeconds>120</IntervalSeconds> <ApplicationName><![CDATA[%windir%\system32\windowspowershell\v1.0\powershell.exe]]></ApplicationName> <WorkingDirectory /> <CommandLine>.\CDiscovery.ps1</CommandLine> <TimeoutSeconds>110</TimeoutSeconds> <RequireOutput>true</RequireOutput> <Files> <File> <Name>CDiscovery.ps1</Name> <Contents><![CDATA[ $SourceId = "$MPElement$" $ManagedEntityId = "$Target/Id$" $B = "$Target/Property[Type="Hierarchy.Class.B"]/B$" Set-ExecutionPolicy Unrestricted $snapIns = Get-PSSnapin $api = New-Object -ComObject 'MOM.ScriptAPI' $oDiscoveryData = $api.CreateDiscoveryData(0, $SourceId, $ManagedEntityId) $Inst = $oDiscoveryData.CreateClassInstance("$MPElement[Name='Hierarchy.Class.C']$") $Inst.AddProperty("$MPElement[Name='Hierarchy.Class.C']/C$", "ABC on $B") $Inst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "ABC") $Inst.AddProperty("$MPElement[Name='Hierarchy.Class.B']/B$", $B) $oDiscoveryData.AddInstance($Inst) $api.Return($oDiscoveryData) ]]></Contents> </File> </Files> </DataSource> </Discovery> </Discoveries> </Monitoring> <LanguagePacks> <LanguagePack ID="ENG" IsDefault="false"> <DisplayStrings> <DisplayString ElementID="Hierarchy"> <Name>Hierarchy</Name> <Description> Simple Hierarchy Check</Description> </DisplayString> <DisplayString ElementID="Hierarchy.Class.A"> <Name>A</Name> <Description>This is Class A</Description> </DisplayString> <DisplayString ElementID="Hierarchy.Class.B"> <Name>B</Name> <Description>This is class B</Description> </DisplayString> <DisplayString ElementID="Hierarchy.Class.B" SubElementID="B"> <Name>B</Name> </DisplayString> <DisplayString ElementID="Hierarchy.Discovery.A"> <Name>A</Name> <Description>Test Class A </Description> </DisplayString> </DisplayStrings> </LanguagePack> <LanguagePack ID="ENU" IsDefault="true"> <DisplayStrings> <DisplayString ElementID="Hierarchy"> <Name>Hierarchy</Name> <Description> Simple Hierarchy Check</Description> </DisplayString> <DisplayString ElementID="Hierarchy.Class.A"> <Name>A</Name> <Description>This is Class A</Description> </DisplayString> <DisplayString ElementID="Hierarchy.Class.B"> <Name>B</Name> <Description>This is class B</Description> </DisplayString> <DisplayString ElementID="Hierarchy.Class.B" SubElementID="B"> <Name>B</Name> </DisplayString> <DisplayString ElementID="Hierarchy.Class.C"> <Name>C</Name> <Description>Test Class C</Description> </DisplayString> <DisplayString ElementID="Hierarchy.Discovery.A"> <Name>A</Name> <Description /> </DisplayString> <DisplayString ElementID="Hierarchy.Discovery.B"> <Name>B</Name> <Description>Test Descovery Class B</Description> </DisplayString> <DisplayString ElementID="Hierarchy.Discovery.C"> <Name>C</Name> <Description>Test Discovery Class C</Description> </DisplayString> <DisplayString ElementID="Hierarchy.Relationship.AHostsB"> <Name>AHostsB</Name> <Description>AHostsB</Description> </DisplayString> <DisplayString ElementID="Hierarchy.Relationship.BHostsC"> <Name>BHostsC</Name> <Description>BHostsC</Description> </DisplayString> </DisplayStrings> </LanguagePack> </LanguagePacks> </ManagementPack>
Thursday, May 19, 2011 7:34 AM
Answers
-
Couple of issues. You can eliminate the "agent should manage" logic from all of your discoveries as this is not needed and will not change your results.
your C discovery will not function as coded because you did not specifiy the full key up to A. You need to add the A property to C discovery to get the right pair of AB to be selected. To get the $A value in this case, you have to use $A = "$Target/Host/Host/Property[Type='Hierarchy.Class.A']/A$" and then add the line
$Inst.AddProperty("$MPElement[Name='Hierarchy.Class.A']/A$", $A)
To your C discovery to get it to work.
Microsoft Corporation- Marked as answer by Yog Li Friday, May 27, 2011 8:59 AM
Thursday, May 19, 2011 8:31 PM