BizTalk Application Artifact Configuration Monitoring Module

Microsoft.BizTalk.Server.2016.Monitor.ArtifactConfiguration.DataSource (DataSourceModuleType)

This module provides data for monitoring the configuration state of various BizTalk application artifacts.

Element properties:

TypeDataSourceModuleType
IsolationAny
AccessibilityPublic
RunAsMicrosoft.BizTalk.ProbeAccount
OutputTypeSystem.PropertyBagData

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource System.CommandExecuterPropertyBagSource 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.
LogSuccessEventstring$Config/LogSuccessEvent$Log Success EventAn event is logged based on successful completion of the script associated with the module when value is set to 'true'.
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.Monitor.ArtifactConfiguration.DataSource" Accessibility="Public" RunAs="Microsoft.BizTalk.ProbeAccount" Batching="false">
<Configuration>
<xsd:element name="IntervalSeconds" type="xsd:integer"/>
<xsd:element name="TargetComputerName" type="xsd:string"/>
<xsd:element name="ArtifactHostName" type="xsd:string"/>
<xsd:element name="ArtifactType" type="xsd:string"/>
<xsd:element name="MgmtDbServerName" type="xsd:string"/>
<xsd:element name="MgmtDbName" type="xsd:string"/>
<xsd:element name="LogSuccessEvent" type="xsd:boolean"/>
<xsd:element name="TimeoutSeconds" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int"/>
<OverrideableParameter ID="LogSuccessEvent" Selector="$Config/LogSuccessEvent$" ParameterType="string"/>
<OverrideableParameter ID="TimeoutSeconds" Selector="$Config/TimeoutSeconds$" ParameterType="int"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<DataSource ID="DS" TypeID="System!System.CommandExecuterPropertyBagSource">
<IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
<ApplicationName>%windir%\system32\cscript.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>//nologo $file/BizTalkArtifactConfigurationMonitor.vbs$ "$Config/TargetComputerName$" "$Config/ArtifactHostName$" "$Config/ArtifactType$" "$Config/MgmtDbServerName$" "$Config/MgmtDbName$" "$Config/LogSuccessEvent$"</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>BizTalkArtifactConfigurationMonitor.vbs</Name>
<Contents><Script>
'Copyright (c) Microsoft Corporation. All rights reserved

'This script generates monitoring data for BizTalk application artifact configuration.
'Each artifact will be in one of the three monitoring states - success, warning, error.

Option Explicit

'Event Constants
Const EVENT_TYPE_SUCCESS = 0
Const EVENT_TYPE_ERROR = 1
Const EVENT_TYPE_WARNING = 2
Const EVENT_TYPE_INFORMATION = 4
'Other constants
Const SCRIPT_NAME = "BizTalk Server Artifact Configuration Monitor"
' Event ID Constants
Const EVENTID_SUCCESS = 99
Const EVENTID_SCRIPT_ERROR = 1000

Const ARTIFACT_CONFIGURATION_CONNECT_FAILURE = -1
Const ARTIFACT_CONFIGURATION_QUERY_FAILURE = -2

Dim oAPI, oBagState
Dim oParams, TargetComputer, ArtifactHostName, ArtifactType, MgmtDbServerName, MgmtDbName, bLogSuccessEvent
Dim strMonitorStatus, strErrorDetail
Dim strQueryToUse, strArtifactCategory
Dim strPropValueSuccess, strPropValueError, boolUseHost, boolCheckIsolatedTypes
Dim dtStart, strMessage

dtStart = Now

Set oParams = WScript.Arguments
If oParams.Count &lt; 6 then
Wscript.Quit -1
End if

Dim parameters
Dim arg
for each arg in oParams
parameters = parameters &amp; " , " &amp; arg
Next

strMonitorStatus = "0"
strErrorDetail = ""

TargetComputer = oParams(0)
ArtifactHostName = oParams(1)
ArtifactType = oParams(2)
MgmtDbServerName = oParams(3)
MgmtDbName = oParams(4)
bLogSuccessEvent = CBool(oParams(5))

Set oAPI = CreateObject("Mom.ScriptAPI")
Set oBagState = oAPI.CreatePropertyBag()

Dim defaultConnStr
defaultConnStr = "Server=" &amp; MgmtDbServerName &amp; ";Database=" &amp; MgmtDbName &amp; ";Trusted_Connection=yes"

Call GetMonitorConfig()
GetMonitorStatus

Sub GetMonitorStatus()
Call ComputeMonitorStatus()

If bLogSuccessEvent Then
CreateEvent EVENTID_SUCCESS, EVENT_TYPE_INFORMATION, strMessage
strMessage = "The script '" &amp; SCRIPT_NAME &amp; " : " &amp; strArtifactCategory &amp; "' completed successfully in " &amp; DateDiff("s", dtStart, Now) &amp; " seconds."
CreateEvent EVENTID_SUCCESS, EVENT_TYPE_INFORMATION, strMessage
End If

