Skip to content

Commit

Permalink
Merge pull request #995 from dataplat/instancecheckscontinued
Browse files Browse the repository at this point in the history
so that we can see failed connections and they are in the results #882
  • Loading branch information
SQLDBAWithABeard authored Aug 16, 2023
2 parents 7111e69 + 85229dc commit 10b7d26
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
22 changes: 22 additions & 0 deletions source/checks/Instancev5.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,29 @@ BeforeDiscovery {
Set-PSFConfig -Module dbachecks -Name global.notcontactable -Value $NotContactable
# Get-DbcConfig is expensive so we call it once
$__dbcconfig = Get-DbcConfig
$notcontactable = (Get-PSFConfig -Module dbachecks -Name global.notcontactable).Value
$Checks = Get-DbcCheck
$TestsNoGoBrrr = foreach ($Not in $notcontactable) {
foreach ($tag in $tags) {
[PSCustomObject]@{
Name = $Not
Tag = $tag
}
}
}
}

BeforeAll {

}
Describe "<_.Tag> failed on <_.Name>" -Tag FailedConnections -ForEach $TestsNoGoBrrr {
Context "Checking <_.Tag> on <_.Name>" {
It "The instance <_.Name> is not connectable" -Skip:$skip {
$false | Should -BeTrue -Because "This instance is not connectable"
}
}
}


# Ordered alphabetically by unique tag please
Describe "Ad Hoc Distributed Queries" -Tag AdHocDistributedQueriesEnabled, security, CIS, Medium, Instance -ForEach $InstancesToTest {
Expand Down
3 changes: 2 additions & 1 deletion source/functions/Invoke-DbcCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ function Invoke-DbcCheck {
}
}
process {

if ($legacy) {
try {
Write-PSFMessage 'Running in legacy mode, we need Version 4'
Expand Down Expand Up @@ -365,7 +366,7 @@ function Invoke-DbcCheck {
# cast from empty hashtable to get default
$configuration = New-PesterConfiguration
$configuration.Output.Verbosity = $NewShow
$configuration.Filter.Tag = $check
$configuration.Filter.Tag = $check + 'FailedConnections'
$configuration.Filter.ExcludeTag = $ExcludeCheck
if ($PassThru) {
$configuration.Run.PassThru = $true
Expand Down
4 changes: 2 additions & 2 deletions source/internal/functions/Invoke-DbcCheckv5.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function Invoke-DbcCheckv5 {
$name = "Config" + (($name.Split(".") | ForEach-Object { $_.SubString(0, 1).ToUpper() + $_.SubString(1) }) -join '')
$ParamAttrib = New-Object System.Management.Automation.ParameterAttribute
$ParamAttrib.ParameterSetName = '__AllParameterSets'
$AttribColl = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
$AttribColl = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
$AttribColl.Add($ParamAttrib)

$RuntimeParam = New-Object System.Management.Automation.RuntimeDefinedParameter($name, [object], $AttribColl)
Expand Down Expand Up @@ -159,8 +159,8 @@ function Invoke-DbcCheckv5 {
Write-PSFMessage -Message "SqlInstance is $SqlInstance" -Level Verbose
# Because we have all these bound params :-(
$null = $PSBoundParameters.Remove('configuration')

Invoke-Pester -Configuration $configuration

Pop-Location
}
}
Expand Down
18 changes: 9 additions & 9 deletions source/internal/functions/NewGet-AllInstanceInfo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -419,16 +419,16 @@ function NewGet-AllInstanceInfo {
{ 'PublicRolePermissions' -or 'PublicPermission' } {
#This needs to be done in query just in case the account had already been renamed
$query = "
SELECT Count(*) AS [RowCount]
FROM master.sys.server_permissions
WHERE (grantee_principal_id = SUSER_SID(N'public') and state_desc LIKE 'GRANT%')
AND NOT (state_desc = 'GRANT' and [permission_name] = 'VIEW ANY DATABASE' and class_desc = 'SERVER')
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 2)
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 3)
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 4)
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 5);
SELECT Count(*) AS [RowCount]
FROM master.sys.server_permissions
WHERE (grantee_principal_id = SUSER_SID(N'public') and state_desc LIKE 'GRANT%')
AND NOT (state_desc = 'GRANT' and [permission_name] = 'VIEW ANY DATABASE' and class_desc = 'SERVER')
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 2)
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 3)
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 4)
AND NOT (state_desc = 'GRANT' and [permission_name] = 'CONNECT' and class_desc = 'ENDPOINT' and major_id = 5);
"
$PublicRolePermsCount = $srv.Query($query).RowCount
$PublicRolePermsCount = $Instance.Query($query).RowCount
}

'SuspectPageLimit' {
Expand Down

0 comments on commit 10b7d26

Please sign in to comment.