Discover Relationship of AppTier to TFS DB Rule

TeamFoundationServer2008.DiscoverAppTierToTFSDatabaseRelationshipRule (Discovery)

Knowledge Base article:

Summary

This discovers the relationship between the Application Tier and the SQL instance

Element properties:

TargetTeamFoundationServer2008.TFSApplicationTier
EnabledTrue
Frequency900
RemotableFalse

Object Discovery Details:

Discovered relationships and their attribuets:

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.TimedScript.DiscoveryProvider Default

Source Code:

<Discovery ID="TeamFoundationServer2008.DiscoverAppTierToTFSDatabaseRelationshipRule" Enabled="true" Target="TeamFoundationServer2008.TFSApplicationTier" ConfirmDelivery="false" Remotable="true" Priority="Normal">
<Category>Discovery</Category>
<DiscoveryTypes>
<DiscoveryRelationship TypeID="TeamFoundationServer2008.ATtoDBContainmentRelationship"/>
</DiscoveryTypes>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>900</IntervalSeconds>
<SyncTime/>
<ScriptName>RelnATtoTFSDB.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Target/Property[Type="TeamFoundationServer2008.TFSApplicationTier"]/TFSATComputerName$ $Target/Property[Type="TeamFoundationServer2008.TFSApplicationTier"]/DataTierHostName$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/DomainDnsName$</Arguments>
<ScriptBody><Script>Dim SourceId, ManagedEntityId, tfsATComputerName, dataTierHostName, principalName
Dim oSource, oDB, oDB2, oDB3, oDiscoveryData, oAPI, oRelnShipVC, oRelnShipWIT, oRelnShipTfsIntegration

Dim sVCDatabaseName, sWITDatabaseName,sTFSIntegration, sDBHostNameRel, sFQDNSource, sFQDNTarget, sDNSDomainName

Dim oArgs
Set oArgs = WScript.Arguments
If oArgs.Count &lt; 6 Then
Wscript.Quit -1
End If





SourceId = oArgs(0)
ManagedEntityId = oArgs(1)
tfsATComputerName = oArgs(2)
dataTierHostName = oArgs(3)
principalName = oArgs(4)
sDNSDomainName = oArgs(5)




Set oAPI = CreateObject("MOM.ScriptAPI")
set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''' Now Create the Relationship and fill in its property values'''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

sVCDatabaseName = "TfsVersionControl"
sWITDatabaseName = "TfsWorkItemTracking"
sTFSIntegration = "TfsIntegration"
sDBHostNameRel = dataTierHostName
sFQDNSource = tfsATComputerName
sFQDNTarget = dataTierHostName&amp;"."&amp;sDNSDomainName

'Call TraceLogMessage("TFSATComputerName=["&amp;tfsATComputerName&amp;"];dataTierHostName=["&amp;dataTierHostName&amp;"];sFQDNSource=["&amp;sFQDNSource&amp;"];sFQDNTarget =["&amp;sFQDNTarget&amp;"]sDNSDomainName=["&amp;sDNSDomainName&amp;"]")

' First create the source of the relationship which is the TFSApplicationTier Class with the key TFSATComputerName
'Call TraceLogMessage("Create the SourceClass :TFSApplicationTier and fill in its Key property values")
set oSource = oDiscoveryData.CreateClassInstance("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']$")
call oSource.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/TFSATComputerName$",tfsATComputerName)
call oSource.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", sFQDNSource )
'Call TraceLogMessage("TFSATComputerName=["&amp;tfsATComputerName&amp;"];sFQDNSource=["&amp;sFQDNSource&amp;"]")

