Skip to content

Commit 405fc07

Browse files
authored
Merge pull request #920 from jpomfret/qs
New V5 Check - QS Enabled - Just boosting those contributions numbers...
2 parents d48db21 + 3935ac3 commit 405fc07

File tree

3 files changed

+46
-37
lines changed

3 files changed

+46
-37
lines changed

source/checks/Databasev5.Tests.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ BeforeDiscovery {
3434
$__dbcconfig = Get-DbcConfig
3535
}
3636

37-
# Each Test will have a -ForEach for the Instances and the InstancesToTest object will have a
37+
# Each Test will have a -ForEach for the Instances and the InstancesToTest object will have a
3838
# lot of information gathered up front to reduce trips and connections to the database
3939

4040

@@ -191,4 +191,14 @@ Describe "Database Status" -Tag DatabaseStatus, High, Database -ForEach $Instanc
191191
$psitem.Status | Should -Not -Match 'Suspect' -Because "We expect that there will be no databases in a Suspect state"
192192
}
193193
}
194-
}
194+
}
195+
196+
Describe "Query Store Enabled" -Tag QueryStoreEnabled, Medium, Database -ForEach $InstancesToTest {
197+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.querystoreenabled' }).Value
198+
199+
Context "Testing to see if Query Store is enabled on <_.Name>" {
200+
It "Database <_.Name> should have Query Store enabled on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.qsenabledexclude -notcontains $PsItem.Name } } {
201+
$psitem.QueryStoreEnabled | Should -Not -BeIn ('OFF', 'ERROR') -Because "We expect the Query Store to be enabled"
202+
}
203+
}
204+
}

source/internal/configurations/configuration.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Set-PSFConfig -Module dbachecks -Name policy.database.maxdop -Value 0 -Initializ
161161
Set-PSFConfig -Module dbachecks -Name policy.database.status.excludereadonly -Value @() -Initialize -Description "Database names that we expect to be readonly"
162162
Set-PSFConfig -Module dbachecks -Name policy.database.status.excludeoffline -Value @() -Initialize -Description "Database names that we expect to be offline"
163163
Set-PSFConfig -Module dbachecks -Name policy.database.status.excluderestoring -Value @() -Initialize -Description "Database names that we expect to be restoring"
164-
Set-PSFConfig -Module dbachecks -Name database.querystoreenabled.excludedb -Value @() -Initialize -Description "A List of databases that we do not want to check for Query Store enabled"
164+
Set-PSFConfig -Module dbachecks -Name database.querystoreenabled.excludedb -Value @('model', 'tempdb', 'master') -Initialize -Description "A List of databases that we do not want to check for Query Store enabled"
165165
Set-PSFConfig -Module dbachecks -Name database.querystoredisabled.excludedb -Value @() -Initialize -Description "A List of databases that we do not want to check for Query Store disabled"
166166
Set-PSFConfig -Module dbachecks -Name policy.database.filegrowthdaystocheck -Value $null -Initialize -Description "The number of days to go back to check for growth events"
167167
Set-PSFConfig -Module dbachecks -Name policy.database.trustworthyexcludedb -Value @('msdb') -Initialize -Description "A List of databases that we do not want to check for Trustworthy being on"

