AK588978

Monitor_AK588978 (UnitMonitor)

SQL Server system health extended event session has incorrect event specification

Knowledge Base article:

External

http://go.microsoft.com/fwlink/?LinkId=247349

Element properties:

TargetMicrosoft.KnowledgeServices.SQLServer.DBEngine
Parent MonitorSystem.Health.ConfigurationState
CategoryAlert
EnabledTrue
Alert GenerateTrue
Alert SeverityWarning
Alert PriorityNormal
Alert Auto ResolveTrue
Monitor TypeMicrosoft.KnowledgeServices.Library.PowerShellMonitorEx
RemotableTrue
AccessibilityPublic
Alert Message
SQL Server system health extended event session has incorrect event specification
<Details>
<Content>Every SQL Server instance has a default extended event session created with the name system_health. This session captures information about the wait_info and wait_info_external events. The current definition of the system_health session contains incorrect map_key specified for the wait_types of interest. Use the information from the knowledge base article to correct the extended event session definition.</Content>
<CollectedInformation />
</Details>
RunAsDefault
CommentSupportTopic=TBD;VersionNumber=1.0.0.0;

Source Code:

<UnitMonitor ID="Monitor_AK588978" Comment="SupportTopic=TBD;VersionNumber=1.0.0.0;" Accessibility="Public" Enabled="true" Target="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.DBEngine" ParentMonitorID="Health!System.Health.ConfigurationState" Remotable="true" Priority="Normal" TypeID="KnowledgeServicesLibrary!Microsoft.KnowledgeServices.Library.PowerShellMonitorEx" ConfirmDelivery="true">
<Category>Alert</Category>
<AlertSettings AlertMessage="MonitorMessage7bbfe1e4e1bd4f538d9ba39be0a72131">
<AlertOnState>Error</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>Warning</AlertSeverity>
</AlertSettings>
<OperationalStates>
<OperationalState ID="Success" MonitorTypeStateID="Success" HealthState="Success"/>
<OperationalState ID="Error" MonitorTypeStateID="Error" HealthState="Error"/>
</OperationalStates>
<Configuration>
<ScriptName>AK588978.ps1</ScriptName>
<Parameters>
<Parameter>
<Name>ConnectionString</Name>
<Value>$Target/Property[Type="MicrosoftSQLServerLibrary!Microsoft.SQLServer.DBEngine"]/ConnectionString$</Value>
</Parameter>
<Parameter>
<Name>CurrentSQLServerBuildInput</Name>
<Value>$Target/Property[Type="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.DBEngine"]/ProductVersion$</Value>
</Parameter>
</Parameters>
<ScriptBody><Script>


param($ConnectionString,$CurrentSQLServerBuildInput)

$ErrorActionPreference = "Stop"

# Set up the arguments
$scriptargs = new-object psobject
$scriptargs | add-member NoteProperty "ConnectionString" $ConnectionString
$scriptargs | add-member NoteProperty "CurrentSQLServerBuildInput" $CurrentSQLServerBuildInput

# Set up the output
$global:scriptoutput = new-object psobject
$scriptoutput | add-member NoteProperty "HasIssue" $false
#-----------------------------------------------------
# MAIN CODE SECTION
#-----------------------------------------------------

# Environment

$scriptenv = New-Object psobject
$scriptenv | Add-Member NoteProperty "RuntimeError" $false
$scriptenv | Add-Member NoteProperty "IncorrectMapKeysEnv" $false
$scriptenv | Add-Member NoteProperty "CurrentSQLServerBuildEnv" ""


function CheckIfSystemHealthHasIncorrectMapKeys()
{
#CheckIfSystemHealthHasIncorrectMapKeys = "SELECT COUNT(*) FROM sys.server_event_session_events ese JOIN sys.server_event_sessions se ON se.event_session_id = ese.event_session_id WHERE se.name = N'system_health' AND ese.name = N'wait_info' AND ese.predicate LIKE N'%wait_type]=(107)%' AND ese.predicate LIKE N'%wait_type]=(113)%'"
#return IncorrectMapKeysEnv

# Create SqlConnection object and define connection string
$oConnection = New-Object System.Data.SqlClient.SqlConnection
$oConnection.ConnectionString = "Server=" + $scriptargs.ConnectionString + ";" + "Database=master;Integrated Security=true"
$oConnection.Open()

# Create SqlCommand object, define command text, and set the connection
$oSQLCommand = New-Object System.Data.SqlClient.SqlCommand
$oSQLCommand.CommandText = "SELECT COUNT(*) FROM sys.server_event_session_events ese JOIN sys.server_event_sessions se ON se.event_session_id = ese.event_session_id WHERE se.name = N'system_health' AND ese.name = N'wait_info' AND ese.predicate LIKE N'%wait_type]=(107)%' AND ese.predicate LIKE N'%wait_type]=(113)%'"
$oSQLCommand.Connection = $oConnection

# Execute Command
$result = $oSQLCommand.ExecuteScalar()

if($result -eq 1)
{
$scriptenv.IncorrectMapKeysEnv = $true
}

# Close SqlConnection object
$oConnection.Close()
}


# Main function

function AdvisorRule($scriptargs, $scriptoutput)
{
# All parameters should be populated outside of the main function.
# The mian function should only include the detection logic so that it can be easyly reused by the Atlanta authoring tool.

trap [Exception] {
$scriptenv.RuntimeError = $true
continue;
}
# Initialize parameters
$scriptoutput.HasIssue = $false

# Set parameter values
CheckIfSystemHealthHasIncorrectMapKeys
$scriptenv.CurrentSQLServerBuildEnv = $scriptargs.CurrentSQLServerBuildInput

if($scriptenv.RuntimeError -eq $false)
{
if(([version]$scriptenv.CurrentSQLServerBuildEnv).Major -eq 11)
{
if($scriptenv.IncorrectMapKeysEnv -eq $true)
{
$scriptoutput.HasIssue = $true
}
}
}
}
AdvisorRule $scriptargs $scriptoutput

# set the output
$mom = new-object -comobject "MOM.ScriptAPI"
$bag = $mom.CreatePropertyBag()

if ($scriptoutput.HasIssue -ne $null)
{
$bag.AddValue("HasIssue", $scriptoutput.HasIssue)
}

$bag

</Script></ScriptBody>
<SnapIns/>
<TimeoutSeconds>300</TimeoutSeconds>
<Schedule>86397</Schedule>
<ErrorExpression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='HasIssue']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</ErrorExpression>
<SuccessExpression>
<Not>
<Expression>
<SimpleExpression>
<ValueExpression>
<XPathQuery Type="Boolean">Property[@Name='HasIssue']</XPathQuery>
</ValueExpression>
<Operator>Equal</Operator>
<ValueExpression>
<Value Type="Boolean">true</Value>
</ValueExpression>
</SimpleExpression>
</Expression>
</Not>
</SuccessExpression>
</Configuration>
</UnitMonitor>