''''######################### Version Control Database ###############
'Call TraceLogMessage("Now Create the TargetClass: SQLServer:Version Control Database and fill in its Key property values")
set oDB=oDiscoveryData.CreateClassInstance("$MPElement[Name='TeamFoundationServer2008.TFSDatabase']$")
call oDB.AddProperty ("$MPElement[Name='MicrosoftSQLServerLibrary!Microsoft.SQLServer.Database']/DatabaseName$", sVCDatabaseName )
call oDB.AddProperty ("$MPElement[Name='MicrosoftSQLServerLibrary!Microsoft.SQLServer.ServerRole']/InstanceName$","MSSQLSERVER" )
call oDB.AddProperty ("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", sFQDNTarget )
'Call TraceLogMessage("DatabaseName =["&amp;sVCDatabaseName &amp;"];sFQDNTarget =["&amp;sFQDNTarget &amp;"]")

' note that these are all required key properties of Microsoft.SQLServer.2005.Database
'Then you create your relationship instance

'Call TraceLogMessage("Now Create the VC Relationship Instance")
set oRelnShipVC= oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='TeamFoundationServer2008.ATtoDBContainmentRelationship']$")

oRelnShipVC.Source = oSource
oRelnShipVC.Target = oDB

'Call TraceLogMessage("Now Add the VC Relationship Instance")
Call oDiscoveryData.AddInstance(oRelnShipVC)

''''######################### Work Item Tracking Database ###############
'Call TraceLogMessage("Now Create the TargetClass: SQLServer:WIT Database and fill in its Key property values")
set oDB2=oDiscoveryData.CreateClassInstance("$MPElement[Name='TeamFoundationServer2008.TFSDatabase']$")
call oDB2.AddProperty ("$MPElement[Name='MicrosoftSQLServerLibrary!Microsoft.SQLServer.Database']/DatabaseName$", sWITDatabaseName )
call oDB2.AddProperty ("$MPElement[Name='MicrosoftSQLServerLibrary!Microsoft.SQLServer.ServerRole']/InstanceName$","MSSQLSERVER" )
call oDB2.AddProperty ("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", sFQDNTarget )
'Call TraceLogMessage("DatabaseName =["&amp;sWITDatabaseName &amp;"];sFQDNTarget =["&amp;sFQDNTarget &amp;"]")

' note that these are all required key properties of Microsoft.SQLServer.2005.Database
'Then you create your relationship instance

'Call TraceLogMessage("Now Create the WIT Relationship Instance")
set oRelnShipWIT= oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='TeamFoundationServer2008.ATtoDBContainmentRelationship']$")

oRelnShipWIT.Source = oSource
oRelnShipWIT.Target = oDB2

'Call TraceLogMessage("Now Add the WIT Relationship Instance")
Call oDiscoveryData.AddInstance(oRelnShipWIT)


''''######################### TFS Integration Database (based on BGCOE) ###############
'Call TraceLogMessage("Now Create the TargetClass: SQLServer:WIT Database and fill in its Key property values")
set oDB3=oDiscoveryData.CreateClassInstance("$MPElement[Name='TeamFoundationServer2008.TFSDatabase']$")
call oDB3.AddProperty ("$MPElement[Name='MicrosoftSQLServerLibrary!Microsoft.SQLServer.Database']/DatabaseName$", sTFSIntegration )
call oDB3.AddProperty ("$MPElement[Name='MicrosoftSQLServerLibrary!Microsoft.SQLServer.ServerRole']/InstanceName$","MSSQLSERVER" )
call oDB3.AddProperty ("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", sFQDNTarget )
'Call TraceLogMessage("DatabaseName =["&amp;sWITDatabaseName &amp;"];sFQDNTarget =["&amp;sFQDNTarget &amp;"]")

' note that these are all required key properties of Microsoft.SQLServer.2005.Database
'Then you create your relationship instance

'Call TraceLogMessage("Now Create the WIT Relationship Instance")
set oRelnShipTfsIntegration= oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='TeamFoundationServer2008.ATtoDBContainmentRelationship']$")

oRelnShipTfsIntegration.Source = oSource
oRelnShipTfsIntegration.Target = oDB3

'Call TraceLogMessage("Now Add the WIT Relationship Instance")
Call oDiscoveryData.AddInstance(oRelnShipTfsIntegration)





Call oAPI.Return(oDiscoveryData)

'###### FUNCTION TRACELOGMESSAGE ################
Function TraceLogMessage(ByVal sMessage)
Dim lsEventInformation
WScript.Echo sMessage

' Retrieve the name of this (running) script
Dim FSO, ScriptFileName
Set FSO = CreateObject("Scripting.FileSystemObject")
ScriptFileName = FSO.GetFile(WScript.ScriptFullName).Name
Set FSO = Nothing

On Error Resume Next
Dim oAPITemp
Set oAPITemp = CreateObject("MOM.ScriptAPI")
lsEventInformation = 3
oAPITemp.LogScriptEvent ScriptFileName, 4000, lsEventInformation, sMessage
On Error Goto 0
End Function</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</DataSource>
</Discovery>