oAPI.AddItem oBagState
Call oAPI.ReturnItems
End Sub

Function ComputeMonitorStatus()
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
ComputeMonitorStatus = ARTIFACT_CONFIGURATION_CONNECT_FAILURE
Exit Function
End If

Dim objResults
Set objResults = cnADOConnection.Execute(strQueryToUse)
ObjError.Save
On Error Goto 0

If ObjError.Number &lt;&gt; 0 Then
' Error event to go in here
ComputeMonitorStatus = ARTIFACT_CONFIGURATION_QUERY_FAILURE
If (objResults &lt;&gt; null) Then objResults.Close
Exit Function
End If

strMessage = ""
Dim propValue, artifactName, strScope
Do While Not objResults.EOF
propValue = CStr(objResults(1))
If propValue = strPropValueSuccess Then
strMonitorStatus = "2"
strErrorDetail = ""
Else
artifactName = CStr(objResults(0))
if propValue = strPropValueError then
strMonitorStatus = "0"
If boolUseHost = true Then
strErrorDetail = "The " &amp; strArtifactCategory &amp; " " &amp; artifactName &amp; " under HostName " &amp; ArtifactHostName &amp; " is not running."
Else
strErrorDetail = "The " &amp; strArtifactCategory &amp; " " &amp; artifactName &amp; " is not running."
End If
else
strMonitorStatus = "1"
If boolUseHost = true Then
strErrorDetail = "The " &amp; strArtifactCategory &amp; " " &amp; artifactName &amp; " under HostName " &amp; ArtifactHostName &amp; " is not enlisted."
Else
strErrorDetail = "The " &amp; strArtifactCategory &amp; " " &amp; artifactName &amp; " is not enlisted."
End If
end if
End If

strScope = CStr(objResults(0))
Dim ErrorScope
Dim MonitoringStateScope
if strScope = "" then
MonitoringStateScope = "State"
ErrorScope = "ErrorDetail"
else
MonitoringStateScope = strScope &amp; "/" &amp; "State"
ErrorScope = strScope &amp; "/" &amp; "ErrorDetail"
end if

oBagState.AddValue MonitoringStateScope, strMonitorStatus
strMessage = strMessage &amp; MonitoringStateScope &amp; " " &amp; strMonitorStatus

objResults.MoveNext
Loop
cnADOConnection.Close
End Function

Function GetMonitorConfig()
Select Case ArtifactType
Case "1" 'Orchestration
strArtifactCategory = "Orchestration"
strQueryToUse = "select orc.nvcFullName+N', '+asm.nvcName+N', '+asm.nvcVersion+N', '+asm.nvcCulture+N', '+asm.nvcPublicKeyToken, nOrchestrationStatus from bts_orchestration orc with (NoLock) " &amp; _
"inner join bts_item itm with (NoLock) on orc.nItemID = itm.id " &amp; _
"inner join bts_assembly asm with (NoLock) on asm.nID = itm.AssemblyId"
strPropValueSuccess = "3"
strPropValueError = "2"
boolUseHost = false
boolCheckIsolatedTypes = false

Case "2" 'Send Port
strArtifactCategory = "Send Port"
strQueryToUse = "select nvcName, nPortStatus from bts_sendport with (NoLock)"
strPropValueSuccess = "3"
strPropValueError = "2"
boolUseHost = false
boolCheckIsolatedTypes = false

Case "3" 'Send Port Group
strArtifactCategory = "Send Port Group"
strQueryToUse = "select nvcName, nPortStatus from bts_sendportgroup with (NoLock)"
strPropValueSuccess = "3"
strPropValueError = "2"
boolUseHost = false
boolCheckIsolatedTypes = false

Case "4" 'Receive Location
strArtifactCategory = "Receive Location"
strQueryToUse = "select Name, Disabled from adm_ReceiveLocation with (NoLock)"
strPropValueSuccess = "0"
strPropValueError = "-1"
boolUseHost = false
boolCheckIsolatedTypes = false
End Select
End Function

Sub CreateEvent(lEventID, lEventType, strMessage)
oAPI.LogScriptEvent SCRIPT_NAME, lEventID, lEventType, strMessage
End Sub

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

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

If oError.Number &lt;&gt; 0 Then ThrowScriptError "Unable to create automation object '" &amp; sProgramId &amp; "'", oError
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></Contents>
<Unicode>1</Unicode>
</File>
</Files>
</DataSource>
</MemberModules>
<Composition>
<Node ID="DS"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.PropertyBagData</OutputType>
</DataSourceModuleType>