Skip to content

Commit

Permalink
Merge pull request #920 from jpomfret/qs
Browse files Browse the repository at this point in the history
New V5 Check - QS Enabled - Just boosting those contributions numbers...
  • Loading branch information
jpomfret authored Feb 18, 2023
2 parents d48db21 + 3935ac3 commit 405fc07
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 37 deletions.
14 changes: 12 additions & 2 deletions source/checks/Databasev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ BeforeDiscovery {
$__dbcconfig = Get-DbcConfig
}

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


Expand Down Expand Up @@ -191,4 +191,14 @@ Describe "Database Status" -Tag DatabaseStatus, High, Database -ForEach $Instanc
$psitem.Status | Should -Not -Match 'Suspect' -Because "We expect that there will be no databases in a Suspect state"
}
}
}
}

Describe "Query Store Enabled" -Tag QueryStoreEnabled, Medium, Database -ForEach $InstancesToTest {
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.security.querystoreenabled' }).Value

Context "Testing to see if Query Store is enabled on <_.Name>" {
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 } } {
$psitem.QueryStoreEnabled | Should -Not -BeIn ('OFF', 'ERROR') -Because "We expect the Query Store to be enabled"
}
}
}
2 changes: 1 addition & 1 deletion source/internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Set-PSFConfig -Module dbachecks -Name policy.database.maxdop -Value 0 -Initializ
Set-PSFConfig -Module dbachecks -Name policy.database.status.excludereadonly -Value @() -Initialize -Description "Database names that we expect to be readonly"
Set-PSFConfig -Module dbachecks -Name policy.database.status.excludeoffline -Value @() -Initialize -Description "Database names that we expect to be offline"
Set-PSFConfig -Module dbachecks -Name policy.database.status.excluderestoring -Value @() -Initialize -Description "Database names that we expect to be restoring"
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"
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"
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"
Set-PSFConfig -Module dbachecks -Name policy.database.filegrowthdaystocheck -Value $null -Initialize -Description "The number of days to go back to check for growth events"
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"
Expand Down
67 changes: 33 additions & 34 deletions source/internal/functions/Get-AllDatabaseInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function Get-AllDatabaseInfo {

'AutoShrink' {
$autoshrink = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoshrink' -Value (Get-DbcConfigValue policy.database.autoshrink)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoshrink' -Value (Get-DbcConfigValue policy.database.autoshrink)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'autoshrinkexclude' -Value (Get-DbcConfigValue policy.autoshrinke.excludedb)
}

Expand Down Expand Up @@ -118,49 +118,48 @@ function Get-AllDatabaseInfo {
}
'DatabaseStatus' {
$status = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'excludereadonly' -Value (Get-DbcConfigValue policy.database.status.excludereadonly)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'excludeoffline' -Value (Get-DbcConfigValue policy.database.status.excludeoffline)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'excluderestoring' -Value (Get-DbcConfigValue policy.database.status.excluderestoring)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'excludereadonly' -Value (Get-DbcConfigValue policy.database.status.excludereadonly)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'excludeoffline' -Value (Get-DbcConfigValue policy.database.status.excludeoffline)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'excluderestoring' -Value (Get-DbcConfigValue policy.database.status.excluderestoring)
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'statusexclude' -Value (Get-DbcConfigValue policy.database.statusexcludedb)

}
'SymmetricKeyEncryptionLevel' {
$symmetrickey = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'symmetrickeyexclude' -Value (Get-DbcConfigValue policy.database.symmetrickeyencryptionlevelexcludedb)

'QueryStoreEnabled' {
$qsenabled = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'qsenabledexclude' -Value (Get-DbcConfigValue database.querystoreenabled.excludedb)
}
Default { }
}

#build the object
$testInstanceObject = [PSCustomObject]@{
ComputerName = $Instance.ComputerName
InstanceName = $Instance.DbaInstanceName
Name = $Instance.Name
ConfigValues = $ConfigValues # can we move this out to here?
Databases = $Instance.Databases.Foreach{
ComputerName = $Instance.ComputerName
InstanceName = $Instance.DbaInstanceName
Name = $Instance.Name
ConfigValues = $ConfigValues # can we move this out to here?
Databases = $Instance.Databases.Foreach{
[PSCustomObject]@{
Name = $psitem.Name
SqlInstance = $Instance.Name
Owner = if ($owner) { $psitem.owner }
ServerCollation = if ($collation) { $Instance.collation }
Collation = if ($collation) { $psitem.collation }
SuspectPage = if ($suspectPage) { (Get-DbaSuspectPage -SqlInstance $Instance -Database $psitem.Name | Measure-Object).Count }
ConfigValues = $ConfigValues # can we move this out?
AsymmetricKeySize = if ($asymmetrickey) { ($psitem.AsymmetricKeys | Where-Object { $_.KeyLength -lt 2048} | Measure-Object).Count }
Name = $psitem.Name
SqlInstance = $Instance.Name
Owner = @(if ($owner) { $psitem.owner })
ServerCollation = @(if ($collation) { $Instance.collation })
Collation = @(if ($collation) { $psitem.collation })
SuspectPage = @(if ($suspectPage) { (Get-DbaSuspectPage -SqlInstance $Instance -Database $psitem.Name | Measure-Object).Count })
ConfigValues = $ConfigValues # can we move this out?
AsymmetricKeySize = @(if ($asymmetrickey) { ($psitem.AsymmetricKeys | Where-Object { $_.KeyLength -lt 2048 } | Measure-Object).Count })
#AsymmetricKeySize = if ($asymmetrickey) { $psitem.AsymmetricKeys.KeyLength } # doing this I got $null if there wasn't a key so counting ones that are too short
AutoClose = if ($autoclose) { $psitem.AutoClose}
AutoCreateStatistics = if ($autocreatestats) { $psitem.AutoCreateStatisticsEnabled }
AutoUpdateStatistics = if ($autoupdatestats) { $psitem.AutoUpdateStatisticsEnabled }
AutoUpdateStatisticsAsync = if ($autoupdatestatsasync) { $psitem.AutoUpdateStatisticsAsync }
AutoShrink = if ($autoshrink) { $psitem.AutoShrink}
VLF = if ($vlf) { ($psitem.Query("DBCC LOGINFO") | Measure-Object).Count }
LogFileCount = if ($logfilecount) { ($psitem.LogFiles | Measure-Object).Count }
Trustworthy = if ($trustworthy) { $psitem.Trustworthy }
Status = if ($status) { $psitem.Status }
IsDatabaseSnapshot = if ($status) { $psitem.IsDatabaseSnapshot } # needed for status test
Readonly = if ($status) { $psitem.Readonly } # needed for status test
SymmetricKey = if ($symmetrickey) { ($psitem | where IsAccessible).SymmetricKeys }
AutoClose = @(if ($autoclose) { $psitem.AutoClose })
AutoCreateStatistics = @(if ($autocreatestats) { $psitem.AutoCreateStatisticsEnabled })
AutoUpdateStatistics = @(if ($autoupdatestats) { $psitem.AutoUpdateStatisticsEnabled })
AutoUpdateStatisticsAsync = @(if ($autoupdatestatsasync) { $psitem.AutoUpdateStatisticsAsync })
AutoShrink = @(if ($autoshrink) { $psitem.AutoShrink })
VLF = @(if ($vlf) { ($psitem.Query("DBCC LOGINFO") | Measure-Object).Count })
LogFileCount = @(if ($logfilecount) { ($psitem.LogFiles | Measure-Object).Count })
Trustworthy = @(if ($trustworthy) { $psitem.Trustworthy })
Status = @(if ($status) { $psitem.Status })
IsDatabaseSnapshot = @(if ($status) { $psitem.IsDatabaseSnapshot }) # needed for status test
Readonly = @(if ($status) { $psitem.Readonly }) # needed for status test
QueryStoreEnabled = @(if ($qsenabled) { $psitem.QueryStoreOptions.ActualState })

}
}
}
Expand Down

0 comments on commit 405fc07

Please sign in to comment.