Skip to content

Commit f5d717d

Browse files
authored
Merge pull request #574 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents f108250 + d059f5e commit f5d717d

File tree

4 files changed

+57
-30
lines changed

4 files changed

+57
-30
lines changed

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserDomain.ps1

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function Push-DomainAnalyserDomain {
145145
try {
146146
$DMARCPolicy = Read-DmarcPolicy -Domain $Domain -ErrorAction Stop
147147

148-
If ([string]::IsNullOrEmpty($DMARCPolicy.Record)) {
148+
if ([string]::IsNullOrEmpty($DMARCPolicy.Record)) {
149149
$Result.DMARCPresent = $false
150150
$ScoreExplanation.Add('No DMARC Records Found') | Out-Null
151151
} else {
@@ -320,11 +320,8 @@ function Push-DomainAnalyserDomain {
320320
$DomainTable.Entity = $DomainObject
321321
$DomainTable.Force = $true
322322
Add-CIPPAzDataTableEntity @DomainTable -Entity $DomainObject -Force
323-
324-
# Final Write to Output
325-
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message "DNS Analyser Finished For $Domain" -sev Info
326323
} catch {
327324
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message "Error saving domain $Domain to table " -sev Error -LogData (Get-CippException -Exception $_)
328325
}
329-
return $null
326+
return $Result
330327
}

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
function Push-DomainAnalyserTenant {
22
<#
3-
.FUNCTIONALITY
4-
Entrypoint
5-
#>
3+
.FUNCTIONALITY
4+
Entrypoint
5+
#>
66
param($Item)
77

88
$Tenant = Get-Tenants -IncludeAll | Where-Object { $_.customerId -eq $Item.customerId } | Select-Object -First 1
@@ -13,7 +13,7 @@ function Push-DomainAnalyserTenant {
1313
$CleanupRows = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter
1414
$CleanupCount = ($CleanupRows | Measure-Object).Count
1515
if ($CleanupCount -gt 0) {
16-
Write-LogMessage -API 'DomainAnalyser' -tenant $Tenant.defaultDomainName -message "Cleaning up $CleanupCount domain(s) for excluded tenant" -sev Info
16+
Write-LogMessage -API 'DomainAnalyser' -tenant $Tenant.defaultDomainName -tenantid $Tenant.customerId -message "Cleaning up $CleanupCount domain(s) for excluded tenant" -sev Info
1717
Remove-AzDataTableEntity -Force @DomainTable -Entity $CleanupRows
1818
}
1919
} elseif ($Tenant.GraphErrorCount -gt 50) {
@@ -61,8 +61,6 @@ function Push-DomainAnalyserTenant {
6161
}
6262
}
6363

64-
Write-Information ($TenantDomains | ConvertTo-Json -Depth 10)
65-
6664
$DomainCount = ($TenantDomains | Measure-Object).Count
6765
if ($DomainCount -gt 0) {
6866
Write-Host "############# $DomainCount tenant Domains"
@@ -119,21 +117,26 @@ function Push-DomainAnalyserTenant {
119117
TenantGUID = $Tenant.customerId
120118
}
121119
OrchestratorName = "DomainAnalyser_$($Tenant.defaultDomainName)"
122-
SkipLog = $true
120+
PostExecution = @{
121+
FunctionName = 'GetDomainAnalyserResults'
122+
Parameters = @{
123+
Tenant = $Tenant
124+
}
125+
}
123126
}
124127
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5)
125128
Write-Host "Started analysis for $DomainCount tenant domains in $($Tenant.defaultDomainName)"
126-
Write-LogMessage -API 'DomainAnalyser' -tenant $Tenant.defaultDomainName -message "Started analysis for $DomainCount tenant domains" -sev Info
129+
Write-LogMessage -Tenant $Tenant.defaultDomainName -TenantId $Tenant.customerId -API 'DomainAnalyser' -message "Started analysis for $DomainCount tenant domains" -sev Info
127130
} catch {
128-
Write-LogMessage -API 'DomainAnalyser' -message 'Domain Analyser GetTenantDomains error' -sev 'Error' -LogData (Get-CippException -Exception $_)
131+
Write-LogMessage -Tenant $Tenant.defaultDomainName -TenantId $Tenant.customerId -API 'DomainAnalyser' -message 'Domain Analyser GetTenantDomains error' -sev 'Error' -LogData (Get-CippException -Exception $_)
129132
}
130133
} catch {
131-
Write-LogMessage -API 'DomainAnalyser' -message 'GetTenantDomains loop error' -sev 'Error' -LogData (Get-CippException -Exception $_)
134+
Write-LogMessage -Tenant $Tenant.defaultDomainName -TenantId $Tenant.customerId -API 'DomainAnalyser' -message 'GetTenantDomains loop error' -sev 'Error' -LogData (Get-CippException -Exception $_)
132135
}
133136
}
134137
} catch {
135138
#Write-Host (Get-CippException -Exception $_ | ConvertTo-Json)
136-
Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.defaultDomainName -message 'DNS Analyser GraphGetRequest' -LogData (Get-CippException -Exception $_) -sev Error
139+
Write-LogMessage -Tenant $Tenant.defaultDomainName -TenantId $Tenant.customerId -API 'DomainAnalyser' -message 'DNS Analyser GraphGetRequest' -LogData (Get-CippException -Exception $_) -sev Error
137140
}
138141
}
139142
return $null
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
function Push-GetDomainAnalyserResults {
2+
[CmdletBinding()]
3+
param (
4+
$Item
5+
)
6+
7+
$Tenant = $Item.Parameters.Tenant
8+
Write-LogMessage -API 'DomainAnalyser' -Tenant $Tenant.defaultDomainName -TenantId $Tenant.customerId -message "Domain Analyser completed for tenant $($Tenant.defaultDomainName)" -sev Info -LogData ($Item.Results | Select-Object Domain, @{Name = 'Score'; Expression = { "$($_.Score)/$($_.MaximumScore)" } })
9+
return
10+
}

