AK561862

Monitor_AK561862 (UnitMonitor)

Windows operating system missing update KB2523134 to prevent log shipping process hang.

Knowledge Base article:

External

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

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
Windows operating system missing update KB2523134 to prevent log shipping process hang.
<Details>
<Content>You are missing Windows Update KB2523134. This update prevents SqlLogShip.exe from running into hang conditions. Once SqlLogShip.exe encounters this, your log shipping configuration will encounter latency. This can result in the secondary server falling behind the primary server and can result in data loss if you need to perform immediate switch in a disaster recovery scenario using log shipping. Review the information provided and apply the windows update.</Content>
<CollectedInformation>
<Info>
<Name>Current NTOSKRNL.EXE file version</Name>
<Value>{0}</Value>
</Info>
<Info>
<Name>Recommended NTOSKRNL.EXE version</Name>
<Value>{1}</Value>
</Info>
<Info>
<Name>Number of databases configured as primary for log shipping</Name>
<Value>{2}</Value>
</Info>
<Info>
<Name>Number of databases configured as secondary for log shipping</Name>
<Value>{3}</Value>
</Info>
</CollectedInformation>
</Details>
RunAsDefault
CommentSupportTopic=TBD;VersionNumber=1.0.0.0;

Source Code:

<UnitMonitor ID="Monitor_AK561862" 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="MonitorMessage060ac91a2a834f67809370ca42bb2f73">
<AlertOnState>Error</AlertOnState>
<AutoResolve>true</AutoResolve>
<AlertPriority>Normal</AlertPriority>
<AlertSeverity>Warning</AlertSeverity>
<AlertParameters>
<AlertParameter1>$Data/Context/Property[@Name='CurrentNTOSKRNLVersion']$</AlertParameter1>
<AlertParameter2>$Data/Context/Property[@Name='RecommendedNTOSKRNLVersion']$</AlertParameter2>
<AlertParameter3>$Data/Context/Property[@Name='CountOfPrimaryDatabase']$</AlertParameter3>
<AlertParameter4>$Data/Context/Property[@Name='CountOfSecondaryDatabase']$</AlertParameter4>
</AlertParameters>
</AlertSettings>
<OperationalStates>
<OperationalState ID="Success" MonitorTypeStateID="Success" HealthState="Success"/>
<OperationalState ID="Error" MonitorTypeStateID="Error" HealthState="Error"/>
</OperationalStates>
<Configuration>
<ScriptName>AK561862.ps1</ScriptName>
<Parameters>
<Parameter>
<Name>ConnectionString</Name>
<Value>$Target/Property[Type="MicrosoftSQLServerLibrary!Microsoft.SQLServer.DBEngine"]/ConnectionString$</Value>
</Parameter>
<Parameter>
<Name>NtoskrnlVersion</Name>
<Value>$Target/Property[Type="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.DBEngine"]/NtoskrnlVersion$</Value>
</Parameter>
<Parameter>
<Name>MajorVersion</Name>
<Value>$Target/Property[Type="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.DBEngine"]/MajorVersion$</Value>
</Parameter>
<Parameter>
<Name>MinorVersion</Name>
<Value>$Target/Property[Type="KnowledgeServicesSQLServerLibrary!Microsoft.KnowledgeServices.SQLServer.DBEngine"]/MinorVersion$</Value>
</Parameter>
</Parameters>
<ScriptBody><Script>


param($ConnectionString,$NtoskrnlVersion,$MajorVersion,$MinorVersion)

$ErrorActionPreference = "Stop"

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

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

# Environment

$scriptenv = new-object psobject
$scriptenv | add-member NoteProperty "ErrorFlag" $null
$scriptenv | add-member NoteProperty "IsSQLVersionAffected" $null
$scriptenv | add-member NoteProperty "IsLogShippingConfigured" $null
$scriptenv | add-member NoteProperty "IsOSUpdateNeeded" $null

