Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

so that we stop when we havent converted #1015

Merged
merged 9 commits into from
Sep 7, 2023
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- added pester tests to check that changelog is edited.

### Changed

- Fix to Invoke-DbcCheck so that tests that have not been converted to v5 produce warning messages.

## [3.0.1-preview0026] - 2023-08-28

### Added
Expand Down
34 changes: 21 additions & 13 deletions developing/Oslo Demo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,47 @@ $containers = $SQLInstances = $dbachecks1, $dbachecks2, $dbachecks3 = 'dbachecks
$password = ConvertTo-SecureString "dbatools.IO" -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "sqladmin", $password
$show = 'All'

$PSDefaultParameterValues = @{
"*:SQlInstance" = $SQLInstances
"*:SqlCredential" = $cred
}
#endregion

#region What do we have?

Get-DbaDatabase -SqlInstance $Sqlinstances -SqlCredential $cred -ExcludeSystem | Select-Object Sqlinstance, DatabaseName, Status
Get-DbaDatabase | Select-Object Sqlinstance, Name, Status

Get-DbaAgentJob -SqlInstance $Sqlinstances -SqlCredential $cred | Select-Object Sqlinstance, Name, Enabled
Get-DbaAgentJob | Select-Object Sqlinstance, Name, Enabled
#end region

Get-DbaLastBackup -SqlInstance $Sqlinstances -SqlCredential $cred | Select-Object Sqlinstance, Database, LastFullBackup | Format-Table
Get-DbaLastBackup | Select-Object Sqlinstance, Database, LastFullBackup | Format-Table

# lets run a couple of tests

# this one shows that the old existing code will work
# the legacy switch is set to true by default

Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show
Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show

# So lets show the shiny new faster code - legacy switch set to false

Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false
Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false


# The Authentication check failed but we would like to pass - lets set config
Set-DbcConfig -Name policy.connection.authscheme -Value SQL

# run again

Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false
Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false

# Hmmm, we know that we will never be able to remote onto these containers so let talk about skipping. No Claudio not that sort of skipping!!
Set-DbcConfig -Name skip.connection.remoting -Value $true

# run again

Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false
Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false

# So much quicker !!! OK for one check it will be slower. For two it will probably be about the same but for 3 or more it will be quicker. Much quicket. Exrapolate that to 100 checks and a 1000 instances you can see the difference.

Expand All @@ -57,7 +62,7 @@ Invoke-PerfAndValidateCheck -Checks $Checks

# ok lets run the checks and save the out put to a variable so that we can show you what happens. Notice we need the -PassThru switch

$CheckResults = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false -PassThru
$CheckResults = Invoke-DbcCheck -Check InstanceConnection, DatabaseStatus -Show $show -legacy $false -PassThru

# this is our base results object
$CheckResults
Expand All @@ -68,6 +73,7 @@ $SomethingUseful = $CheckResults | Convert-DbcResult

$SomethingUseful
$SomethingUseful | Format-Table
#TODO: fix this Checking Instance Connection on on dbachecks3

$SomethingUseful | Select-Object -First 1

Expand All @@ -87,23 +93,25 @@ code ./oslo.json

# or put them into a database table

$CheckResults | Convert-DbcResult -Label 'CoffeeFilter' | Write-DbcTable -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Verbose
$CheckResults | Convert-DbcResult -Label 'claudiodidthis' | Write-DbcTable -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb

Invoke-DbaQuery -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Query 'SELECT * FROM CheckResults'
Invoke-DbaQuery -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Query 'SELECT COUNT(*) FROM CheckResults'

# AUDIENCE AND OTHER PRESENTERS - WE NEED REMINDERS HERE !!!
# YOU CANT DO THIS FROM HERE - Open Windows terminal on the host and run

Start-DbcPowerBi -FromDatabase

# AUDIENCE AND OTHER PRESENTERS - WE NEED REMINDERS HERE !!!
# then use localhost,7401 tempdb and u:sqladmin p:dbatools.IO

# question turn off a container adn talk about hte fails?
# question turn off a container and talk about the fails?


## made some funky results for the Power Bi

$CheckResults = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check Instance, Database -Show $show -legacy $false -PassThru
$CheckResults = Invoke-DbcCheck -Check Instance, Database -Show $show -legacy $false -PassThru

$CheckResults | Convert-DbcResult -Label 'DatabaseInstance' | Write-DbcTable -SqlInstance dbachecks1 -SqlCredential $cred -Database tempdb -Verbose

$CheckResults = Invoke-DbcCheck -SqlInstance $Sqlinstances -SqlCredential $cred -Check compatibilitylevel -Show $show -legacy $false -PassThru
$CheckResults = Invoke-DbcCheck -Check compatibilitylevel -Show $show -legacy $false -PassThru
7 changes: 7 additions & 0 deletions developing/Robs-Instance.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ $Checks = 'LoginAuditSuccessful', 'LoginAuditFailed'
Set-DbcConfig -Name skip.security.PublicPermission -Value $false
$Checks = 'PublicRolePermission'
$Checks = 'PUblicPermission'
$Checks = 'Database'
$Checks = 'AgentServiceAccount', 'DbaOperator', 'DatabaseMailProfile', 'AgentMailProfile'

$DatabaseTags = (Get-DbcCheck -Group Database).UniqueTag

$Checks = $DatabaseTags[1..5]


