Skip to content

Commit

Permalink
Merge branch 'main' into agentV5
Browse files Browse the repository at this point in the history
  • Loading branch information
jpomfret authored Aug 28, 2023
2 parents 6d39640 + ccb5813 commit e80b9b7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Pester v5 support for agent checks.

## [3.0.1-preview0025] - 2023-08-28

### Added

- PageVerify check converted to V5 functionality.

### Changed

- For changes in existing functionality.
Expand Down
30 changes: 30 additions & 0 deletions source/checks/Databasev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ Describe "Contained Database Auto Close" -Tag ContainedDBAutoClose, CIS, Databas
Describe "Contained Database SQL Authenticated Users" -Tag ContainedDBSQLAuth, CIS, Database -ForEach $InstancesToTest {
$Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.security.ContainedDBSQLAuth').Value

#TODO: something with this?
#if ($version -lt 13 ) { $skip = $true }

Context "Testing contained database to see if sql authenticated users exist on <_.Name>" {
Expand All @@ -274,3 +275,32 @@ Describe "Contained Database SQL Authenticated Users" -Tag ContainedDBSQLAuth, C
}
}
}

Describe "Page Verify" -Tag PageVerify, Medium, Database -ForEach $InstancesToTest {
$Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.database.pageverify').Value
Context "Testing page verify on <_.Name>" {

# handle differently depending on major version - not available at all in SQL 2000. 2005 not available on tempdb.
if($psitem.MajorVersion -eq 8) {
It "Database Page verify is not available on SQL 2000 on <_.SqlInstance>" {
$true | Should -BeTrue
}
} elseif ($psitem.MajorVersion -eq 9) {
It "Database <_.Name> should have page verify set to <_.ConfigValues.pageverify> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.pageverifyexclude -notcontains $psitem.Name } } {
if($psitem.Name -ne 'tempdb') {
$psitem.PageVerify | Should -Be $psitem.ConfigValues.PageVerify -Because "Page verify helps SQL Server to detect corruption"
} else {
$true | Should -BeTrue
}
}
} else {
It "Database <_.Name> should have page verify set to <_.ConfigValues.pageverify> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.pageverifyexclude -notcontains $psitem.Name -and $_.Name -ne 'tempdb'} } {
$psitem.PageVerify | Should -Be $psitem.ConfigValues.PageVerify -Because "Page verify helps SQL Server to detect corruption."
}
#tempdb handled like v4
It "Database Page verify is not available on tempdb on SQL 2005 on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ $_.Name -eq 'tempdb' } {
$psitem.PageVerify | Should -Be $psitem.ConfigValues.PageVerify -Because "Page verify helps SQL Server to detect corruption."
}
}
}
}
2 changes: 2 additions & 0 deletions source/internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Set-PSFConfig -Module dbachecks -Name policy.cluster.registerallprovidersIP -Val
Set-PSFConfig -Module dbachecks -Name policy.dump.maxcount -Value 1 -Initialize -Description "Maximum number of expected dumps"

#pageverify
#TODO: Only 2 part name - should we fix this?
Set-PSFConfig -Module dbachecks -Name policy.pageverify -Value "Checksum" -Initialize -Description "Page verify option should be set to this value"

# InstanceMaxDop
Expand Down Expand Up @@ -340,6 +341,7 @@ Set-PSFConfig -Module dbachecks -Name skip.database.status -Validation bool -Val
Set-PSFConfig -Module dbachecks -Name skip.database.compatibilitylevel -Validation bool -Value $false -Initialize -Description "Skip the database compatibility test"
Set-PSFConfig -Module dbachecks -Name skip.database.recoverymodel -Validation bool -Value $false -Initialize -Description "Skip the database recovery model test"
Set-PSFConfig -Module dbachecks -Name skip.database.pseudosimple -Validation bool -Value $false -Initialize -Description "Skip the database PseudoSimple recovery model test"
Set-PSFConfig -Module dbachecks -Name skip.database.pageverify -Validation bool -Value $false -Initialize -Description "Skip the database page verify test"

Set-PSFConfig -Module dbachecks -Name skip.logshiptesting -Validation bool -Value $false -Initialize -Description "Skip the logshipping test"

Expand Down
11 changes: 9 additions & 2 deletions source/internal/functions/Get-AllDatabaseInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,15 @@ function Get-AllDatabaseInfo {
$containedDbAutoClose = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'contdbautocloseexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'policy.database.contdbautocloseexclude').Value
}
'ContainedDBSQLAuth'{
'ContainedDBSQLAuth' {
$containedDbSqlAuthUsers = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'contdbsqlauthexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'policy.database.contdbsqlauthexclude').Value
}
'PageVerify' {
$pageverify = $true
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'pageverifyexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'policy.database.contdbsqlauthexclude').Value
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'pageverify' -Value ($__dbcconfig | Where-Object Name -EQ 'policy.pageverify').Value
}
Default { }
}

Expand All @@ -165,6 +170,7 @@ function Get-AllDatabaseInfo {
InstanceName = $Instance.DbaInstanceName
Name = $Instance.Name
ConfigValues = $ConfigValues
MajorVersion = $Instance.VersionMajor
Databases = $Instance.Databases.Foreach{
[PSCustomObject]@{
Name = $psitem.Name
Expand Down Expand Up @@ -194,7 +200,8 @@ function Get-AllDatabaseInfo {
PseudoSimple = @(if ($pseudoSimple) { '' -eq (($psitem.Query('Select last_log_backup_lsn from sys.database_recovery_status where database_id = DB_ID()')).last_log_backup_lsn) })
ContainmentType = @(if ($containedDbAutoClose -or $containedDbSqlAuthUsers) { $psitem.ContainmentType })
ContainedDbAutoClose = @(if ($containedDbAutoClose) { if (($psItem.ContainmentType -ne "NONE") -and ($null -ne $psItem.ContainmentType) -and $psitem.AutoClose) { $true } else { $false } } )
ContainedDbSqlAuthUsers = @(if ($containedDbSqlAuthUsers) { if ($psItem.ContainmentType -ne "NONE" -and ($null -ne $psItem.ContainmentType)) { ($psitem.Users | Where-Object {$_.LoginType -eq "SqlLogin" -and $_.HasDbAccess -eq $true } | Measure-Object ).Count}} )
ContainedDbSqlAuthUsers = @(if ($containedDbSqlAuthUsers) { if ($psItem.ContainmentType -ne "NONE" -and ($null -ne $psItem.ContainmentType)) { ($psitem.Users | Where-Object { $_.LoginType -eq "SqlLogin" -and $_.HasDbAccess -eq $true } | Measure-Object ).Count } } )
PageVerify = @(if ($pageverify) { $psitem.PageVerify })
}
}
}
Expand Down

0 comments on commit e80b9b7

Please sign in to comment.