Skip to content

Commit a8d4d3a

Browse files
add filesafeoperator + small improves + configs
1 parent 09bc3a6 commit a8d4d3a

File tree

3 files changed

+42
-41
lines changed

3 files changed

+42
-41
lines changed

source/checks/Agentv5.Tests.ps1

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,26 @@ BeforeDiscovery {
3131
}
3232
}
3333
}
34+
3435
Write-PSFMessage -Message "Instances = $($InstancesToTest.Name)" -Level Verbose
3536
Set-PSFConfig -Module dbachecks -Name global.notcontactable -Value $NotContactable
36-
}
3737

38+
# Get-DbcConfig is expensive so we call it once
39+
$__dbcconfig = Get-DbcConfig
40+
}
3841

39-
Describe "Database Mail XPs" -Tag DatabaseMailEnabled, CIS, security -ForEach $InstancesToTest {
40-
$skip = Get-DbcConfigValue skip.agent.databasemailenabled
42+
Describe "Database Mail XPs" -Tag DatabaseMailEnabled, CIS, security, Agent -ForEach $InstancesToTest {
43+
$skip = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.agent.databasemailenabled' }).Value
4144
Context "Testing Database Mail XPs on <_.Name>" {
42-
It "Testing Database Mail XPs is set to <_.DatabaseMailEnabled> on <_.Name>" -Skip:$skip {
45+
It "Testing Database Mail XPs is set to <_.ConfigValues.DatabaseMailEnabled> on <_.Name>" -Skip:$skip {
4346
$PSItem.DatabaseMailEnabled | Should -Be $PSItem.ConfigValues.DatabaseMailEnabled -Because 'The Database Mail XPs setting should be set correctly'
4447
}
4548
}
4649
}
4750

48-
Describe "SQL Agent Account" -Tag AgentServiceAccount, ServiceAccount -ForEach $InstancesToTest {
49-
$skipServiceState = Get-DbcConfigValue skip.agent.servicestate
50-
$skipServiceStartMode = Get-DbcConfigValue skip.agent.servicestartmode
51+
Describe "SQL Agent Account" -Tag AgentServiceAccount, ServiceAccount, Agent -ForEach $InstancesToTest {
52+
$skipServiceState = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.agent.servicestate' }).Value
53+
$skipServiceStartMode = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.agent.servicestartmode' }).Value
5154

5255
Context "Testing SQL Agent is running on <_.Name>" {
5356
It "SQL Agent should be running for <_.InstanceName> on <_.Name>" -Skip:$skipServiceState {
@@ -66,9 +69,9 @@ Describe "SQL Agent Account" -Tag AgentServiceAccount, ServiceAccount -ForEach $
6669
}
6770
}
6871

69-
Describe "DBA Operator" -Tag DbaOperator, Operator -ForEach $InstancesToTest {
70-
$skipOperatorName = Get-DbcConfigValue skip.agent.operatorname
71-
$skipOperatorEmail = Get-DbcConfigValue skip.agent.operatoremail
72+
Describe "DBA Operator" -Tag DbaOperator, Operator, Agent -ForEach $InstancesToTest {
73+
$skipOperatorName = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.agent.dbaoperatorname' }).Value
74+
$skipOperatorEmail = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.agent.dbaoperatoremail' }).Value
7275

7376
Context "Testing DBA Operators exists on <_.Name>" {
7477
It "The Operator <_.ExpectedOperatorName> exists on <_.Name>" -Skip:$skipOperatorName -ForEach ($PSItem.Operator | Where-Object ExpectedOperatorName -NE 'null') {
@@ -81,23 +84,28 @@ Describe "DBA Operator" -Tag DbaOperator, Operator -ForEach $InstancesToTest {
8184
}
8285
}
8386

84-
# Describe "Failsafe Operator" -Tags FailsafeOperator, Operator, $filename {
85-
# if ($NotContactable -contains $psitem) {
86-
# Context "Testing failsafe operator exists on $psitem" {
87-
# It "Can't Connect to $Psitem" {
88-
# $false | Should -BeTrue -Because "The instance should be available to be connected to!"
89-
# }
90-
# }
91-
# }
92-
# else {
93-
# Context "Testing failsafe operator exists on $psitem" {
94-
# $failsafeoperator = Get-DbcConfigValue agent.failsafeoperator
95-
# It "The Failsafe Operator exists on $psitem" {
96-
# (Connect-DbaInstance -SqlInstance $psitem).JobServer.AlertSystem.FailSafeOperator | Should -Be $failsafeoperator -Because 'The failsafe operator will ensure that any job failures will be notified to someone if not set explicitly'
97-
# }
98-
# }
99-
# }
100-
# }
87+
Describe "Failsafe operator" -Tag FailsafeOperator, CIS, security, Agent -ForEach $InstancesToTest {
88+
$skipFailsafeOperator = ($__dbcconfig | Where-Object { $_.Name -eq 'skip.agent.failsafeoperator' }).Value
89+
90+
Context "Testing failsafe operator exists on <_.Name>" {
91+
It "The failsafe operator <_.FailSafeOperator.ExpectedFailSafeOperator> exists on <_.Name>" -Skip:$skipFailsafeOperator {
92+
$PSItem.FailSafeOperator.ActualFailSafeOperator | Should -Be $PSItem.FailSafeOperator.ExpectedFailSafeOperator -Because 'The failsafe operator will ensure that any job failures will be notified to someone if not set explicitly'
93+
}
94+
}
95+
}
96+
97+
#
98+
## Write-PSFMessage -Message "Tags = $Tags" -Level Verbose
99+
#
100+
#Describe "Failsafe Operator" -Tag FailsafeOperator, Operator, Agent -ForEach $InstancesToTest {
101+
# $skipFailsafeOperator = Get-DbcConfigValue skip.agent.failsafeoperator
102+
#
103+
# Context "Testing failsafe operator exists on <_.Name>" {
104+
# It "The Failsafe Operator <_.ExpectedFailSafeOperator> exists on <_.Name>" -Skip:$skipFailsafeOperator -ForEach ($PSItem.AlertSystem | Where-Object ExpectedFailSafeOperator -NE 'null') {
105+
# $PSItem.ExpectedFailSafeOperator | Should -Be $PSItem.ActualFailSafeOperator -Because 'The failsafe operator will ensure that any job failures will be notified to someone if not set explicitly'
106+
# }
107+
# }
108+
#}
101109

102110
# Describe "Database Mail Profile" -Tags DatabaseMailProfile, $filename {
103111
# if ($NotContactable -contains $psitem) {

source/internal/configurations/configuration.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,8 @@ Set-PSFConfig -Module dbachecks -Name skip.hadr.listener.pingcheck -Validation b
338338
Set-PSFConfig -Module dbachecks -Name skip.agent.databasemailenabled -Validation bool -Value $false -Initialize -Description "Skip the Database Mail Enabled agent check"
339339
Set-PSFConfig -Module dbachecks -Name skip.agent.servicestartmode -Validation bool -Value $false -Initialize -Description "Skip the Agent Service State check"
340340
Set-PSFConfig -Module dbachecks -Name skip.agent.servicestate -Validation bool -Value $false -Initialize -Description "Skip the Agent Service Start Mode check"
341-
Set-PSFConfig -Module dbachecks -Name skip.agent.operatorname -Validation bool -Value $false -Initialize -Description "Skip the Agent Operator Name check"
342-
Set-PSFConfig -Module dbachecks -Name skip.agent.operatoremail -Validation bool -Value $false -Initialize -Description "Skip the Agent Operator Email check"
341+
Set-PSFConfig -Module dbachecks -Name skip.agent.dbaoperatorname -Validation bool -Value $false -Initialize -Description "Skip the Agent Operator Name check"
342+
Set-PSFConfig -Module dbachecks -Name skip.agent.dbaoperatoremail -Validation bool -Value $false -Initialize -Description "Skip the Agent Operator Email check"
343343
Set-PSFConfig -Module dbachecks -Name skip.agent.failsafeoperator -Validation bool -Value $false -Initialize -Description "Skip the Agent Failsafe Operator check"
344344
Set-PSFConfig -Module dbachecks -Name skip.agent.longrunningjobs -Validation bool -Value $false -Initialize -Description "Skip the long running agent jobs check"
345345
Set-PSFConfig -Module dbachecks -Name skip.agent.lastjobruntime -Validation bool -Value $false -Initialize -Description "Skip the last agent job time check"

source/internal/functions/Get-AllAgentInfo.ps1

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ function Get-AllAgentInfo {
88
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Login], $false)
99
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Agent.Job], $false)
1010
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Agent.Operator], $false)
11+
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Agent.AlertSystem], $false)
1112
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.StoredProcedure], $false)
1213
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Information], $false)
1314
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Settings], $false)
@@ -102,28 +103,19 @@ function Get-AllAgentInfo {
102103
}
103104
}
104105
'FailsafeOperator' {
105-
$FailsafeInitFields.Add("Name") | Out-Null # so we can check failsafe operators
106+
$FailsafeInitFields.Add("FailSafeOperator") | Out-Null # so we can check failsafe operators
106107
$Instance.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Agent.AlertSystem], $FailsafeInitFields)
107108
$FailsafeInitFields = $Instance.GetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Agent.AlertSystem])
108109