source/internal/functions/Get-AllDatabaseInfo.ps1

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function Get-AllDatabaseInfo {
6262

6363
'AutoShrink' {
6464
$autoshrink = $true
65-
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoshrink' -Value (Get-DbcConfigValue policy.database.autoshrink)
65+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoshrink' -Value (Get-DbcConfigValue policy.database.autoshrink)
6666
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoshrinkexclude' -Value (Get-DbcConfigValue policy.autoshrinke.excludedb)
6767
}
6868

@@ -118,49 +118,48 @@ function Get-AllDatabaseInfo {
118118
}
119119
'DatabaseStatus' {
120120
$status = $true
121-
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'excludereadonly' -Value (Get-DbcConfigValue policy.database.status.excludereadonly)
122-
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'excludeoffline' -Value (Get-DbcConfigValue policy.database.status.excludeoffline)
123-
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'excluderestoring' -Value (Get-DbcConfigValue policy.database.status.excluderestoring)
121+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'excludereadonly' -Value (Get-DbcConfigValue policy.database.status.excludereadonly)
122+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'excludeoffline' -Value (Get-DbcConfigValue policy.database.status.excludeoffline)
123+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'excluderestoring' -Value (Get-DbcConfigValue policy.database.status.excluderestoring)
124124
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'statusexclude' -Value (Get-DbcConfigValue policy.database.statusexcludedb)
125-
126125
}
127-
'SymmetricKeyEncryptionLevel' {
128-
$symmetrickey = $true
129-
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'symmetrickeyexclude' -Value (Get-DbcConfigValue policy.database.symmetrickeyencryptionlevelexcludedb)
130-
126+
'QueryStoreEnabled' {
127+
$qsenabled = $true
128+
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'qsenabledexclude' -Value (Get-DbcConfigValue database.querystoreenabled.excludedb)
131129
}
132130
Default { }
133131
}
134132

135133
#build the object
136134
$testInstanceObject = [PSCustomObject]@{
137-
ComputerName = $Instance.ComputerName
138-
InstanceName = $Instance.DbaInstanceName
139-
Name = $Instance.Name
140-
ConfigValues = $ConfigValues # can we move this out to here?
141-
Databases = $Instance.Databases.Foreach{
135+
ComputerName = $Instance.ComputerName
136+
InstanceName = $Instance.DbaInstanceName
137+
Name = $Instance.Name
138+
ConfigValues = $ConfigValues # can we move this out to here?
139+
Databases = $Instance.Databases.Foreach{
142140
[PSCustomObject]@{
143-
Name = $psitem.Name
144-
SqlInstance = $Instance.Name
145-
Owner = if ($owner) { $psitem.owner }
146-
ServerCollation = if ($collation) { $Instance.collation }
147-
Collation = if ($collation) { $psitem.collation }
148-
SuspectPage = if ($suspectPage) { (Get-DbaSuspectPage -SqlInstance $Instance -Database $psitem.Name | Measure-Object).Count }
149-
ConfigValues = $ConfigValues # can we move this out?
150-
AsymmetricKeySize = if ($asymmetrickey) { ($psitem.AsymmetricKeys | Where-Object { $_.KeyLength -lt 2048} | Measure-Object).Count }
141+
Name = $psitem.Name
142+
SqlInstance = $Instance.Name
143+
Owner = @(if ($owner) { $psitem.owner })
144+
ServerCollation = @(if ($collation) { $Instance.collation })
145+
Collation = @(if ($collation) { $psitem.collation })
146+
SuspectPage = @(if ($suspectPage) { (Get-DbaSuspectPage -SqlInstance $Instance -Database $psitem.Name | Measure-Object).Count })
147+
ConfigValues = $ConfigValues # can we move this out?
148+
AsymmetricKeySize = @(if ($asymmetrickey) { ($psitem.AsymmetricKeys | Where-Object { $_.KeyLength -lt 2048 } | Measure-Object).Count })
151149
#AsymmetricKeySize = if ($asymmetrickey) { $psitem.AsymmetricKeys.KeyLength } # doing this I got $null if there wasn't a key so counting ones that are too short
152-
AutoClose = if ($autoclose) { $psitem.AutoClose}
153-
AutoCreateStatistics = if ($autocreatestats) { $psitem.AutoCreateStatisticsEnabled }
154-
AutoUpdateStatistics = if ($autoupdatestats) { $psitem.AutoUpdateStatisticsEnabled }
155-
AutoUpdateStatisticsAsync = if ($autoupdatestatsasync) { $psitem.AutoUpdateStatisticsAsync }
156-
AutoShrink = if ($autoshrink) { $psitem.AutoShrink}
157-
VLF = if ($vlf) { ($psitem.Query("DBCC LOGINFO") | Measure-Object).Count }
158-
LogFileCount = if ($logfilecount) { ($psitem.LogFiles | Measure-Object).Count }
159-
Trustworthy = if ($trustworthy) { $psitem.Trustworthy }
160-
Status = if ($status) { $psitem.Status }
161-
IsDatabaseSnapshot = if ($status) { $psitem.IsDatabaseSnapshot } # needed for status test
162-
Readonly = if ($status) { $psitem.Readonly } # needed for status test
163-
SymmetricKey = if ($symmetrickey) { ($psitem | where IsAccessible).SymmetricKeys }
150+
AutoClose = @(if ($autoclose) { $psitem.AutoClose })
151+
AutoCreateStatistics = @(if ($autocreatestats) { $psitem.AutoCreateStatisticsEnabled })
152+
AutoUpdateStatistics = @(if ($autoupdatestats) { $psitem.AutoUpdateStatisticsEnabled })
153+
AutoUpdateStatisticsAsync = @(if ($autoupdatestatsasync) { $psitem.AutoUpdateStatisticsAsync })
154+
AutoShrink = @(if ($autoshrink) { $psitem.AutoShrink })
155+
VLF = @(if ($vlf) { ($psitem.Query("DBCC LOGINFO") | Measure-Object).Count })
156+
LogFileCount = @(if ($logfilecount) { ($psitem.LogFiles | Measure-Object).Count })
157+
Trustworthy = @(if ($trustworthy) { $psitem.Trustworthy })
158+
Status = @(if ($status) { $psitem.Status })
159+
IsDatabaseSnapshot = @(if ($status) { $psitem.IsDatabaseSnapshot }) # needed for status test
160+
Readonly = @(if ($status) { $psitem.Readonly }) # needed for status test
161+
QueryStoreEnabled = @(if ($qsenabled) { $psitem.QueryStoreOptions.ActualState })
162+
164163
}
165164
}
166165
}

0 commit comments

Comments
 (0)