diff --git a/checks/Instancev5.Tests.ps1 b/checks/Instancev5.Tests.ps1 index 6f89a447..608534cc 100644 --- a/checks/Instancev5.Tests.ps1 +++ b/checks/Instancev5.Tests.ps1 @@ -286,6 +286,14 @@ Describe "XE Sessions that should Exist" -Tag XESessionExists, ExtendedEvent, Me } } } +Describe "XE Sessions that should be running" -Tag XESessionRunning, ExtendedEvent, Medium, Instance -ForEach $InstancesToTest { + $skip = Get-DbcConfigValue skip.instance.XESessionRunning + Context "Checking sessions on <_.Name>" { + It "Session <_.SessionName> should be running on <_.Name>" -Skip:$skip -ForEach $PsItem.XeSessions.RequiredRunning { + $psitem.SessionName | Should -BeIn $PsItem.Running -Because "$($psitem.SessionName) session should be running on $($PsItem.Name)" + } + } +} <# Describe "XE Sessions That should be Running" -Tags XESessionRunning, ExtendedEvent, Medium, $filename { diff --git a/developing/Robs-Instance.ps1 b/developing/Robs-Instance.ps1 index 7851a444..002eded0 100644 --- a/developing/Robs-Instance.ps1 +++ b/developing/Robs-Instance.ps1 @@ -1,5 +1,6 @@ $Checks = 'XESessionExists','XESessionStopped','XpCmdShellDisabled','WhoIsActiveInstalled','CLREnabled','TraceFlagsNotExpected','TraceFlagsExpected','TwoDigitYearCutoff','MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation' -$Checks = 'XESessionExists' +$Checks = 'XESessionRunning' +$Checks = 'RemoteAccessDisabled' Invoke-PerfAndValidateCheck -Checks $Checks @@ -9,4 +10,8 @@ $show = 'All' $v4code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $true -Show $show -PassThru # Run v5 checks -$v5code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false -Show $show -PassThru # -Verbose \ No newline at end of file +$v5code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false -Show $show -PassThru -Verbose + +Set-DbcConfig -Name policy.xevent.requiredrunningsession -Value system_health +Set-DbcConfig -Name policy.xevent.requiredrunningsession -Value system_health ,AlwaysOn_health +Set-DbcConfig -Name policy.xevent.requiredrunningsession -Value system_health ,AlwaysOn_health,QuickSessionStandard \ No newline at end of file diff --git a/internal/functions/NewGet-AllInstanceInfo.ps1 b/internal/functions/NewGet-AllInstanceInfo.ps1 index 5ba231fd..abc62c79 100644 --- a/internal/functions/NewGet-AllInstanceInfo.ps1 +++ b/internal/functions/NewGet-AllInstanceInfo.ps1 @@ -219,7 +219,6 @@ function NewGet-AllInstanceInfo { } } 'XESessionExists' { - Write-Host "IAM HERE" if (-not $xeSessions) { $xeSessions = Get-DbaXESession -SqlInstance $Instance } @@ -232,6 +231,20 @@ function NewGet-AllInstanceInfo { $Sessions = $xeSessions.Name } } + 'XESessionRunning' { + + if (-not $xeSessions) { + $xeSessions = Get-DbaXESession -SqlInstance $Instance + } + $RequiredRunning = (Get-DbcConfigValue policy.xevent.requiredrunningsession) + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'requiredrunningsession' -Value $RequiredRunning + if (-not $RunningSessions) { + $RunningSessions = $xeSessions.Where{ $_.Status -eq 'Running' }.Name + } + if (-not $Sessions) { + $Sessions = $xeSessions.Name + } + } Default { } } @@ -249,7 +262,7 @@ function NewGet-AllInstanceInfo { Logins = $Instance.Logins Databases = $Instance.Databases NumberOfLogFiles = $Instance.NumberOfLogFiles - MaxDopSettings = $MaxDopSettings + MaxDopSettings = $MaxDopSettings ExpectedTraceFlags = $ExpectedTraceFlags NotExpectedTraceFlags = $NotExpectedTraceFlags XESessions = [pscustomobject]@{ @@ -260,17 +273,24 @@ function NewGet-AllInstanceInfo { Running = $RunningSessions } } - RequiredExists = $RequiredExists.ForEach{ + RequiredExists = $RequiredExists.ForEach{ [pscustomobject]@{ Name = $Instance.Name SessionName = $PSItem Sessions = $Sessions } } + RequiredRunning = $RequiredRunning.ForEach{ + [pscustomobject]@{ + Name = $Instance.Name + SessionName = $PSItem + Sessions = $Sessions + Running = $RunningSessions + } + } Name = $Instance.Name Sessions = $Sessions Running = $RunningSessions - } } if ($ScanForStartupProceduresDisabled) {