Skip to content

Commit

Permalink
whoisactive check added and tested #882
Browse files Browse the repository at this point in the history
  • Loading branch information
SQLDBAWithABeard committed May 16, 2022
1 parent a81ea5f commit 040f35f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Perf Testing pesterv5.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ ipmo ./dbachecks.psd1

#

$Checks = 'TraceFlagsExpected','TwoDigitYearCutoff','MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'

$Checks = 'WhoIsActiveInstalled','CLREnabled','TraceFlagsNotExpected','TraceFlagsExpected','TwoDigitYearCutoff','MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'
$Checks = 'WhoIsActiveInstalled'

<#
When there are default skips (some of the CIS checks) we need to set the configs and check
Expand Down Expand Up @@ -64,7 +64,7 @@ function Compare-CheckRuns {
param($Checks)
$password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password
$Sqlinstances = 'localhost,14333', 'localhost,14334' #'localhost,7401', 'localhost,7402', 'localhost,7403'
$Sqlinstances = 'localhost,7401', 'localhost,7402', 'localhost,7403'

$originalCode = {
Invoke-DbcCheck -SqlInstance $Sqlinstances -Check $Checks -SqlCredential $cred -legacy $true -Show None
Expand Down Expand Up @@ -101,5 +101,5 @@ Write-PSFMessage -Message $savingMessage -Level Output
}


$Checks = 'DbaOperator'
# $Checks = 'DbaOperator'
Compare-CheckRuns -Checks $checks
4 changes: 2 additions & 2 deletions Validate v4 adn v5.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ RUN THIS SECTION MANUALLY IF YOU JUST IMPORT THE FUNCTION BELOW!
ipmo ./dbachecks.psd1
$Checks = 'CLREnabled','TraceFlagsNotExpected','TraceFlagsExpected','TwoDigitYearCutoff','MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'
$Checks = 'CLREnabled'
$Checks = 'WhoIsActiveInstalled','CLREnabled','TraceFlagsNotExpected','TraceFlagsExpected','TwoDigitYearCutoff','MaxDopInstance','ErrorLogCount','ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation'
$Checks = 'WhoIsActiveInstalled'
Compare-v4andv5Results -Checks $Checks
# if you need to see the details to see why the results are different
Expand Down
9 changes: 9 additions & 0 deletions checks/Instancev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,12 @@ Describe "CLR Enabled" -Tag CLREnabled, security, CIS, High, Instance -ForEach $
}
}
}

Describe "sp_whoisactive is Installed" -Tag WhoIsActiveInstalled, Low, Instance -ForEach $InstancesToTest {
$skip = Get-DbcConfigValue skip.instance.WhoIsActiveInstalled
Context "Testing WhoIsActive exists on <_.Name>" {
It "WhoIsActive should exist on <_.ConfigValues.whoisactivedatabase> on <_.Name>" -Skip:$skip {
$Psitem.ConfigValues.WhoIsActiveInstalled | Should -Be 1 -Because "The sp_WhoIsActive stored procedure should be installed in $($psitem.ConfigValues.whoisactivedatabase)"
}
}
}
16 changes: 14 additions & 2 deletions internal/functions/NewGet-AllInstanceInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ function NewGet-AllInstanceInfo {
'TraceFlagsExpected' {
$TraceFlagsExpected = Get-DbcConfigValue policy.traceflags.expected
$TraceFlagsActual = $Instance.EnumActiveGlobalTraceFlags()
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'TraceFlagsExpected' -Value $TraceFlagsExpected
if (-not $ConfigValues.TraceFlagsExpected) {
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'TraceFlagsExpected' -Value $TraceFlagsExpected
}
$ExpectedTraceFlags = $TraceFlagsExpected.Foreach{
[PSCustomObject]@{
InstanceName = $Instance.Name
Expand All @@ -170,7 +172,7 @@ function NewGet-AllInstanceInfo {
if ($null -eq $TraceFlagsExpected) { $TraceFlagsExpected = 'none expected' }
$TraceFlagsActual = $Instance.EnumActiveGlobalTraceFlags()
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'TraceFlagsNotExpected' -Value $TraceFlagsNotExpected
if (-not $ConfigValues.ExpectedTraceFlag) {
if (-not $ConfigValues.TraceFlagsExpected) {
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'TraceFlagsExpected' -Value $TraceFlagsExpected
}
$NotExpectedTraceFlags = $TraceFlagsNotExpected.Where{ $_ -notin $TraceFlagsExpected }.Foreach{
Expand All @@ -192,6 +194,11 @@ function NewGet-AllInstanceInfo {
$configurations = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'CLREnabled' -Value (Get-DbcConfigValue policy.security.clrenabled)
}
'WhoIsActiveInstalled' {
$configurations = $true
$WhoIsActiveInstalled = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'whoisactivedatabase' -Value (Get-DbcConfigValue policy.whoisactive.database)
}
Default { }
}

Expand All @@ -218,5 +225,10 @@ function NewGet-AllInstanceInfo {
$testInstanceObject.Configuration.ScanForStartupProcedures.ConfigValue = 0
}
}
if ($WhoIsActiveInstalled) {
$whoisdatabase = Get-DbcConfigValue policy.whoisactive.database
$WhoIsActiveInstalled = $Instance.Databases[$whoisdatabase].StoredProcedures.Where{ $_.Name -eq 'sp_WhoIsActive' }.count
$testInstanceObject.ConfigValues | Add-Member -MemberType NoteProperty -Name 'WhoIsActiveInstalled' -Value $whoIsActiveInstalled
}
return $testInstanceObject
}

0 comments on commit 040f35f

Please sign in to comment.