109110
$ConfigValues | Add-Member -MemberType NoteProperty -Name 'FailsafeOperator' -Value (Get-DbcConfigValue agent.failsafeoperator)
110111

111-
$Operator = $ConfigValues.FailsafeOperator.ForEach{
112+
$failsafeOperator = $ConfigValues.FailsafeOperator.ForEach{
112113
[PSCustomObject]@{
113114
InstanceName = $Instance.Name
114115
ExpectedFailSafeOperator = $PSItem
115-
ActualOperatorName = $Instance.JobServer.AlertSystem.Name
116+
ActualFailSafeOperator = $Instance.JobServer.AlertSystem.FailSafeOperator
116117
}
117118
}
118-
119-
$Operator += $ConfigValues.FailsafeOperator.ForEach{
120-
[PSCustomObject]@{
121-
InstanceName = $Instance.Name
122-
ExpectedFailSafeOperator = 'null'
123-
ActualOperatorName = 'null'
124-
}
125-
}
126-
127119
}
128120
'DatabaseMailProfile' {
129121

@@ -166,6 +158,7 @@ function Get-AllAgentInfo {
166158
DatabaseMailEnabled = $Instance.Configuration.DatabaseMailEnabled.ConfigValue
167159
Agent = @($Agent)
168160
Operator = @($Operator)
161+
FailSafeOperator = @($failsafeOperator)
169162
}
170163
return $testInstanceObject
171164
}

0 commit comments

Comments
 (0)