diff --git a/Perf Testing pesterv5.ps1 b/Perf Testing pesterv5.ps1 index 629aba6f..c7324169 100644 --- a/Perf Testing pesterv5.ps1 +++ b/Perf Testing pesterv5.ps1 @@ -15,7 +15,7 @@ ipmo ./dbachecks.psd1 # $Checks = 'ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation' -$Checks = 'ModelDbGrowth' +$Checks = 'ErrorLogCount' Compare-CheckRuns -Checks $checks <# diff --git a/Validate v4 adn v5.ps1 b/Validate v4 adn v5.ps1 index 12719879..83f995ec 100644 --- a/Validate v4 adn v5.ps1 +++ b/Validate v4 adn v5.ps1 @@ -15,7 +15,7 @@ ipmo ./dbachecks.psd1 # $Checks = 'ModelDbGrowth','DefaultBackupCompression','SaExist','SaDisabled','SaRenamed','DefaultFilePath','AdHocDistributedQueriesEnabled','AdHocWorkload', 'DefaultTrace', 'OleAutomationProceduresDisabled', 'CrossDBOwnershipChaining', 'ScanForStartupProceduresDisabled', 'RemoteAccessDisabled', 'SQLMailXPsDisabled', 'DAC', 'OLEAutomation' -$Checks = 'ModelDbGrowth' +$Checks = 'ErrorLogCount' Compare-v4andv5Results -Checks $Checks <# diff --git a/checks/Instancev5.Tests.ps1 b/checks/Instancev5.Tests.ps1 index 9b2acb8f..49f6d49c 100644 --- a/checks/Instancev5.Tests.ps1 +++ b/checks/Instancev5.Tests.ps1 @@ -186,5 +186,13 @@ Describe "Model Database Growth" -Tag ModelDbGrowth, Low, Instance -ForEach $Ins } } +Describe "Error Log Count" -Tag ErrorLogCount, CIS, Low, Instance -ForEach $InstancesToTest { + $skip = Get-DbcConfigValue skip.instance.ErrorLogCount + Context "Checking error log count on <_.Name>" { + It "Error log count should be greater or equal to <_.ConfigValues.errorLogCount> on <_.Name>" -Skip:$skip{ + $psitem.NumberOfLogFiles | Should -BeGreaterOrEqual $psitem.ConfigValues.errorLogCount -Because "We expect to have at least $($psitem.ConfigValues.errorLogCount) number of error log files" + } + } +} diff --git a/internal/functions/NewGet-AllInstanceInfo.ps1 b/internal/functions/NewGet-AllInstanceInfo.ps1 index f3e25266..809dac82 100644 --- a/internal/functions/NewGet-AllInstanceInfo.ps1 +++ b/internal/functions/NewGet-AllInstanceInfo.ps1 @@ -63,6 +63,7 @@ function NewGet-AllInstanceInfo { $ScanForStartupProceduresDisabled = $true $StoredProcedureInitFields.Add("Startup") | Out-Null # So we can check SPs start up for the CIS checks $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.StoredProcedure], $StoredProcedureInitFields) + $StoredProcedureInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.StoredProcedure]) # I think we need to re-initialise here $ConfigValues | Add-Member -MemberType NoteProperty -Name 'scanforstartupproceduresdisabled' -Value (Get-DbcConfigValue policy.security.scanforstartupproceduresdisabled) } 'RemoteAccessDisabled' { @@ -96,7 +97,6 @@ function NewGet-AllInstanceInfo { $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Settings], $SettingsInitFields) } 'SaRenamed' { - } 'SaDisabled' { $LoginInitFields.Add("IsDisabled") | Out-Null # so we can check if sa is disabled @@ -112,6 +112,18 @@ function NewGet-AllInstanceInfo { $DataFileInitFields.Add("Name") | Out-Null # So we can check the model file growth settings $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.LogFile], $LogFileInitFields) $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.DataFile], $DataFileInitFields) + $LogFileInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.LogFile]) # I think we need to re-initialise here + $DataFileInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.DataFile]) # I think we need to re-initialise here + + } + 'ErrorlogCount' { + $ServerInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server]) + $ServerInitFields.Add("NumberOfLogFiles") | Out-Null # so we can check versions + $Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server], $ServerInitFields) + $ServerInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Server]) # I think we need to re-initialise here + + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'errorLogCount' -Value (Get-DbcConfigValue policy.errorlog.logcount) + } Default { } @@ -122,15 +134,16 @@ function NewGet-AllInstanceInfo { #build the object $testInstanceObject = [PSCustomObject]@{ - ComputerName = $Instance.ComputerName - InstanceName = $Instance.DbaInstanceName - Name = $Instance.Name - ConfigValues = $ConfigValues - VersionMajor = $Instance.VersionMajor - Configuration = if ($configurations) { $Instance.Configuration } else { $null } - Settings = $Instance.Settings - Logins = $Instance.Logins - Databases = $Instance.Databases + ComputerName = $Instance.ComputerName + InstanceName = $Instance.DbaInstanceName + Name = $Instance.Name + ConfigValues = $ConfigValues + VersionMajor = $Instance.VersionMajor + Configuration = if ($configurations) { $Instance.Configuration } else { $null } + Settings = $Instance.Settings + Logins = $Instance.Logins + Databases = $Instance.Databases + NumberOfLogFiles = $Instance.NumberOfLogFiles } if ($ScanForStartupProceduresDisabled) { $StartUpSPs = $Instance.Databases['master'].StoredProcedures.Where{ $_. Name -ne 'sp_MSrepl_startup' -and $_.StartUp -eq $true }.count