MSSQL 2012: Server Windows Service

Microsoft.SQLServer.2012.CheckWinServiceStateMonitorType (UnitMonitorType)

Monitor type to detect the state of SQL Server Windows service.

Element properties:

RunAsMicrosoft.SQLServer.SQLProbeAccount
AccessibilityInternal
Support Monitor RecalculateFalse

Member Modules:

ID Module Type TypeId RunAs 
DS DataSource Microsoft.Windows.WmiProvider Default
CheckServiceState ProbeAction Microsoft.SQLServer.2012.VerifyWindowsServiceState Default
ServiceNotRunning ConditionDetection System.ExpressionFilter Default
ServiceRunning ConditionDetection System.ExpressionFilter Default

Overrideable Parameters:

IDParameterTypeSelectorDisplay NameDescription
Frequencyint$Config/Frequency$Interval (seconds)The recurring interval of time in seconds in which to run the workflow.
CheckStartupTypestring$Config/CheckStartupType$Alert only if service startup type is automaticThis may only be set to 'true' or 'false'. If set to 'false', then alerts will be triggered no matter what the startup type is set to. Default is 'true'.
UnavailableTimeint$Config/UnavailableTime$Unavailable Time (seconds)The minimum duration of service unavailability before considering it unhealthy.

Source Code:

<UnitMonitorType ID="Microsoft.SQLServer.2012.CheckWinServiceStateMonitorType" Accessibility="Internal" RunAs="SQL!Microsoft.SQLServer.SQLProbeAccount">
<MonitorTypeStates>
<MonitorTypeState ID="Running" NoDetection="false"/>
<MonitorTypeState ID="NotRunning" NoDetection="false"/>
</MonitorTypeStates>
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Frequency" type="xsd:integer"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ComputerName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="ServiceName" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="CheckStartupType" minOccurs="0" maxOccurs="1" type="xsd:string"/>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="UnavailableTime" type="xsd:integer"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="Frequency" Selector="$Config/Frequency$" ParameterType="int"/>
<OverrideableParameter ID="CheckStartupType" Selector="$Config/CheckStartupType$" ParameterType="string"/>
<OverrideableParameter ID="UnavailableTime" Selector="$Config/UnavailableTime$" ParameterType="int"/>
</OverrideableParameters>
<MonitorImplementation>
<MemberModules>
<DataSource ID="DS" TypeID="Windows!Microsoft.Windows.WmiProvider">
<NameSpace>\\.\Root\cimv2</NameSpace>
<Query>SELECT StartMode, State FROM Win32_Service WHERE Name = '$Config/ServiceName$'</Query>
<Frequency>$Config/Frequency$</Frequency>
</DataSource>
<ProbeAction ID="CheckServiceState" TypeID="Microsoft.SQLServer.2012.VerifyWindowsServiceState">
<ServiceName>$Config/ServiceName$</ServiceName>
<ServiceUnavailableTime>$Config/UnavailableTime$</ServiceUnavailableTime>
<CheckStartupType>$Config/CheckStartupType$</CheckStartupType>
<StartMode>$Data/Property[@Name='StartMode']$</StartMode>
<State>$Data/Property[@Name='State']$</State>
</ProbeAction>
<ConditionDetection ID="ServiceRunning" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='ServiceState']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">Running</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
<ConditionDetection ID="ServiceNotRunning" TypeID="System!System.ExpressionFilter">
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="String">Property[@Name='ServiceState']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="String">NotRunning</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</ConditionDetection>
</MemberModules>
<RegularDetections>
<RegularDetection MonitorTypeStateID="Running">
<Node ID="ServiceRunning">
<Node ID="CheckServiceState">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
<RegularDetection MonitorTypeStateID="NotRunning">
<Node ID="ServiceNotRunning">
<Node ID="CheckServiceState">
<Node ID="DS"/>
</Node>
</Node>
</RegularDetection>
</RegularDetections>
</MonitorImplementation>
</UnitMonitorType>