BAM Analysis Discovery Module

Microsoft.BizTalk.Server.2016.BAMAnalysisDiscovery (DataSourceModuleType)

Discovers BAM analysis and BAM alerts components, if configured on a computer where BAM run time is discovered.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsMicrosoft.BizTalk.DiscoveryAccount
OutputTypeSystem.Discovery.Data

Member Modules:

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

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
IntervalSecondsint$Config/IntervalSeconds$Interval SecondsThis is the interval (in seconds) at which the script associated with the module is run.
TimeoutSecondsint$Config/TimeoutSeconds$Timeout SecondsThis is the timeout (in seconds) after which execution of the script associated with the module is terminated if not yet completed.

Source Code:

<DataSourceModuleType ID="Microsoft.BizTalk.Server.2016.BAMAnalysisDiscovery" Accessibility="Public" RunAs="Microsoft.BizTalk.DiscoveryAccount" Batching="false">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DataSource" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<SyncTime/>
<ScriptName>Microsoft.BizTalk.Server.2016.BAMAnalysisDiscovery.vbs</ScriptName>
<Arguments>$MPElement$ $Target/Id$ $Target/Property[Type="Microsoft.BizTalk.Server.2016.BAMRuntime"]/BAMPrimaryImportDbName$ $Target/Property[Type="Microsoft.BizTalk.Server.2016.BAMRuntime"]/BAMPrimaryImportDbServerName$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Arguments>
<ScriptBody><Script>
'Copyright (c) Microsoft Corporation. All rights reserved

'This script discovers BAM analysis and alerts components on a computer where
'BAM runtime component is discovered.

Option Explicit

Const BAM_DISCOVERY_CONNECT_FAILURE = -1
Const BAM_DISCOVERY_QUERY_FAILURE = -2

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

Dim SourceID, ManagedEntityId
Dim BAMDbName, BAMDbServerName
Dim ComputerName

BAMDbName = null
BAMDbServerName = null

SourceId = oArgs(0)
ManagedEntityId = oArgs(1)
BAMDbName = oArgs(2)
BAMDbServerName = oArgs(3)
ComputerName = oArgs(4)

Call GetBAMRuntimeComponents()

Sub GetBAMRuntimeComponents()
Dim objAPI, objDiscoveryData
Set objAPI = CreateObject("MOM.ScriptAPI")
Set objDiscoveryData = objAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)

if Not IsNull(BAMDbName) and Not IsNull(BAMDbServerName) then
Dim defaultConnStr
defaultConnStr = "Server=" &amp; BAMDbServerName &amp; ";Database=" &amp; BAMDbName &amp; ";Trusted_Connection=yes"
CreateObjectsAndRelations defaultConnStr, objAPI, objDiscoveryData
end if

Call objAPI.Return(objDiscoveryData)
End Sub

Function CreateObjectsAndRelations(defaultConnStr, byRef objAPI, byRef objDiscoveryData)
Dim ObjError
Set ObjError = New Error

Dim cnADOConnection
Set cnADOConnection = MomCreateObject("ADODB.Connection")
cnADOConnection.Provider = "SQLNCLI11"
cnADOConnection.ConnectionTimeout = 15

ObjError.Clear
On Error Resume Next
cnADOConnection.Open defaultConnStr
ObjError.Save
On Error Goto 0
If 0 &lt;&gt; Err.number then
CreateObjectsAndRelations = BAM_DISCOVERY_CONNECT_FAILURE
Exit Function
End If

Dim objResults

ObjError.Clear
On Error Resume Next
Set objResults = cnADOConnection.Execute("select * from bam_Metadata_Properties bmp with (NoLock) where bmp.Scope = 'AnalysisDatabase' or bmp.Scope = 'StarSchemaDatabase' or bmp.Scope = 'Alert'")
ObjError.Save
On Error Goto 0

If ObjError.Number &lt;&gt; 0 Then
CreateObjectsAndRelations = BAM_DISCOVERY_QUERY_FAILURE
If (objResults &lt;&gt; null) Then objResults.Close
Exit Function
End If

Dim oBAMAnalysis, oBAMAlerts, oBAMRuntime

Set oBAMRuntime = objDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMRuntime']$")
call oBAMRuntime.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", ComputerName)
call oBAMRuntime.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMRuntime']/BAMPrimaryImportDbName$", BAMDbName)
call oBAMRuntime.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMRuntime']/BAMPrimaryImportDbServerName$", BAMDbServerName)

