From dbfd172cb748df661aeb1cae7281c32bdb7f2137 Mon Sep 17 00:00:00 2001 From: jpomfret Date: Wed, 1 Jun 2022 13:05:19 +0100 Subject: [PATCH] #884 add log file count check --- checks/Databasev5.Tests.ps1 | 12 +++++++++++- internal/configurations/configuration.ps1 | 1 + internal/functions/Get-AllDatabaseInfo.ps1 | 7 ++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/checks/Databasev5.Tests.ps1 b/checks/Databasev5.Tests.ps1 index a680688e..dcb4383a 100644 --- a/checks/Databasev5.Tests.ps1 +++ b/checks/Databasev5.Tests.ps1 @@ -129,4 +129,14 @@ Describe "Virtual Log Files" -Tag VirtualLogFile, Medium, Database -ForEach $Ins $psitem.VLF | Should -BeLessThan $psitem.ConfigValues.maxvlf -Because "Too many VLFs can impact performance and slow down backup/restore" } } -} \ No newline at end of file +} + +Describe "Log File Count Checks" -Tag LogfileCount, Medium, Database -ForEach $InstancesToTest { + $skip = Get-DbcConfigValue skip.database.logfilecounttest + + Context "Testing Log File count for <_.Name>" { + It "Database <_.Name> should have <_.ConfigValues.logfilecount> or less log files on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.logfilecountexclude -notcontains $PsItem.Name } } { + $psitem.LogFileCount | Should -BeLessOrEqual $psitem.ConfigValues.logfilecount -Because "You want the correct number of log files" + } + } +} diff --git a/internal/configurations/configuration.ps1 b/internal/configurations/configuration.ps1 index c237f3d0..4957dc61 100644 --- a/internal/configurations/configuration.ps1 +++ b/internal/configurations/configuration.ps1 @@ -233,6 +233,7 @@ Set-PSFConfig -Module dbachecks -Name policy.asymmetrickeysize.excludedb -Value Set-PSFConfig -Module dbachecks -Name policy.autoclose.excludedb -Value @() -Initialize -Description "Databases to exclude from autoclose key size checks" Set-PSFConfig -Module dbachecks -Name policy.autoshrink.excludedb -Value @() -Initialize -Description "Databases to exclude from autoclose key size checks" Set-PSFConfig -Module dbachecks -Name policy.vlf.excludedb -Value @('master', 'msdb', 'tempdb', 'model') -Initialize -Description "Databases to exclude from asymmetric key size checks" +Set-PSFConfig -Module dbachecks -Name policy.logfilecount.excludedb -Value @() -Initialize -Description "Databases to exclude from log file count checks" diff --git a/internal/functions/Get-AllDatabaseInfo.ps1 b/internal/functions/Get-AllDatabaseInfo.ps1 index 39e6d6d3..f12f918b 100644 --- a/internal/functions/Get-AllDatabaseInfo.ps1 +++ b/internal/functions/Get-AllDatabaseInfo.ps1 @@ -92,7 +92,11 @@ function Get-AllDatabaseInfo { $ConfigValues | Add-Member -MemberType NoteProperty -Name 'maxvlf' -Value (Get-DbcConfigValue policy.database.maxvlf) $ConfigValues | Add-Member -MemberType NoteProperty -Name 'vlfexclude' -Value (Get-DbcConfigValue policy.vlf.excludedb) } - + 'LogFileCount' { + $logfilecount = $true + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'logfilecount' -Value (Get-DbcConfigValue policy.database.logfilecount) + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'logfilecountexclude' -Value (Get-DbcConfigValue policy.logfilecount.excludedb) + } Default { } } @@ -116,6 +120,7 @@ function Get-AllDatabaseInfo { AutoClose = if ($autoclose) { $psitem.AutoClose} AutoShrink = if ($autoshrink) { $psitem.AutoShrink} VLF = if ($vlf) { ($psitem.Query("DBCC LOGINFO") | Measure-Object).Count } + LogFileCount = if ($logfilecount) { ($psitem.LogFiles | Measure-Object).Count } } } }