Database Mirroring Partners Status

Microsoft.SQLServer.Windows.Mirroring.PartnersState.Monitor (UnitMonitor)

This monitor checks if database mirror is synchronized.

Knowledge Base article:

Summary

This monitor checks the status of the database mirroring session as reported by Microsoft® SQL Server™. This is done by running a query against the master database of the SQL Server instance and returning the state of the database mirroring session. If you receive an alert from this monitor, action is required in order to bring the database mirroring session back to an operational state.

Causes

An unhealthy state indicates that the SQL Server™ database mirroring session is not in operational state. The possible states are detailed below:

Mirroring Partners State

Description

MOM Health State

IN_SYNC

This is normal operational state. Mirroring Partners are synchronized and mirroring is performing normally.

HEALTHY

OUT_OF_SYNC

Mirroring Partners are out of sync.

CRITICAL

Resolutions

To resolve the issue try the following:

Overridable Parameters

Name

Description

Default Value

Interval (seconds)

The recurring interval of time in seconds in which to run the workflow.

900

Synchronization Time

The synchronization time specified by using a 24-hour format. May be omitted.

 

Timeout (seconds)

Specifies the time the workflow is allowed to run before being closed and marked as failed.

300

Enabled

Enables or disables the workflow.

Yes

Generates Alerts

Defines whether the workflow generates an Alert.

Yes

Alert Severity

Defines Alert Severity.

Error

Alert Priority

Defines Alert Priority.

Normal

Element properties:

TargetMicrosoft.SQLServer.Windows.Mirroring.Witness
Parent MonitorSystem.Health.AvailabilityState
CategoryAvailabilityHealth
EnabledTrue
Alert GenerateTrue
Alert SeverityError
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeMicrosoft.SQLServer.Windows.Mirroring.ScriptedTwoStateType.MonitorType
RemotableTrue
AccessibilityPublic
Alert Message
Database mirroring partners are not synchronized
Database mirror '{0}' is not synchronized. Mirroring partners are '{1}' and '{2}'.
RunAsMicrosoft.SQLServer.Core.RunAs.Monitoring

Source Code:

<UnitMonitor ID="Microsoft.SQLServer.Windows.Mirroring.PartnersState.Monitor" Accessibility="Public" Enabled="true" Target="Microsoft.SQLServer.Windows.Mirroring.Witness" ParentMonitorID="Health!System.Health.AvailabilityState" Remotable="true" Priority="Normal" RunAs="MSCL!Microsoft.SQLServer.Core.RunAs.Monitoring" TypeID="Microsoft.SQLServer.Windows.Mirroring.ScriptedTwoStateType.MonitorType" ConfirmDelivery="false">
<Category>AvailabilityHealth</Category>
<AlertSettings AlertMessage="Microsoft.SQLServer.Windows.Mirroring.PartnersState.Monitor.AlertMessage">
<AlertOnState>Error</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>Error</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Target/Property[Type="Microsoft.SQLServer.Windows.Mirroring.Witness"]/DatabaseName$</AlertParameter1>
<AlertParameter2>$Target/Property[Type="Microsoft.SQLServer.Windows.Mirroring.Witness"]/Principal$</AlertParameter2>
<AlertParameter3>$Target/Property[Type="Microsoft.SQLServer.Windows.Mirroring.Witness"]/Mirror$</AlertParameter3>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="Good" MonitorTypeStateID="Good" HealthState="Success"/>
<OperationalState ID="Bad" MonitorTypeStateID="Bad" HealthState="Error"/>
</OperationalStates>
<Configuration>
<IntervalSeconds>901</IntervalSeconds>
<SyncTime/>
<ScriptName>Microsoft.SQLServer.Windows.Mirroring.PartnersState.Monitor.vbs</ScriptName>
<ConnectionString>$Target/Host/Host/Property[Type="MSCL!Microsoft.SQLServer.Core.DBEngine"]/ConnectionString$</ConnectionString>
<MachineName>$Target/Host/Host/Property[Type="MSCL!Microsoft.SQLServer.Core.DBEngine"]/MachineName$</MachineName>
<InstanceName>$Target/Host/Host/Property[Type="MSCL!Microsoft.SQLServer.Core.DBEngine"]/InstanceName$</InstanceName>
<TcpPorts>$Target/Host/Host/Property[Type="MSWD!Microsoft.SQLServer.Windows.DBEngine"]/TcpPorts$</TcpPorts>
<Version>$Target/Host/Host/Property[Type="MSCL!Microsoft.SQLServer.Core.DBEngine"]/Version$</Version>
<ScriptBody><Script>'#Include File:Microsoft.SQLServer.Windows.Mirroring.PartnersState.Monitor.vbs
'Copyright (c) Microsoft Corporation. All rights reserved.
' This script takes a single parameter
' Param 0: The SQL connection string to connect to

