Skip to content

Commit

Permalink
ErrorLogCount added and tested #882
Browse files Browse the repository at this point in the history
  • Loading branch information
SQLDBAWithABeard committed Apr 27, 2022
1 parent c62535f commit b073c19
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Perf Testing pesterv5.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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

<#
Expand Down
2 changes: 1 addition & 1 deletion Validate v4 adn v5.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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

<#
Expand Down
8 changes: 8 additions & 0 deletions checks/Instancev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}


33 changes: 23 additions & 10 deletions internal/functions/NewGet-AllInstanceInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down Expand Up @@ -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
Expand All @@ -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 { }
Expand All @@ -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
Expand Down

0 comments on commit b073c19

Please sign in to comment.