Skip to content

Commit

Permalink
so that the old checks will match the new ones!! #882
Browse files Browse the repository at this point in the history
  • Loading branch information
SQLDBAWithABeard committed Apr 28, 2022
1 parent d24918a commit 89bb3de
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 36 deletions.
53 changes: 32 additions & 21 deletions checks/Instance.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -541,29 +541,29 @@ $Tags = Get-CheckInformation -Check $Check -Group Instance -AllChecks $AllChecks
Describe "XE Sessions That Are Allowed to Be Running" -Tags XESessionRunningAllowed, ExtendedEvent, Medium, $filename {
$xesession = Get-DbcConfigValue policy.xevent.validrunningsession
if ((Get-Version -SQLInstance $psitem) -gt 10) {
# no point running if we dont have something to check
if ($xesession) {
if ($NotContactable -contains $psitem) {
Context "Checking running sessions allowed on $psitem" {
It "Can't Connect to $Psitem" {
$true | Should -BeFalse -Because "The instance should be available to be connected to!"
# no point running if we dont have something to check
if ($xesession) {
if ($NotContactable -contains $psitem) {
Context "Checking running sessions allowed on $psitem" {
It "Can't Connect to $Psitem" {
$true | Should -BeFalse -Because "The instance should be available to be connected to!"
}
}
}
}
else {
Context "Checking running sessions allowed on $psitem" {
@(Get-DbaXESession -SqlInstance $psitem).Where{ $_.Status -eq 'Running' }.ForEach{
It "Session $($Psitem.Name) is allowed to be running on $Instance" {
$psitem.name | Should -BeIn $xesession -Because "Only these sessions are allowed to be running"
else {
Context "Checking running sessions allowed on $psitem" {
@(Get-DbaXESession -SqlInstance $psitem).Where{ $_.Status -eq 'Running' }.ForEach{
It "Session $($Psitem.Name) is allowed to be running on $Instance" {
$psitem.name | Should -BeIn $xesession -Because "Only these sessions are allowed to be running"
}
}
}
}
}
else {
Write-Warning "You need to use Set-DbcConfig -Name policy.xevent.validrunningsession -Value to add some Extended Events session names to run this check"
}
}
else {
Write-Warning "You need to use Set-DbcConfig -Name policy.xevent.validrunningsession -Value to add some Extended Events session names to run this check"
}
}
else {
Context "Checking running sessions allowed on $psitem" {
It "Version does not support XE sessions on $Instance" -skip {
Expand Down Expand Up @@ -788,9 +788,20 @@ $Tags = Get-CheckInformation -Check $Check -Group Instance -AllChecks $AllChecks
}
}
else {
if ($null -eq $ExpectedTraceFlags) { $ExpectedTraceFlags = 0 }
$ActualTraceflags = (Get-DbaTraceFlag -SqlInstance $psitem).TraceFlag
Context "Testing Expected Trace Flags on $psitem" {
It "Expected Trace Flags $ExpectedTraceFlags exist on $psitem" {
Assert-TraceFlag -SQLInstance $psitem -ExpectedTraceFlag $ExpectedTraceFlags
foreach ($ExpectedTraceFlag in $ExpectedTraceFlags) {
if ($ExpectedTraceFlag -ne 0) {
It "Expected Trace Flag $ExpectedTraceFlag to exist on $psitem" {
Assert-TraceFlag -ActualTraceflags $ActualTraceflags -ExpectedTraceFlag $ExpectedTraceFlag
}
}
else {
It "Expected No Trace Flag to exist on $psitem" {
Assert-TraceFlag -ActualTraceflags $ActualTraceflags -ExpectedTraceFlag $ExpectedTraceFlag
}
}
}
}
}
Expand Down Expand Up @@ -1204,7 +1215,7 @@ $Tags = Get-CheckInformation -Check $Check -Group Instance -AllChecks $AllChecks
else {
Context "Testing if the suspect_pages table is nearing the limit of 1000 rows on $psitem" {
It "The suspect_pages table in msdb shouldn't be nearing the limit of 1000 rows on $psitem" -Skip:$skip {
(((Get-DbaSuspectPage -SqlInstance $psitem | Measure-Object).Count)/1000)*100 | Should -BeLessThan $thresholdPercent
(((Get-DbaSuspectPage -SqlInstance $psitem | Measure-Object).Count) / 1000) * 100 | Should -BeLessThan $thresholdPercent
}
}
}
Expand All @@ -1214,14 +1225,14 @@ $Tags = Get-CheckInformation -Check $Check -Group Instance -AllChecks $AllChecks
$skip = Get-DbcConfigValue skip.security.SQLMailXPsDisabled
if ($NotContactable -contains $psitem) {
Context "Testing SQL Mail XPs on $psitem" {
It "Can't Connect to $Psitem" -Skip:($skip -or $InstanceSMO.VersionMajor -gt 10){
It "Can't Connect to $Psitem" -Skip:($skip -or $InstanceSMO.VersionMajor -gt 10) {
$false | Should -BeTrue -Because "The instance should be available to be connected to!"
}
}
}
else {
Context "Testing SQL Mail XPs on $psitem" {
It "The SQL Mail XPs should be disabled on $psitem" -Skip:($skip -or $InstanceSMO.VersionMajor -gt 10){
It "The SQL Mail XPs should be disabled on $psitem" -Skip:($skip -or $InstanceSMO.VersionMajor -gt 10) {
Assert-SQLMailXPs -AllInstanceInfo $AllInstanceInfo
}
}
Expand Down
30 changes: 15 additions & 15 deletions internal/assertions/Instance.Assertions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,10 @@ function Get-AllInstanceInfo {
AND name <> 'sp_MSrepl_startup'"
$results = Invoke-DbaQuery -SqlInstance $Instance -Query $query

if ($null -eq $results) {
if ($null -eq $results) {
$Value = 0
} else {
}
else {
$Value = $SpConfig.ConfiguredValue
}

Expand Down Expand Up @@ -251,7 +252,7 @@ function Get-AllInstanceInfo {
$MaxDump = [pscustomobject] @{
# Warning Action removes dbatools output for version too low from test results
# Skip on the it will show in the results
Count = (@(Get-DbaDump -SqlInstance $Instance -WarningAction SilentlyContinue).Where{ $_.CreationTime -gt $datetocheckfrom}).Count
Count = (@(Get-DbaDump -SqlInstance $Instance -WarningAction SilentlyContinue).Where{ $_.CreationTime -gt $datetocheckfrom }).Count
}
}
catch {
Expand Down Expand Up @@ -446,10 +447,10 @@ function Get-AllInstanceInfo {
if ($There) {
try {
$ComputerName, $InstanceName = $Instance.Name.Split('\')
if ($null -eq $InstanceName){
if ($null -eq $InstanceName) {
$InstanceName = 'MSSQLSERVER'
}
$logins = Get-DbaLogin -SqlInstance $Instance | Where-Object {$_.LoginType -eq 'WindowsGroup' -and $_.Name.Split('\') -eq $ComputerName}
$logins = Get-DbaLogin -SqlInstance $Instance | Where-Object { $_.LoginType -eq 'WindowsGroup' -and $_.Name.Split('\') -eq $ComputerName }
if ($null -ne $logins) {
$LocalWindowsGroup = [pscustomobject] @{
Exist = $true
Expand Down Expand Up @@ -727,7 +728,7 @@ function Get-AllInstanceInfo {
if ($There) {
try {
$LoginCheckPolicy = [pscustomobject] @{
Count = @(Get-DbaLogin -SQLInstance $instance -Type SQL | Where-Object { $_.PasswordPolicyEnforced -eq $false -and $_.IsDisabled -eq $false}).Count
Count = @(Get-DbaLogin -SQLInstance $instance -Type SQL | Where-Object { $_.PasswordPolicyEnforced -eq $false -and $_.IsDisabled -eq $false }).Count
}
}
catch {
Expand All @@ -751,7 +752,7 @@ function Get-AllInstanceInfo {
$role = Get-DbaServerRole -SQLInstance $instance -ServerRole "sysadmin"

$LoginPasswordExpiration = [pscustomobject] @{
Count = @(Get-DbaLogin -SQLInstance $instance -Login @($role.Login) -Type SQL | Where-Object { $_.PasswordExpirationEnabled -eq $false -and $_.IsDisabled -eq $false}).Count
Count = @(Get-DbaLogin -SQLInstance $instance -Login @($role.Login) -Type SQL | Where-Object { $_.PasswordExpirationEnabled -eq $false -and $_.IsDisabled -eq $false }).Count
}
}
catch {
Expand Down Expand Up @@ -842,7 +843,7 @@ function Get-AllInstanceInfo {
LoginCheckPolicy = $LoginCheckPolicy
LoginPasswordExpiration = $LoginPasswordExpiration
LoginMustChange = $LoginMustChange
SQLMailXPsDisabled = $SQLMailXPsDisabled
SQLMailXPsDisabled = $SQLMailXPsDisabled
}
}

Expand Down Expand Up @@ -954,16 +955,15 @@ function Assert-TwoDigitYearCutoff {

function Assert-TraceFlag {
Param(
[string]$SQLInstance,
$ActualTraceflags,
[int[]]$ExpectedTraceFlag
)
if ($null -eq $ExpectedTraceFlag) {
(Get-DbaTraceFlag -SqlInstance $SQLInstance).TraceFlag | Should -BeNullOrEmpty -Because "We expect that there will be no Trace Flags set on $SQLInstance"

if ($ExpectedTraceFlag -ne 0) {
$ExpectedTraceFlag | Should -BeIn $ActualTraceflags -Because "We expect that Trace Flag $ExpectedTraceFlag will be set"
}
else {
@($ExpectedTraceFlag).ForEach{
(Get-DbaTraceFlag -SqlInstance $SQLInstance).TraceFlag | Should -Contain $PSItem -Because "We expect that Trace Flag $PsItem will be set on $SQLInstance"
}
$ActualTraceflags | Should -BeNullOrEmpty -Because "We expect that there will be no Trace Flags set"
}
}
function Assert-NotTraceFlag {
Expand All @@ -976,7 +976,7 @@ function Assert-NotTraceFlag {
)

if ($null -eq $NotExpectedTraceFlag) {
(@(Get-DbaTraceFlag -SqlInstance $SQLInstance).Where{ $_.TraceFlag -notin $ExpectedTraceFlag} | Select-Object).TraceFlag | Should -BeNullOrEmpty -Because "We expect that there will be no Trace Flags set on $SQLInstance"
(@(Get-DbaTraceFlag -SqlInstance $SQLInstance).Where{ $_.TraceFlag -notin $ExpectedTraceFlag } | Select-Object).TraceFlag | Should -BeNullOrEmpty -Because "We expect that there will be no Trace Flags set on $SQLInstance"
}
else {
@($NotExpectedTraceFlag).ForEach{
Expand Down

0 comments on commit 89bb3de

Please sign in to comment.