Const SQL_MONITORING_CONNECT_FAILURE = -1
Const SQL_MONITORING_QUERY_FAILURE = -2
Const SQL_MONITORING_SUCCESS = 0

Const SCRIPT_EVENT_ID = 4211

Dim GetPartnersStatusQuery
GetPartnersStatusQuery = "SELECT " &amp;_
" mirroring_guid, " &amp;_
" partner_sync_state_desc " &amp;_
" FROM sys.database_mirroring_witnesses "

Call GetPartnersStatus()

'Log script event for completion
EndTime = Now
sTime = DateDiff("s", StartTime, EndTime)
Call oAPI.LogScriptEvent("Microsoft.SQLServer.Windows.Mirroring.PartnersState.Monitor.vbs", 4006, 0, "Ending script. Script runtime in seconds: " &amp; sTime)


Sub GetPartnersStatus()
If WScript.Arguments.Count = 5 Then
Dim oBag
Set oBag = oAPI.CreatePropertyBag()

Dim state, serviceName

serviceName = GetSQLServiceName(WScript.Arguments(2))
state = GetServiceState(WScript.Arguments(1), serviceName)

if (state &lt;&gt; "Running") And (state &lt;&gt; "Unknown") Then
Call oAPI.Return(oBag)
WScript.Quit()
End If

Dim nResult
nResult = PartnersStatus(WScript.Arguments(0), oBag, WScript.Arguments(1), WScript.Arguments(2), WScript.Arguments(3))
Call oAPI.Return(oBag)
Call GlobalErrorListToEventLog()
Else
Wscript.Quit()
End If
End Sub

Function PartnersStatus(ByVal sSQLConnectionString, ByRef oBag, ByVal sComputerName, ByVal sInstanceName, ByVal sTcpPort)
Dim e
Set e = New Error

Dim cnADOConnection
Set cnADOConnection = SmartConnectWithoutSQLADODB(sSQLConnectionString, sTcpPort, sComputerName, sInstanceName, "master")
if cnADOConnection Is Nothing Then
PartnersStatus = SQL_MONITORING_CONNECT_FAILURE
Exit Function
End If

Dim oResults
e.Clear
On Error Resume Next
Set oResults = cnADOConnection.Execute(GetPartnersStatusQuery)
e.Save
On Error Goto 0
If e.Number &lt;&gt; 0 Then
PartnersStatus = SQL_MONITORING_QUERY_FAILURE
ThrowScriptErrorNoAbort "Query execution failed", e
If (oResults &lt;&gt; null) Then oResults.Close
cnADOConnection.Close
Exit Function
End If

Do While Not oResults.EOF
Call oBag.AddValue(oResults(0), CStr(oResults(1)))
oResults.MoveNext
Loop

cnADOConnection.Close
PartnersStatus = SQL_MONITORING_SUCCESS
End Function
</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
<GoodExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='$Target/Property[Type="Microsoft.SQLServer.Windows.Mirroring.Witness"]/MirroringGUID$']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">IN_SYNC</Value>
</ValueExpression>
</SimpleExpression>
</GoodExpression>
<BadExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='$Target/Property[Type="Microsoft.SQLServer.Windows.Mirroring.Witness"]/MirroringGUID$']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">OUT_OF_SYNC</Value>
</ValueExpression>
</SimpleExpression>
</BadExpression>
</Configuration>
</UnitMonitor>