Dim AnalysisDb, AnalysisDbServer
Dim StarSchemaDb, StarSchemaDbServer
Dim AlertsServiceName, AlertsServer
AnalysisDb = null
AnalysisDbServer = null
AlertsServiceName = null
AlertsServer = null
Do While Not objResults.EOF
if CStr(objResults(0)) = "AnalysisDatabase" then
if CStr(objResults(1)) = "DatabaseName" then
AnalysisDb = CStr(objResults(2))
else
AnalysisDbServer = CStr(objResults(2))
end if
else
if CStr(objResults(0)) = "StarSchemaDatabase" then
if CStr(objResults(1)) = "DatabaseName" then
StarSchemaDb = CStr(objResults(2))
else
StarSchemaDbServer = CStr(objResults(2))
end if
else
if CStr(objResults(0)) = "Alert" then
if CStr(objResults(1)) = "InstanceDatabaseName" then
AlertsServiceName = "NS$" &amp; CStr(objResults(2))
else
' Important: The properties 'DistributorServerName', 'GeneratorServerName'
' and 'ProviderServerName' are all same for OOB BAM alerts configuration as
' the components corresponding to these run under a single alerts service.
' There is a scale-out scenario where these components can be different but
' in that case these properties are not updated in the bam_Metadata_Properties
' table. So currently only OOB scenario will work.
if CStr(objResults(1)) = "DistributorServerName" then
AlertsServer = CStr(objResults(2))
end if
end if
end if
end if
end if
objResults.MoveNext
Loop
cnADOConnection.Close

if Not IsNull(AnalysisDb) and Not IsNull(AnalysisDbServer) then
Set oBAMAnalysis = objDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMAnalysis']$")
call oBAMAnalysis.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", ComputerName)
call oBAMAnalysis.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMRuntime']/BAMPrimaryImportDbName$", BAMDbName)
call oBAMAnalysis.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMRuntime']/BAMPrimaryImportDbServerName$", BAMDbServerName)
call oBAMAnalysis.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMAnalysis']/BAMAnalysisDbName$", AnalysisDb)
call oBAMAnalysis.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMAnalysis']/BAMAnalysisDbServerName$", AnalysisDbServer)
call oBAMAnalysis.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMAnalysis']/BAMStarSchemaDbName$", StarSchemaDb)
call oBAMAnalysis.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMAnalysis']/BAMStarSchemaDbServerName$", StarSchemaDbServer)

call objDiscoveryData.AddInstance(oBAMAnalysis)
CreateRelationShip objDiscoveryData, oBAMRuntime, oBAMAnalysis, "$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMRuntimeHostsBAMAnalysis']$"
end if

if Not IsNull(AlertsServiceName) and Not IsNull(AlertsServer) then
Set oBAMAlerts = objDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMAlerts']$")
call oBAMAlerts.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", ComputerName)
call oBAMAlerts.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMRuntime']/BAMPrimaryImportDbName$", BAMDbName)
call oBAMAlerts.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMRuntime']/BAMPrimaryImportDbServerName$", BAMDbServerName)
call oBAMAlerts.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMAlerts']/BAMAlertsServiceName$", AlertsServiceName)
call oBAMAlerts.AddProperty("$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMAlerts']/BAMAlertsServerName$", AlertsServer)

call objDiscoveryData.AddInstance(oBAMAlerts)
CreateRelationShip objDiscoveryData, oBAMRuntime, oBAMAlerts, "$MPElement[Name='Microsoft.BizTalk.Server.2016.BAMRuntimeHostsBAMAlerts']$"
end if
End Function

Function CreateRelationShip(byRef objDiscoveryData, SourceObject, TargetObject, strRelationShipClassId)
Dim objRelation
Set objRelation = objDiscoveryData.CreateRelationshipInstance(strRelationShipClassId)
objRelation.Source = SourceObject
objRelation.Target = TargetObject
objDiscoveryData.AddInstance objRelation
End Function

Function MomCreateObject(ByVal sProgramId)
Dim ObjError
Set ObjError = New Error

On Error Resume Next
Set MomCreateObject = CreateObject(sProgramId)
ObjError.Save
On Error Goto 0

If ObjError.Number &lt;&gt; 0 Then WScript.Quit
End Function

Class Error
Private m_lNumber
Private m_sSource
Private m_sDescription
Private m_sHelpContext
Private m_sHelpFile
Public Sub Save()
m_lNumber = Err.number
m_sSource = Err.Source
m_sDescription = Err.Description
m_sHelpContext = Err.HelpContext
m_sHelpFile = Err.helpfile
End Sub
Public Sub Raise()
Err.Raise m_lNumber, m_sSource, m_sDescription, m_sHelpFile, m_sHelpContext
End Sub
Public Sub Clear()
m_lNumber = 0
m_sSource = ""
m_sDescription = ""
m_sHelpContext = ""
m_sHelpFile = ""
End Sub
Public Default Property Get Number()
Number = m_lNumber
End Property
Public Property Get Source()
Source = m_sSource
End Property
Public Property Get Description()
Description = m_sDescription
End Property
Public Property Get HelpContext()
HelpContext = m_sHelpContext
End Property
Public Property Get HelpFile()
HelpFile = m_sHelpFile
End Property
End Class
</Script></ScriptBody>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DataSource"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.Discovery.Data</OutputType>
</DataSourceModuleType>