Skip to content

Commit 62df56d

Browse files
so we can check instance connections #882
1 parent 0ffeb2e commit 62df56d

File tree

3 files changed

+50
-41
lines changed

3 files changed

+50
-41
lines changed

source/checks/Instancev5.Tests.ps1

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,34 @@ BeforeDiscovery {
3636
$__dbcconfig = Get-DbcConfig
3737
}
3838

39-
Describe "Instance Connection" -Tags InstanceConnection, Connectivity, High, Instance -ForEach $InstancesToTest {
39+
Describe "Instance Connection" -Tag InstanceConnection, Connectivity, High, Instance -ForEach $InstancesToTest {
4040
BeforeAll {
4141
$skipall = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.connection' }).Value
4242
$skipremote = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.connection.remoting' }).Value
4343
$skipping = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.connection.ping' }).Value
4444
$skipauth = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.connection.auth' }).Value
4545
$authscheme = ($__dbcconfig | Where-Object { $_.Name -eq 'policy.connection.authscheme' }).Value
4646
}
47+
BeforeDiscovery {
48+
$authscheme = ($__dbcconfig | Where-Object { $_.Name -eq 'policy.connection.authscheme' }).Value
49+
}
4750

4851
Context "Checking Instance Connection on on <_.Name>" -Skip:$skipall {
49-
It "connects successfully to <_.Name>" -Skip:skipall {
52+
It "connects successfully to <_.Name>" -Skip:$skipall {
5053
$PsItem.InstanceConnection.Connect | Should -BeTrue -Because "We expect the instance to be connectable"
5154
}
5255
It "auth scheme should be $authscheme on <_.Name>" -Skip:$skipauth {
5356
$PsItem.InstanceConnection.AuthScheme | Should -Be $authscheme -Because "We expect the auth scheme to be $authscheme"
5457
}
5558
It "We should be able to ping host <_.Name>" -Skip:$skipping {
56-
$PsItem.InstanceConnection.Ping | Should -BeTrue -Because "We expect the instance to be pingable"
59+
$PsItem.InstanceConnection.Ping | Should -Be 'Success' -Because "We expect the instance to be pingable"
5760
}
5861
It "We should be able to remote onto <_.Name>" -Skip:$skipremote {
5962
$PsItem.InstanceConnection.Remote | Should -BeTrue -Because "We expect the instance to be remotely connectable"
6063
}
6164
}
6265
}
6366

64-
6567
Describe "Default Trace" -Tag DefaultTrace, CIS, Low, Instance -ForEach $InstancesToTest {
6668
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.instance.defaulttrace' }).Value
6769
Context "Checking Default Trace on <_.Name>" {

source/internal/configurations/configuration.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,20 @@ Register-PSFConfigValidation -Name validation.EmailValidation -ScriptBlock $Emai
2121

2222
# some configs to help with autocompletes and other module level stuff
2323
#apps
24-
$defaultRepo = (Convert-Path -Path "$script:ModuleRoot\checks")
24+
$defaultRepo = "$script:ModuleRoot\checks"
2525
Set-PSFConfig -Module dbachecks -Name app.checkrepos -Value @($defaultRepo) -Initialize -Description "Where Pester tests/checks are stored"
2626
Set-PSFConfig -Module dbachecks -Name app.sqlinstance -Value $null -Initialize -Description "List of SQL Server instances that SQL-based tests will run against"
2727
Set-PSFConfig -Module dbachecks -Name app.computername -Value $null -Initialize -Description "List of Windows Servers that Windows-based tests will run against"
2828
Set-PSFConfig -Module dbachecks -Name app.sqlcredential -Value $null -Initialize -Description "The universal SQL credential if Trusted/Windows Authentication is not used"
2929
Set-PSFConfig -Module dbachecks -Name app.wincredential -Value $null -Initialize -Description "The universal Windows if default Windows Authentication is not used"
3030

31-
Set-PSFConfig -Module dbachecks -Name app.localapp -Value (Convert-Path -Path "$env:localappdata\dbachecks") -Initialize -Description "Persisted files live here"
32-
Set-PSFConfig -Module dbachecks -Name app.maildirectory -Value (Convert-Path -Path "$env:localappdata\dbachecks\dbachecks.mail") -Initialize -Description "Files for mail are stored here"
31+
if ($IsLinux) {
32+
Set-PSFConfig -Module dbachecks -Name app.localapp -Value "$home\dbachecks" -Initialize -Description "Persisted files live here"
33+
Set-PSFConfig -Module dbachecks -Name app.maildirectory -Value "$home\dbachecks\dbachecks.mail" -Initialize -Description "Files for mail are stored here"
34+
} else {
35+
Set-PSFConfig -Module dbachecks -Name app.localapp -Value "$env:localappdata\dbachecks" -Initialize -Description "Persisted files live here"
36+
Set-PSFConfig -Module dbachecks -Name app.maildirectory -Value "$env:localappdata\dbachecks\dbachecks.mail" -Initialize -Description "Files for mail are stored here"
37+
}
3338

3439
Set-PSFConfig -Module dbachecks -Name app.cluster -Value $null -Initialize -Description "One host name for each cluster for the HADR checks"
3540

source/internal/functions/NewGet-AllInstanceInfo.ps1

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -274,41 +274,43 @@ function NewGet-AllInstanceInfo {
274274
$TempDBTest = Test-DbaTempDbConfig -SqlInstance $Instance
275275
}
276276
'InstanceConnection' {
277+
#local is always NTLM except when its a container ;-)
278+
if ($Instance.NetBiosName -eq $ENV:COMPUTERNAME -and ($instance.Name -notlike '*,*')) {
279+
if (-not(($__dbcconfig | Where-Object { $_.Name -eq 'skip.connection.auth' }).Value)) {
280+
$authscheme = $instance.Query("Select auth_scheme as AuthScheme FROM sys.dm_exec_connections WHERE session_id = @@SPID").AuthScheme
281+
} else {
282+
$authscheme = 'skipped'
283+
}
284+
} else {
285+
$authscheme = 'skipped-local'
286+
}
287+
288+
if (-not(($__dbcconfig | Where-Object { $_.Name -eq 'skip.connection.ping' }).Value)) {
289+
$pingu = New-Object System.Net.NetworkInformation.Ping
290+
$timeout = 1000 #milliseconds
291+
$ping = ($pingu.Send($instance.ComputerName, $timeout)).Status
292+
} else {
293+
$ping = 'skipped'
294+
}
295+
296+
297+
if (-not(($__dbcconfig | Where-Object { $_.Name -eq 'skip.connection.remote' }).Value)) {
298+
#simple remoting check
299+
try {
300+
$null = Invoke-Command -ComputerName $instance.ComputerName -ScriptBlock { Get-ChildItem } -ErrorAction Stop
301+
$remote = $true
302+
} catch {
303+
$remote = $false
304+
}
305+
} else {
306+
$remote = 'skipped'
307+
}
308+
277309
$InstanceConnection = @{
278-
connection = $true # because we wouldnt get here otherwise
279-
authscheme = (
280-
#local is always NTLM except when its a container ;-)
281-
if ($Instance.NetBiosName -eq $ENV:COMPUTERNAME -and ($instance.Name -notlike '*,*')) {
282-
if (-not(($__dbcconfig | Where-Object { $_.Name -eq 'skip.connection.auth' }).Value)) {
283-
$instance.Query("Select auth_scheme as AuthScheme FROM sys.dm_exec_connections WHERE session_id = @@SPID").AuthScheme
284-
} else {
285-
'skipped'
286-
}
287-
} else {
288-
'skipped-local' }
289-
)
290-
ping = (
291-
if (-not(($__dbcconfig | Where-Object { $_.Name -eq 'skip.connection.ping' }).Value)) {
292-
$ping = New-Object System.Net.NetworkInformation.Ping
293-
$timeout = 1000 #milliseconds
294-
($ping.Send($instance.ComputerName, $timeout)).Status
295-
} else {
296-
'skipped'
297-
}
298-
)
299-
remote = (
300-
if (-not(($__dbcconfig | Where-Object { $_.Name -eq 'skip.connection.remote' }).Value)) {
301-
#simple remoting check
302-
try {
303-
$null = Invoke-Command -ComputerName $instance.ComputerName -ScriptBlock { Get-ChildItem } -ErrorAction Stop
304-
$true
305-
} catch {
306-
$false
307-
}
308-
} else {
309-
'skipped'
310-
}
311-
)
310+
Connect = $true # because we wouldnt get here otherwise
311+
AuthScheme = $authscheme
312+
Ping = $ping
313+
Remote = $remote
312314
}
313315
}
314316

0 commit comments

Comments
 (0)