# Function to check IsSQLVersionAffected (SQL Server 2008 or SQL Server 2008 R2)
Function Check-IsSQLVersionAffected(){
# Check if the config point SQL DB Engine : Product Version is of the format 10.00 or 10.50 (from Detection Logic)
#If($scriptargs.DBEngineVersion.StartsWith("10.00") -or $scriptargs.DBEngineVersion.StartsWith("10.50")){

# Fix the bug (AK561862: Does not popup alert when condition is satisfied. )
# =&gt; Check if the SQL Server is SQL Server 2008 or SQL Server 2008 R2 (config point SQL DB Engine : Product Version is of the format 10.0 or 10.5 )
If($scriptargs.MajorVersion -eq "10" -and ($scriptargs.MinorVersion -eq "50" -or $scriptargs.MinorVersion -eq "0")){
$scriptenv.IsSQLVersionAffected = $true
}
}

# Function to check IsLogShippingConfigured
Function Check-IsLogShippingConfigured(){
# Create and Open a database connection
$RowNo = 0
$ConnectionString = "Data Source=" + $scriptargs.ConnectionString + "; Initial Catalog=master;Integrated Security=SSPI"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection($ConnectionString)
$SqlConnection.Open()

#Create a command object
$SqlCommand = $SqlConnection.CreateCommand()
$SqlCommand.CommandText = "SELECT COUNT(*) FROM msdb.dbo.log_shipping_primary_databases UNION ALL SELECT COUNT(*) FROM msdb.dbo.log_shipping_secondary_databases"
$Adapter = New-Object "System.Data.SqlClient.SqlDataAdapter" $SqlCommand
$SqlReader= $SqlCommand.ExecuteReader()
while ($SqlReader.Read()){
$RowNo++
If($RowNo -eq 1){
$scriptoutput.CountOfPrimaryDatabase = $SqlReader[0]
}
ElseIf($RowNo -eq 2){
$scriptoutput.CountOfSecondaryDatabase = $SqlReader[0]
}
}
$SqlConnection.Close()

if ($scriptoutput.CountOfPrimaryDatabase -gt 0 -or $scriptoutput.CountOfSecondaryDatabase -gt 0){
$scriptenv.IsLogShippingConfigured = $true
}
}

# Function to check IsOSUpdateNeede
Function Check-IsOSUpdateNeeded(){
# Get the current fix versions from configpoint
$scriptoutput.CurrentNTOSKRNLVersion = $scriptargs.NtoskrnlVersion
$scriptoutput.RecommendedNTOSKRNLVersion = ""

$OSInfo = (Get-WmiObject Win32_OperatingSystem)

# Get OS Version
$OSVersion = $OSInfo.Version

# Get the recommended fix versions
# SP1 based fix version: 6.0.6001.22903
# SP2 based fix version: 6.0.6002.22627
$ServicePackVersion=$OSInfo.ServicePackMajorVersion

If($ServicePackVersion -eq 1){
$scriptoutput.RecommendedNTOSKRNLVersion = "6.0.6001.22903"
}
ElseIf($ServicePackVersion -eq 2){
$scriptoutput.RecommendedNTOSKRNLVersion = "6.0.6002.22627"
}

#if (OSVersion -like 6.0) -and (NtoskrnlVersion -lt FixFileVersion)
If($OSVersion.ToString().StartsWith("6.0") -and $scriptargs.NtoskrnlVersion.CompareTo($scriptoutput.RecommendedNTOSKRNLVersion) -lt 0){
$scriptenv.IsOSUpdateNeeded = $true
}
}


# Main Function
Function AdvisorRule($scriptargs, $scriptoutput) {
trap [Exception] {
$scriptenv.ErrorFlag = $true
continue
}

# 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.

# Initialize parameters
$scriptenv.ErrorFlag = $false
$scriptenv.IsLogShippingConfigured = $false
$scriptenv.IsOSUpdateNeeded = $false
$scriptenv.IsSQLVersionAffected = $false

$scriptoutput.HasIssue = $false

# Set parameter values
Check-IsSQLVersionAffected
Check-IsLogShippingConfigured
Check-IsOSUpdateNeeded

# Detection Logic
# rule is needed for SQL Server 2008 R2 and SQL Server 2008
# check if the SQL Server has Log Shipping configured
# alert customer to apply KBA 2523134 if not installed
If($scriptenv.IsLogShippingConfigured -eq $true -and $scriptenv.IsOSUpdateNeeded -eq $true -and $scriptenv.IsSQLVersionAffected -eq $true){
If ($scriptenv.ErrorFlag -ne $true){
# Raise alert
$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)
}

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

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

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

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

$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>