Modules/CippEntrypoints/CippEntrypoints.psm1

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ function Receive-CippOrchestrationTrigger {
180180
}
181181
Write-Information "Orchestrator started $($OrchestratorInput.OrchestratorName)"
182182
Write-Warning "Receive-CippOrchestrationTrigger - $($OrchestratorInput.OrchestratorName)"
183+
Set-DurableCustomStatus -CustomStatus $OrchestratorInput.OrchestratorName
183184
$DurableRetryOptions = @{
184185
FirstRetryInterval = (New-TimeSpan -Seconds 5)
185186
MaxNumberOfAttempts = if ($OrchestratorInput.MaxAttempts) { $OrchestratorInput.MaxAttempts } else { 1 }
@@ -203,20 +204,15 @@ function Receive-CippOrchestrationTrigger {
203204
Write-Information "Durable Mode: $DurableMode"
204205

205206
$RetryOptions = New-DurableRetryOptions @DurableRetryOptions
206-
207-
if ($Context.IsReplaying -ne $true -and $OrchestratorInput.SkipLog -ne $true) {
208-
Write-LogMessage -API $OrchestratorInput.OrchestratorName -tenant $OrchestratorInput.TenantFilter -message "Started $($OrchestratorInput.OrchestratorName)" -sev info
209-
}
210-
211207
if (!$OrchestratorInput.Batch -or ($OrchestratorInput.Batch | Measure-Object).Count -eq 0) {
212-
$Batch = (Invoke-ActivityFunction -FunctionName 'CIPPActivityFunction' -Input $OrchestratorInput.QueueFunction -ErrorAction Stop)
208+
$Batch = (Invoke-ActivityFunction -FunctionName 'CIPPActivityFunction' -Input $OrchestratorInput.QueueFunction -ErrorAction Stop) | Where-Object { $null -ne $_.FunctionName }
213209
} else {
214-
$Batch = $OrchestratorInput.Batch
210+
$Batch = $OrchestratorInput.Batch | Where-Object { $null -ne $_.FunctionName }
215211
}
216212

217213
if (($Batch | Measure-Object).Count -gt 0) {
218214
Write-Information "Batch Count: $($Batch.Count)"
219-
$Tasks = foreach ($Item in $Batch) {
215+
$Output = foreach ($Item in $Batch) {
220216
$DurableActivity = @{
221217
FunctionName = 'CIPPActivityFunction'
222218
Input = $Item
@@ -226,13 +222,34 @@ function Receive-CippOrchestrationTrigger {
226222
}
227223
Invoke-DurableActivity @DurableActivity
228224
}
229-
if ($NoWait -and $Tasks) {
230-
$null = Wait-ActivityFunction -Task $Tasks
225+
226+
if ($NoWait -and $Output) {
227+
$Output = $Output | Where-Object { $_.GetType().Name -eq 'ActivityInvocationTask' }
228+
if (($Output | Measure-Object).Count -gt 0) {
229+
Write-Information "Waiting for ($($Output.Count)) activity functions to complete..."
230+
$Results = Wait-ActivityFunction -Task @($Output)
231+
} else {
232+
$Results = @()
233+
}
234+
} else {
235+
$Results = $Output
231236
}
232237
}
233238

234-
if ($Context.IsReplaying -ne $true -and $OrchestratorInput.SkipLog -ne $true) {
235-
Write-LogMessage -API $OrchestratorInput.OrchestratorName -tenant $tenant -message "Finished $($OrchestratorInput.OrchestratorName)" -sev Info
239+
if ($Results -and $OrchestratorInput.PostExecution) {
240+
Write-Information "Running post execution function $($OrchestratorInput.PostExecution.FunctionName)"
241+
$PostExecParams = @{
242+
FunctionName = $OrchestratorInput.PostExecution.FunctionName
243+
Parameters = $OrchestratorInput.PostExecution.Parameters
244+
Results = @($Results)
245+
}
246+
if ($null -ne $PostExecParams.FunctionName) {
247+
$null = Invoke-ActivityFunction -FunctionName CIPPActivityFunction -Input $PostExecParams
248+
Write-Information "Post execution function $($OrchestratorInput.PostExecution.FunctionName) completed"
249+
} else {
250+
Write-Information 'No post execution function name provided'
251+
Write-Information ($PostExecParams | ConvertTo-Json -Depth 10)
252+
}
236253
}
237254
} catch {
238255
Write-Information "Orchestrator error $($_.Exception.Message) line $($_.InvocationInfo.ScriptLineNumber)"
@@ -322,11 +339,11 @@ function Receive-CippActivityTrigger {
322339
}
323340
}
324341

325-
# Return the captured output if it exists and is not null, otherwise return $true
342+
# Return the captured output if it exists and is not null
326343
if ($null -ne $Output -and $Output -ne '') {
327344
return $Output
328345
} else {
329-
return $true
346+
return
330347
}
331348
}
332349

0 commit comments

Comments
 (0)