Skip to content

Commit

Permalink
lets add some xesssions running checks #882
Browse files Browse the repository at this point in the history
  • Loading branch information
SQLDBAWithABeard committed Jun 30, 2022
1 parent e3fd63c commit b632323
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
8 changes: 8 additions & 0 deletions checks/Instancev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions developing/Robs-Instance.ps1
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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
$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
28 changes: 24 additions & 4 deletions internal/functions/NewGet-AllInstanceInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ function NewGet-AllInstanceInfo {
}
}
'XESessionExists' {
Write-Host "IAM HERE"
if (-not $xeSessions) {
$xeSessions = Get-DbaXESession -SqlInstance $Instance
}
Expand All @@ -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 { }
}
Expand All @@ -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]@{
Expand All @@ -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) {
Expand Down

0 comments on commit b632323

Please sign in to comment.