BizTalk Host Configuration Monitoring Module

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

This module provides data for monitoring the configuration state of a BizTalk host.

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.
SuccessLimitint$Config/SuccessLimit$Success LimitMonitor state is success if the number of host instances running for this host is equal to or greater than this value.
WarningLimitint$Config/WarningLimit$Warning LimitMonitor state is warning if the number of host instances is less than success limit and equal to or greater than this value. Monitor state is error if the number of host instances is less than this value.
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.HostConfiguration.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="SuccessLimit" type="xsd:integer"/>
<xsd:element name="WarningLimit" type="xsd:integer"/>
<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="SuccessLimit" Selector="$Config/SuccessLimit$" ParameterType="int"/>
<OverrideableParameter ID="WarningLimit" Selector="$Config/WarningLimit$" 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/BizTalkHostConfigurationMonitor.vbs$ "$Config/TargetComputerName$" "$Config/SuccessLimit$" "$Config/WarningLimit$" "$Config/LogSuccessEvent$"</CommandLine>
<TimeoutSeconds>$Config/TimeoutSeconds$</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>BizTalkHostConfigurationMonitor.vbs</Name>
<Contents><Script>
'Copyright (c) Microsoft Corporation. All rights reserved

'This script generates monitoring data for BizTalk host based on the availability
'of all its host instances (BTSNTSvc.exe). States can be success (running &gt;= success limit),
'warning (running &gt;= warning limit and running &lt; success limit) and error (for everything
'else).

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 Host Configuration Monitor"
' Event ID Constants
Const EVENTID_SUCCESS = 99
Const EVENTID_SCRIPT_ERROR = 1000

Dim oAPI, oBagState
Dim oParams, TargetComputer, SuccessLimit, WarningLimit, bLogSuccessEvent
Dim strMonitorStatus, strErrorDetail
Dim strNamespaceToUse, strQueryToUse
Dim strPropNameToCheck, strPropValueSuccess
Dim dtStart, strMessage

dtStart = Now

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

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

strNamespaceToUse = "\ROOT\MicrosoftBizTalkServer"
strQueryToUse = "select * from MSBTS_HostInstance where ClusterInstanceType != 3"
strMonitorStatus = "0"
strErrorDetail = ""

TargetComputer = oParams(0)
SuccessLimit = CInt(oParams(1))
WarningLimit = CInt(oParams(2))
bLogSuccessEvent = CBool(oParams(3))

'warning limit should always be &lt;= success limit
if WarningLimit &gt; SuccessLimit then
Wscript.Quit -1
End if

Set oAPI = CreateObject("Mom.ScriptAPI")
Set oBagState = oAPI.CreatePropertyBag()
Dim HostInstanceCount
Set HostInstanceCount = CreateObject("Scripting.Dictionary")
Dim HostInstanceRunningCount
Set HostInstanceRunningCount = CreateObject("Scripting.Dictionary")

GetMonitorStatus

Sub GetMonitorStatus()
Dim objInst, objInstSet, name, hosttype, status, successState
Set objInstSet = GetWMICollection(TargetComputer, strNamespaceToUse, strQueryToUse)

If objInstSet.Count &gt; 0 then
For Each objInst in objInstSet
name = CStr(objInst.Properties_("HostName").value)
status = CStr(objInst.Properties_("ServiceState").value)
hosttype = CStr(objInst.Properties_("HostType").value)
if hosttype = "1" then
successState = "4"
else
successState = "8"
end if

if not (HostInstanceCount.Exists(name)) then
HostInstanceCount.Add name, 1
else
HostInstanceCount.Item(name) = HostInstanceCount.Item(name) + 1
end if

if status = successState then
if not (HostInstanceRunningCount.Exists(name)) then
HostInstanceRunningCount.Add name, 1
else
HostInstanceRunningCount.Item(name) = HostInstanceRunningCount.Item(name) + 1
end if
end if
Next
End If

Dim key, count, runningCount
for each key in HostInstanceCount.Keys
SuccessLimit = CInt(oParams(1))
WarningLimit = CInt(oParams(2))
count = CInt(HostInstanceCount.Item(key))
if SuccessLimit &gt; count then
SuccessLimit = count
end if
if WarningLimit &gt; count then
WarningLimit = count
end if
if not (HostInstanceRunningCount.Exists(key)) then
runningCount = 0
else
runningCount = CInt(HostInstanceRunningCount.Item(key))
end if

if runningCount &gt;= SuccessLimit then
oBagState.AddValue key &amp; "/State", 2
else
if runningCount &gt;= WarningLimit then
oBagState.AddValue key &amp; "/State", 1
else
oBagState.AddValue key &amp; "/State", 0
end if
end if
next

If bLogSuccessEvent Then
strMessage = "The script '" &amp; SCRIPT_NAME &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

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

Function GetWMICollection(TargetComputerToUse, strNamespace, strQuery)
Dim WbemSrv, WbemObjectSet
Set WbemSrv = Getobject("winmgmts:{impersonationLevel=impersonate}!\\" &amp; TargetComputerToUse &amp; strNamespace)
Set WbemObjectSet = WbemSrv.ExecQuery(strQuery)
Set GetWMICollection = WbemObjectSet
End Function

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>