Invoke-PerfAndValidateCheck -Checks $Checks
Invoke-PerfAndValidateCheck -Checks $Checks -PerfDetail
Expand Down
29 changes: 25 additions & 4 deletions source/functions/Invoke-DbcCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,26 @@ function Invoke-DbcCheck {
if ($PassThru) {
$configuration.Run.PassThru = $true
}
# So that if the only check passed in is not yet converted - so that we dont get red.
if ($check -in $notv5) {
Write-PSFMessage -Message "You are running a single check that is not yet converted to v5." -Level Warning
# So that if all of the checks passed in are not yet converted so that we stop

# Compare the two arrays
$comparisonResult = Compare-Object -ReferenceObject $check -DifferenceObject $notv5

# If all elements of $check are in $notv5, then $comparisonResult will be either $null or only contain differences where SideIndicator is '=>'

if (($comparisonResult | Where-Object SideIndicator -EQ '<=').Count -eq 0) {
$Message = "The checks that you are running are yet to be converted to v5 unfortunately. We cannot continue. Please use the legacy switch"
Write-PSFMessage -Message $Message -Level Warning
Return
}

foreach ($c in $Check) {
# So that if the only check passed in is not yet converted
if ($c -in $notv5) {
$Message = "You are running a check {0} that is not yet converted to v5." -f $c
Write-PSFMessage -Message $Message -Level Warning
}
}
} catch {
Write-PSFMessage -Message 'Something Went wrong' -Level Warning -ErrorRecord $_
Return
Expand All @@ -391,7 +406,13 @@ function Invoke-DbcCheck {
}
}
end {

foreach ($c in $Check) {
# So that if the only check passed in is not yet converted
if ($c -in $notv5) {
$Message = "You are running a check {0} that is not yet converted to v5." -f $c
Write-PSFMessage -Message $Message -Level Warning
}
}
}


Expand Down
2 changes: 1 addition & 1 deletion source/internal/configurations/configuration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $EmailValidationSb = {
}
Register-PSFConfigValidation -Name validation.EmailValidation -ScriptBlock $EmailValidationSb

$__dbachecksNotv5 = 'ADUser', 'BuiltInAdmin', 'EngineServiceAdmin', 'FullTextServiceAdmin', 'LocalWindowsGroup', 'PublicPermission', 'SqlBrowserServiceAccount', 'TempDbConfiguration','CertificateExpiration', 'DatabaseExists', 'DatabaseGrowthEvent', 'DatafileAutoGrowthType', 'DisabledIndex', 'DuplicateIndex', 'FileGroupBalanced', 'FutureFileGrowth', 'IdentityUsage', 'LastDiffBackup', 'LastFullBackup', 'LastGoodCheckDb', 'LastLogBackup', 'LogfilePercentUsed', 'LogfileSize', 'MaxDopDatabase', 'OrphanedUser', 'SymmetricKeyEncryptionLevel', 'TestLastBackup', 'TestLastBackupVerifyOnly', 'UnusedIndex', 'PowerPlan', 'SPN', 'DiskCapacity', 'PingComputer', 'CPUPrioritisation', 'DiskAllocationUnit', 'NonStandardPort', 'ServerProtocol', 'OlaInstalled', 'SystemFull', 'UserFull', 'UserDiff', 'UserLog', 'CommandLog', 'SystemIntegrityCheck', 'UserIntegrityCheck', 'UserIndexOptimize', 'OutputFileCleanup', 'DeleteBackupHistory', 'PurgeJobHistory', 'DomainName', 'OrganizationalUnit', 'ClusterHealth', 'LogShippingPrimary', 'LogShippingSecondary'
$__dbachecksNotv5 = 'ADUser', 'BuiltInAdmin', 'EngineServiceAdmin', 'FullTextServiceAdmin', 'LocalWindowsGroup', 'PublicPermission', 'SqlBrowserServiceAccount', 'TempDbConfiguration','CertificateExpiration', 'DatabaseExists', 'DatabaseGrowthEvent', 'DatafileAutoGrowthType', 'DisabledIndex', 'DuplicateIndex', 'FileGroupBalanced', 'FutureFileGrowth', 'IdentityUsage', 'LastDiffBackup', 'LastFullBackup', 'LastGoodCheckDb', 'LastLogBackup', 'LogfilePercentUsed', 'LogfileSize', 'MaxDopDatabase', 'OrphanedUser', 'SymmetricKeyEncryptionLevel', 'TestLastBackup', 'TestLastBackupVerifyOnly', 'UnusedIndex', 'PowerPlan', 'SPN', 'DiskCapacity', 'PingComputer', 'CPUPrioritisation', 'DiskAllocationUnit', 'NonStandardPort', 'ServerProtocol', 'OlaInstalled', 'SystemFull', 'UserFull', 'UserDiff', 'UserLog', 'CommandLog', 'SystemIntegrityCheck', 'UserIntegrityCheck', 'UserIndexOptimize', 'OutputFileCleanup', 'DeleteBackupHistory', 'PurgeJobHistory', 'DomainName', 'OrganizationalUnit', 'ClusterHealth', 'LogShippingPrimary', 'LogShippingSecondary'

Set-PSFConfig -Module dbachecks -Name checks.notv5ready -Value @($__dbachecksNotv5) -Initialize -Description "Checks that have not been converted to v5 yet"

Expand Down