From 658cc07c3a3a92a72b5a61f4dfd6fef6f1bcdbab Mon Sep 17 00:00:00 2001 From: jpomfret Date: Wed, 14 Jun 2023 16:53:20 +0000 Subject: [PATCH 1/3] add stuff for psconfeu --- .vscode/settings.json | 8 +++- CONTRIBUTING.md | 93 +++++++++++++++++++++++++++++++++++++ developing/PSConfEU demo.md | 48 +++++++++++++++++++ 3 files changed, 148 insertions(+), 1 deletion(-) create mode 100644 developing/PSConfEU demo.md diff --git a/.vscode/settings.json b/.vscode/settings.json index 41e02443..69d93115 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -47,5 +47,11 @@ "[markdown]": { "editor.trimAutoWhitespace": false, "files.trimTrailingWhitespace": false - } + }, + "cSpell.enableFiletypes": [ + "powershell" + ], + "cSpell.ignoreWords": [ + "maxcount" + ] } \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ce17931b..cba6723a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,100 @@ # Contributing ## TODO +## Welcome + +Before we go any further, thanks for being here. Thanks for using dbachecks and especially thanks +for being here and looking into how you can help! + +## Important resources + +- docs +- bugs +- communicate with the team + - slack + - github discussions? +- presentations\blogs? ## Running the Tests If want to know how to run this module's tests you can look at the [Testing Guidelines](https://dsccommunity.org/guidelines/testing-guidelines/#running-tests) + +## Environment details + +We strongly believe that 'every repo should have a devcontainer' and therefore we've built one +for this project that includes 3 SQL Servers and everything you need to develop and build the +dbachecks module. + +It's magic! + +### Prerequisites: + +In order to use the devcontainer there are a few things you need to get started. + +- [Docker](https://www.docker.com/get-started) +- [git](https://git-scm.com/downloads) +- [VSCode](https://code.visualstudio.com/download) +- [`Remote Development` Extension for VSCode](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) + +### Setup + +Once the prerequisites are in place follow these steps to download the repo and start up the +devcontainer. The first time you build the devcontainer it will need to pull down the images +so that could take a hot second depending on your internet speeds. + +1. Download the repo from GitHub + ```PowerShell + # change directory to where you'd like the repo to go + cd C:\GitHub\ + + # clone the repo from GitHub + git clone https://github.com/dataplat/dbachecks + + # move into the folder + cd .\dbachecks\ + + # open VSCode + code . + ``` + +754662. Once code opens, there should be a toast in the bottom right that suggests you 'ReOpen in Container'. +1. The first time you do this it may take a little, and you'll need an internet connection, as it'll download the container images used in our demos + +### Develop & Build +TODO: sampler instructions - similar to /workspace/developing/Howto.md + +### Rebuild + +The only way to properly rebuild to ensure that all volumes etc are removed is to open up a console +or PowerShell window outside of the devcontainer and run the following: + +```PowerShell + cd \path-of-dbachecks-folder\.devcontainer + + docker-compose -f "docker-compose.yml" -p "bitsdbatools_devcontainer" down +``` + +## How to submit changes: +TODO: +Pull Request protocol etc. You might also include what response they'll get back from the team on submission, or any caveats about the speed of response. + +## How to report a bug: +TODO: +Bugs are problems in code, in the functionality of an application or in its UI design; you can submit them through "bug trackers" and most projects invite you to do so, so that they may "debug" with more efficiency and the input of a contributor. Take a look at Atom's example for how to teach people to report bugs to your project. + +## Templates: +TODO: +in this section of your file, you might also want to link to a bug report "template" like this one here which contributors can copy and add context to; this will keep your bugs tidy and relevant. + +## Style Guide +TODO: +include extensions and vscode settings we use to keep things neat + +## Code of Conduct +TODO: maybe beef this out - stolen from data sat repo for now. + +We expect and demand that you follow some basic rules. Nothing dramatic here. There will be a proper code of conduct for the websites added soon, but in this repository + +BE EXCELLENT TO EACH OTHER + +Do I need to say more? If your behaviour or communication does not fit into this statement, we do not wish for you to help us. diff --git a/developing/PSConfEU demo.md b/developing/PSConfEU demo.md new file mode 100644 index 00000000..6590fdde --- /dev/null +++ b/developing/PSConfEU demo.md @@ -0,0 +1,48 @@ +# PSConfEU demo + +1. Develop in the source repository + - copy existing check & rewrite - add check to `source/checks/Databasev5.Tests.ps1` + - add configuration to `source/internal/configurations/configuration.ps1` + - `skip.database.pseudosimple` + - `policy.database.pseudosimpleexcludedb` + - add object info to `source/internal/functions/Get-AllDatabaseInfo.ps1` + + +2. Build the module + ```PowerShell + ./build.ps1 -Tasks build + ``` + +3. Sampler automatically adds the new version to your path + ```PowerShell + get-module dbachecks -ListAvailable | select name, modulebase + ``` + +4. Import new version of the module (if you get a bogus error the first time retry it) + ```PowerShell + Import-Module dbachecks -force + ``` + +5. Test out the new code + + ```PowerShell + # save the password to make for easy connections + $password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force + $cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password + + $show = 'All' + $checks = 'RecoveryModel' + + #$sqlinstances = 'localhost,7401', 'localhost,7402', 'localhost,7403' + $sqlinstances = 'dbachecks1', 'dbachecks2', 'dbachecks3' # need client aliases for this to work New-DbaClientAlias + + # Run v4 checks + $v4code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $true -Show $show -PassThru + # Run v5 checks + $v5code = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check $Checks -legacy $false -Show $show -PassThru -Verbose + + Invoke-PerfAndValidateCheck -SQLInstances $sqlinstances -Checks $Checks + Invoke-PerfAndValidateCheck -SQLInstances $sqlinstances -Checks $Checks -PerfDetail + Invoke-PerfAndValidateCheck -SQLInstances $sqlinstances -Checks $Checks -showTestResults + ``` + From 782a74d1e32457fbcac47ee98c855e48b98f04c9 Mon Sep 17 00:00:00 2001 From: Jess Pomfret Date: Wed, 14 Jun 2023 17:55:48 +0100 Subject: [PATCH 2/3] Update settings.json --- .vscode/settings.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 69d93115..165562eb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -50,8 +50,5 @@ }, "cSpell.enableFiletypes": [ "powershell" - ], - "cSpell.ignoreWords": [ - "maxcount" ] -} \ No newline at end of file +} From 63dbcaa6ae2dfdcb0274ff8ff267a31ee42215d1 Mon Sep 17 00:00:00 2001 From: jpomfret Date: Wed, 21 Jun 2023 07:34:29 +0000 Subject: [PATCH 3/3] new check LIVE AND IN PERSON! --- source/checks/Databasev5.Tests.ps1 | 10 ++++++++++ source/internal/configurations/configuration.ps1 | 1 + source/internal/functions/Get-AllDatabaseInfo.ps1 | 6 ++++++ 3 files changed, 17 insertions(+) diff --git a/source/checks/Databasev5.Tests.ps1 b/source/checks/Databasev5.Tests.ps1 index 8fe3c874..d1cf4e7c 100644 --- a/source/checks/Databasev5.Tests.ps1 +++ b/source/checks/Databasev5.Tests.ps1 @@ -232,3 +232,13 @@ Describe "Guest User" -Tag GuestUserConnect, Security, CIS, Medium, Database -Fo } } } + +Describe "Recovery Model" -Tag RecoveryModel, DISA, Medium, Database -ForEach $InstancesToTest { + $Skip = ($__dbcconfig | Where-Object Name -EQ 'skip.database.recoverymodel').Value + + Context "Testing Recovery Model" { + It "Database <_.Name> should be set to <_.ConfigValues.recoverymodeltype> on <_.SqlInstance>" -Skip:$skip -ForEach $psitem.Databases.Where{ if ($Database) { $_.Name -in $Database } else { $psitem.ConfigValues.recoverymodelexclude -notcontains $psitem.Name } } { + $psitem.RecoveryModel | Should -Be $psitem.ConfigValues.recoverymodeltype -Because "You expect this recovery model." + } + } +} diff --git a/source/internal/configurations/configuration.ps1 b/source/internal/configurations/configuration.ps1 index ed908ebe..746240d6 100644 --- a/source/internal/configurations/configuration.ps1 +++ b/source/internal/configurations/configuration.ps1 @@ -324,6 +324,7 @@ Set-PSFConfig -Module dbachecks -Name skip.database.autoupdatestatisticsasynchro Set-PSFConfig -Module dbachecks -Name skip.database.trustworthy -Validation bool -Value $false -Initialize -Description "Skip the trustworthy database test" Set-PSFConfig -Module dbachecks -Name skip.database.status -Validation bool -Value $false -Initialize -Description "Skip the database status test" 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.logshiptesting -Validation bool -Value $false -Initialize -Description "Skip the logshipping test" diff --git a/source/internal/functions/Get-AllDatabaseInfo.ps1 b/source/internal/functions/Get-AllDatabaseInfo.ps1 index 9c29c9e0..eb58adfe 100644 --- a/source/internal/functions/Get-AllDatabaseInfo.ps1 +++ b/source/internal/functions/Get-AllDatabaseInfo.ps1 @@ -139,6 +139,11 @@ function Get-AllDatabaseInfo { $guestUserConnect = $true $ConfigValues | Add-Member -MemberType NoteProperty -Name 'guestuserexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'database.guestuser.excludedb').Value } + 'RecoveryModel' { + $recoverymodel = $true + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'recoverymodeltype' -Value ($__dbcconfig | Where-Object Name -EQ 'policy.recoverymodel.type').Value + $ConfigValues | Add-Member -MemberType NoteProperty -Name 'recoverymodelexclude' -Value ($__dbcconfig | Where-Object Name -EQ 'policy.recoverymodel.excludedb').Value + } Default { } } @@ -174,6 +179,7 @@ function Get-AllDatabaseInfo { CompatibilityLevel = @(if ($compatibilitylevel) { $psitem.CompatibilityLevel }) ServerLevel = @(if ($compatibilitylevel) { [Enum]::GetNames('Microsoft.SqlServer.Management.Smo.CompatibilityLevel').Where{ $psitem -match $Instance.VersionMajor } }) GuestUserConnect = @(if ($guestUserConnect) { if ($psitem.EnumDatabasePermissions('guest') | Where-Object { $_.PermissionState -eq 'Grant' -and $_.PermissionType.Connect }) { $true } } ) + RecoveryModel = @(if ($recoverymodel) { $psitem.RecoveryModel }) } } }