Dim oArgs
Set oArgs = WScript.Arguments
If oArgs.Count < 7 Then
'Call TraceLogMessage("Arguemnt count is less than 7 :: exiting ")
Wscript.Quit -1
End If
'Call TraceLogMEssage("SourceID=["&SourceID&"]:ManagedEntityId["&ManagedEntityId&"]:TargetComputer["&TargetComputer &"]")
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
Set oAPI = CreateObject("MOM.ScriptAPI")
set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
' Get the Registry Key
objReg.GetStringValue HKEY_LOCAL_MACHINE,strKeyPath,strEntryName,strValue
If Len(strValue) > 0 Then
Set xmlDOC =CreateObject("MSXML.DOMDocument")
xmlDOC.setProperty "SelectionLanguage", "XPath"
XmlDOC.Async = false
bOK = xmlDOC.load(strValue & "Web Services\Services\Web.config")
If xmlDOC.parseError.errorCode <> 0 Then
myErr = xmlDoc.parseError
dataTierHostName = "XML-DOM-LOAD-ERROR"
'Call TraceLogMessage("Failure on dom loading of Web.config")
Else
Set nodeAppSettings = xmlDOC.selectSingleNode("//appSettings/add/@value")
recordSet = split(nodeappSettings.text, ";")
dataSourceText = split(recordSet(3),"=")
dataTierHostName = dataSourceText(1)
set oInstAT1 = oDiscoveryData.CreateClassInstance("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']$")
call oInstAT1.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/DataTierHostName$", dataTierHostName)
call oInstAT1.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/TFSATComputerName$", TargetComputer )
call oInstAT1.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
call oDiscoveryData.AddInstance(oInstAT1)
'Call TraceLogMessage("Succeeded on dom loading of Web.config: dataTierHostName :=> [" &dataTierHostName &"]")
End If
'//////////////////////////
'############## BEGIN - Get Various App Tier properties [from the GetRegistrationEntries Web-Service Method] ######################"
'Call TraceLogMessage("Begin Web Service build up")
'========================================================================
' Set the "environment variables"
'========================================================================
' WebServiceURL = "http://localhost:8080/Services/v1.0/Registration.asmx"
WebServiceURL = GetTfsUrl() & "/Services/v1.0/Registration.asmx"
Call TraceLogMessage("WebServiceURL=>["&WebServiceURL&"]")
'========================================================================
' Now call the web methods
'========================================================================
WebMethodName = "GetRegistrationEntries"
'=========================================================================
' main logic of SOAPClient
'=========================================================================
'Get the Properties of the DOM right
Set xmlDOC2 = CreateObject("MSXML.DOMDocument")
xmlDOC2.SetProperty "SelectionLanguage", "XPath"
XmlDOC2.Async = false
'Call TraceLogMessage("Create SOAP Envelope")
' Create the soapEnvelope as a string body
soapStr = soapStr & "<?xml version=""1.0"" encoding=""utf-8""?>" & vbCrLf
soapStr = soapStr & "<soap:Envelope "
soapStr = soapStr & " xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"""
soapStr = soapStr & " xmlns:xsd=""http://www.w3.org/2001/XMLSchema"""
soapStr = soapStr & " xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/"">"
soapStr = soapStr & vbCrLf
soapStr = soapStr & " <soap:Body>" & vbCrLf
soapStr = soapStr & " <GetRegistrationEntries xmlns=""http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Registration/03""> "
soapStr = soapStr & " <toolId></toolId> "
soapStr = soapStr & " </GetRegistrationEntries> "
soapStr = soapStr & vbCrLf
soapStr = soapStr & " </soap:Body>" & vbCrLf
soapStr = soapStr & " </soap:Envelope>" & vbCrLf
'Call TraceLogMessage("Set the RequestHTTP object and properties")
Set requestHTTP = CreateObject("Microsoft.XMLHTTP")
IF requestHTTP.status <> 200 THEN
'# Usually means the Registration Service call did not return. But we still have to return the DataTier host name we discovered. Hence
'Call TraceLogMessage("Registration :- GetRegistrationEntries method did not return 200 status code")
Call oAPI.Return(oDiscoveryData)
END IF
'''''''DO the XML processing''''''''''''''''''
'========================================================================
' Load the respone.xml into DOM for XPATH processing
'========================================================================
bOK = xmlDOC2.load(requestHTTP.responseXML)
IF xmlDOC2.parseError.errorCode <> 0 THEN
myError = xmlDOC2.parseError
Call TraceLogMessage("You have parse error on loading XmlDOC2" )
'# Usually means the Registration Service call did not return. But we still have to return the DataTier host name we discovered. Hence
Call oAPI.Return(oDiscoveryData)
ELSE
'Call TraceLogMessage("DUMP ENTIRE RESPONSE: [[" & requestHTTP.responseXML.Text & "]]")
' ADDED this to get the namespaces to work right.
' ********************************************************
xmlDOC2.SetProperty "SelectionNamespaces", "xmlns:tns='http://schemas.microsoft.com/TeamFoundation/2005/06/Services/Registration/03'"
' changed the path reference to include namespaces and be XPath simpler
' ********************************************************
Set nodeList = xmlDOC2.selectNodes("//tns:ServiceInterfaces")
'Call TraceLogMessage("After setting node to tns:ServiceInterfaces")
' added check for sanity
' ********************************************************
IF nodeList is nothing THEN
'Call TraceLogMessage( "Null ServiceInterfaces Node returned")
ELSE
' Added: NEED to declare the loop variable
' ***********************************
Select Case serviceName
Case "ReportsService"
vReportService = serviceName
vReportServiceUrl = serviceUrl
Case "WssAdminService"
vWssAdminService = serviceName
vWssAdminServiceUrl = serviceUrl
Case "BaseServerUrl"
vBaseServer = serviceName
vBaseServerUrl = serviceUrl
Case "BaseSiteUrl"
vBaseSite = serviceName
vBaseSiteUrl = serviceUrl
Case "DataSourceServer"
vDataSourceServer = serviceName
vDataSourceServerUrl = serviceUrl
Case "BaseSiteUnc"
vBaseSiteUnc = serviceName
vBaseSiteUncUrl = serviceUrl
Case "BaseReportsUrl"
vBaseReports = serviceName
vBaseReportsUrl = serviceUrl
Case Else
serviceName = ""
serviceUrl =""
End Select
Next
Next
'" Now check for Databases
Set nodeList = xmlDOC2.selectNodes("//tns:Database")
IF nodeList is nothing THEN
'Call TraceLogMessage( "Null Databases Node returned")
ELSE
'Call TraceLogMessage("After setting node to tns:Database")
For each nodeValue in nodeList
'Call TraceLogMessage("Entering FOR LOOP :-> node to tns:Database")
Case Else
'call TraceLogMessage("Reached Case Else in DBNAME - DO NOTHING ")
End Select
Next
END IF
End if
End If
'############## END - Get Various App Tier [properties from the GetRegistrationEntries Web-Service Method ########################"
'//////////////////////////
Else
Call TraceLogMessage("Len("&strValue&") >0 condition failed")
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'''''' Now instantiate the App-Tier class and fill in its property values''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Call TraceLogMessage("'''''' Now instantiate the App-Tier class and fill in its property values''''''''''''")
set oInstAT = oDiscoveryData.CreateClassInstance("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']$")
call oInstAT.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/DataTierHostName$", dataTierHostName)
call oInstAT.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/TFSATComputerName$", TargetComputer )
call oInstAT.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/InstallLocation$", strValue )
call oInstAT.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/BISDB$",vBisDBSQLServerName )
call oInstAT.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/BISDWDB$", vBisDWDBSQLServerName )
call oInstAT.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/BISANALYSISDB$", vBisAnalysisDBSQLServerName )
call oInstAT.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/ReportsServiceUrl$", vReportServiceUrl )
call oInstAT.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/DataSourceServerUrl$", vDataSourceServerUrl )
call oInstAT.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/BaseReportsUrl$", vBaseReportsUrl )
call oInstAT.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/WssAdminServiceUrl$", vWssAdminServiceUrl )
call oInstAT.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/WssBaseServerUrl$", vBaseServerUrl )
call oInstAT.AddProperty("$MPElement[Name='TeamFoundationServer2008.TFSApplicationTier']/WssBaseSiteUrl$", vBaseSiteUrl )
'Call TraceLogMessage("Adding instance data for TeamFoundationServer.ApplicationTier Class: tfsATComputerName:["&tfsATComputerName&"]:dataTierHostName["&dataTierHostName&"]:TargetComputer["&TargetComputer&"]")
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''' Now Create the Relationship and fill in its property values'''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''#######Create the First relationship: AT-TO-SQL ###############################
' Domain name suffix - extract this out of the domain property value and replace.
sFQDN = dataTierHostName&"."&vDNSDomainName
'Call TraceLogMessage("Now Create the TargetClass: SQLServer:DatabaseInstance and fill in its Key property values")
set oDB=oDiscoveryData.CreateClassInstance("$MPElement[Name='TeamFoundationServer2008.TFSDatabaseInstance']$")
call oDB.AddProperty ("$MPElement[Name='MicrosoftSQLServerLibrary!Microsoft.SQLServer.ServerRole']/InstanceName$","MSSQLSERVER" )
call oDB.AddProperty ("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", sFQDN )
' Note that these are all required key properties of Microsoft.SQLServer.ServerRole, and in case you always need the PrincipalName
' Then you create your relationship instance
'Call TraceLogMessage("Now Create the AT-TO-SQL Relationship Instance")
set oRelnShip= oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='TeamFoundationServer2008.TFSATtoTFSDBInstance']$")
oRelnShip.Source = oInstAT
oRelnShip.Target = oDB
'Call TraceLogMessage("Now Add the AT-TO-SQL Relationship Instance")
Call oDiscoveryData.AddInstance(oRelnShip)
''#######Create the Second relationship: AT-TO-SSRS ###############################
'Call TraceLogMessage("Now Create the TargetClass: SQLServer:SSRS and fill in its Key property values")
set oSSRS = oDiscoveryData.CreateClassInstance("$MPElement[Name='TeamFoundationServer2008.TFSReportingServices']$")
'''### Assumes default instance. Else will have to be obtained from Registry entry which will be in the form of hostname\instancename.
call oSSRS.AddProperty ("$MPElement[Name='MicrosoftSQLServerLibrary!Microsoft.SQLServer.ServerRole']/InstanceName$","MSSQLSERVER" )
'''''#### For now we use the DataSourceServerURL property ; Later this will have to be peeled off of the BaseReportsUrl property.
call oSSRS.AddProperty ("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", vDataSourceServerUrl&"."&vDNSDomainName)
' Note that these are all required key properties of Microsoft.SQLServer.ServerRole, and in any case you always need the PrincipalName
' Then you create your relationship instance
'Call TraceLogMessage("Now Create the SSRS Relationship Instance 2")
set oRelnShipSSRS= oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='TeamFoundationServer2008.ATContainsSSRS']$")
'Call TraceLogMessage("Now Add the SSRS Relationship Instance 2")
Call oDiscoveryData.AddInstance(oRelnShipSSRS)
''#######Create the Third relationship: AT-TO-SSAS ###############################
'Call TraceLogMessage("Now Create the TargetClass: SQLServer:SSAS and fill in its Key property values")
IF Len(vBisAnalysisDBSQLServerName) > 0 THEN
set oSSAS = oDiscoveryData.CreateClassInstance("$MPElement[Name='TeamFoundationServer2008.TFSAnalysisServices']$")
'''### Assumes default instance. Else will have to be obtained from Registry entry which will be in the form of hostname\instancename.
call oSSAS.AddProperty ("$MPElement[Name='MicrosoftSQLServerLibrary!Microsoft.SQLServer.ServerRole']/InstanceName$","MSSQLSERVER" )
call oSSAS.AddProperty ("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", vBisAnalysisDBSQLServerName&"."&vDNSDomainName)
' Note that these are all required key properties of Microsoft.SQLServer.ServerRole, and in any case you always need the PrincipalName
' Then you create your relationship instance
'Call TraceLogMessage("Now Create the SSAS Relationship Instance 3")
set oRelnShipSSAS= oDiscoveryData.CreateRelationshipInstance("$MPElement[Name='TeamFoundationServer2008.ATContainsSSAS']$")
'' ###################### FUNCTIONS ###############################
Function GetTfsInstallFolder()
Dim WSHShell, RegKey, sFolder
Set WSHShell = CreateObject("WScript.Shell")
RegKey = "HKLM\SOFTWARE\Microsoft\VisualStudio\9.0\TeamFoundation\ATInstallPath"
sFolder = WSHShell.RegRead(RegKey)
GetTfsInstallFolder = sFolder
End Function
Function GetTfsUrl()
Dim sTfsWebConfigFile, xmlWebConfig, nodeTfsUrl, bConfigFileLoaded
sTfsWebConfigFile= GetTfsInstallFolder() & "Web Services\Web.Config"
Set xmlWebConfig = CreateObject("MSXML.DOMDocument")
xmlWebConfig.SetProperty "SelectionLanguage", "XPath"
xmlWebConfig.Async = false
bConfigFileLoaded = xmlWebConfig.load(sTfsWebConfigFile)
If bConfigFileLoaded = False Then
Exit Function
End If
Set nodeTfsUrl = xmlWebConfig.selectSingleNode("//add[@key = 'TFSNameUrl']/@value")
If nodeTfsUrl Is Nothing Then
Exit Function
End If
GetTfsUrl = nodeTfsUrl.Value
End Function
'''########## 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