From 4155a50382282f77c76f52732f79322b5c9963ee Mon Sep 17 00:00:00 2001 From: John Duprey Date: Tue, 21 May 2024 11:31:08 -0400 Subject: [PATCH 1/5] Domain Analyser tweak --- .../Domain Analyser/Push-DomainAnalyserTenant.ps1 | 13 +++++++++---- .../Domain Analyser/Push-GetTenantDomains.ps1 | 7 +++++++ 2 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-GetTenantDomains.ps1 diff --git a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1 b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1 index 729ffbccee8b..a6e43f66dd78 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1 @@ -41,8 +41,9 @@ function Push-DomainAnalyserTenant { $DomainCount = ($TenantDomains | Measure-Object).Count if ($DomainCount -gt 0) { Write-Host "$DomainCount tenant Domains" + $TenantDomainObjects = [System.Collections.Generic.List[object]]::new() try { - $TenantDomainObjects = foreach ($TenantDomain in $TenantDomains) { + foreach ($TenantDomain in $TenantDomains) { $TenantDetails = ($TenantDomain | ConvertTo-Json -Compress).ToString() $Filter = "PartitionKey eq '{0}' and RowKey eq '{1}'" -f $TenantDomain.Tenant, $TenantDomain.Domain $OldDomain = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter @@ -78,19 +79,23 @@ function Push-DomainAnalyserTenant { } } # Return domain object to list - $Domain + $TenantDomainObjects.Add($Domain) } # Batch insert tenant domains try { Add-CIPPAzDataTableEntity @DomainTable -Entity $TenantDomainObjects -Force $InputObject = [PSCustomObject]@{ - Batch = $TenantDomainObjects | Select-Object RowKey, @{n = 'FunctionName'; exp = { 'DomainAnalyserDomain' } } + QueueFunction = @{ + FunctionName = 'GetTenantDomains' + TenantGUID = $Tenant.customerId + } OrchestratorName = "DomainAnalyser_$($Tenant.defaultDomainName)" SkipLog = $true DurableMode = 'Sequence' } Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5) + Write-Host "Started orchestration for $DomainCount tenant domains in $($Tenant.defaultDomainName)" } catch { Write-LogMessage -API 'DomainAnalyser' -message 'Domain Analyser GetTenantDomains error' -sev info -LogData (Get-CippException -Exception $_) } @@ -99,7 +104,7 @@ function Push-DomainAnalyserTenant { } } } catch { - Write-Host (Get-CippException -Exception $_ | ConvertTo-Json) + #Write-Host (Get-CippException -Exception $_ | ConvertTo-Json) Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.defaultDomainName -message 'DNS Analyser GraphGetRequest' -LogData (Get-CippException -Exception $_) -sev Error } } diff --git a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-GetTenantDomains.ps1 b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-GetTenantDomains.ps1 new file mode 100644 index 000000000000..8a2958ea6da1 --- /dev/null +++ b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-GetTenantDomains.ps1 @@ -0,0 +1,7 @@ +function Push-GetTenantDomains { + Param($Item) + $DomainTable = Get-CippTable -tablename 'Domains' + $Filter = "PartitionKey eq 'TenantDomains' and TenantGUID eq '{0}'" -f $Item.TenantGUID + $Domains = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter | Select-Object RowKey, @{n = 'FunctionName'; exp = { 'DomainAnalyserDomain' } } + return @($Domains) +} \ No newline at end of file From f0b507c4c3e986e4be65ef109401c8ea1fb450d6 Mon Sep 17 00:00:00 2001 From: John Duprey Date: Tue, 21 May 2024 11:31:19 -0400 Subject: [PATCH 2/5] Disable logging for alert scheduled tasks --- .../Activity Triggers/Push-ExecScheduledCommand.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 index de573c156b7a..b75de4bd1d4d 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecScheduledCommand.ps1 @@ -107,5 +107,7 @@ function Push-ExecScheduledCommand { ScheduledTime = "$nextRunUnixTime" } } - Write-LogMessage -API 'Scheduler_UserTasks' -tenant $tenant -message "Successfully executed task: $($task.Name)" -sev Info + if ($TaskType -ne 'Alert') { + Write-LogMessage -API 'Scheduler_UserTasks' -tenant $tenant -message "Successfully executed task: $($task.Name)" -sev Info + } } \ No newline at end of file From 61a4fe1674cb65deb522fb5bbe9cd09af543e027 Mon Sep 17 00:00:00 2001 From: John Duprey Date: Fri, 24 May 2024 10:31:51 -0400 Subject: [PATCH 3/5] Domain Analyser tweak --- DomainAnalyser_OrchestrationStarter/run.ps1 | 1 - .../Push-DomainAnalyserDomain.ps1 | 20 +++++++++---------- .../Push-DomainAnalyserTenant.ps1 | 3 ++- .../Domain Analyser/Push-GetTenantDomains.ps1 | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/DomainAnalyser_OrchestrationStarter/run.ps1 b/DomainAnalyser_OrchestrationStarter/run.ps1 index a5a4b2f904f2..9c16b32afdba 100644 --- a/DomainAnalyser_OrchestrationStarter/run.ps1 +++ b/DomainAnalyser_OrchestrationStarter/run.ps1 @@ -16,7 +16,6 @@ $InputObject = [PSCustomObject]@{ } OrchestratorName = 'DomainAnalyser_Tenants' SkipLog = $true - DurableMode = 'Sequence' } Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5) diff --git a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserDomain.ps1 b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserDomain.ps1 index c80d265bf0ba..5366603a4492 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserDomain.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserDomain.ps1 @@ -122,8 +122,8 @@ function Push-DomainAnalyserDomain { } } catch { $Message = 'SPF Error' - Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message $Message -LogData (Get-CippException -Exception $_) -sev Error - throw $Message + Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error + return $Message } # Check SPF Record @@ -185,8 +185,8 @@ function Push-DomainAnalyserDomain { } } catch { $Message = 'DMARC Error' - Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message $Message -LogData (Get-CippException -Exception $_) -sev Error - throw $Message + Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error + return $Message } # DNS Sec Check @@ -203,8 +203,8 @@ function Push-DomainAnalyserDomain { } } catch { $Message = 'DNSSEC Error' - Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message $Message -LogData (Get-CippException -Exception $_) -sev Error - throw $Message + Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error + return $Message } # DKIM Check @@ -232,8 +232,8 @@ function Push-DomainAnalyserDomain { } } catch { $Message = 'DKIM Exception' - Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message $Message -LogData (Get-CippException -Exception $_) -sev Error - throw $Message + Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error + return $Message } # Final Score $Result.Score = $ScoreDomain @@ -248,9 +248,9 @@ function Push-DomainAnalyserDomain { Add-CIPPAzDataTableEntity @DomainTable -Entity $DomainObject -Force # Final Write to Output - Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message "DNS Analyser Finished For $Domain" -sev Info + Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message "DNS Analyser Finished For $Domain" -sev Info } catch { - Write-LogMessage -API -API 'DomainAnalyser' -tenant $tenant.tenant -message "Error saving domain $Domain to table " -sev Error -LogData (Get-CippException -Exception $_) + Write-LogMessage -API -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message "Error saving domain $Domain to table " -sev Error -LogData (Get-CippException -Exception $_) } return $null } \ No newline at end of file diff --git a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1 b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1 index a6e43f66dd78..09cd1f7ff95a 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1 @@ -95,7 +95,8 @@ function Push-DomainAnalyserTenant { DurableMode = 'Sequence' } Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5) - Write-Host "Started orchestration for $DomainCount tenant domains in $($Tenant.defaultDomainName)" + Write-Host "Started analysis for $DomainCount tenant domains in $($Tenant.defaultDomainName)" + Write-LogMessage -API 'DomainAnalyser' -tenant $Tenant.defaultDomainName -message "Started analysis for $DomainCount tenant domains" -sev Info } catch { Write-LogMessage -API 'DomainAnalyser' -message 'Domain Analyser GetTenantDomains error' -sev info -LogData (Get-CippException -Exception $_) } diff --git a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-GetTenantDomains.ps1 b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-GetTenantDomains.ps1 index 8a2958ea6da1..5fb9c64cdad1 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-GetTenantDomains.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-GetTenantDomains.ps1 @@ -2,6 +2,6 @@ function Push-GetTenantDomains { Param($Item) $DomainTable = Get-CippTable -tablename 'Domains' $Filter = "PartitionKey eq 'TenantDomains' and TenantGUID eq '{0}'" -f $Item.TenantGUID - $Domains = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter | Select-Object RowKey, @{n = 'FunctionName'; exp = { 'DomainAnalyserDomain' } } + $Domains = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter -Property RowKey | Select-Object RowKey, @{n = 'FunctionName'; exp = { 'DomainAnalyserDomain' } } return @($Domains) } \ No newline at end of file From b17050548ee0fe8c35fa02703782e98bce5d57ab Mon Sep 17 00:00:00 2001 From: John Duprey Date: Fri, 24 May 2024 10:59:45 -0400 Subject: [PATCH 4/5] Update Push-DomainAnalyserTenant.ps1 --- .../Domain Analyser/Push-DomainAnalyserTenant.ps1 | 1 - 1 file changed, 1 deletion(-) diff --git a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1 b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1 index 09cd1f7ff95a..605c56bebb53 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Domain Analyser/Push-DomainAnalyserTenant.ps1 @@ -92,7 +92,6 @@ function Push-DomainAnalyserTenant { } OrchestratorName = "DomainAnalyser_$($Tenant.defaultDomainName)" SkipLog = $true - DurableMode = 'Sequence' } Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5) Write-Host "Started analysis for $DomainCount tenant domains in $($Tenant.defaultDomainName)" From ba6bb5cf8bcd9db2c455a865a00ca85653624cd8 Mon Sep 17 00:00:00 2001 From: John Duprey Date: Fri, 24 May 2024 11:39:44 -0400 Subject: [PATCH 5/5] Update version_latest.txt --- version_latest.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version_latest.txt b/version_latest.txt index 722fb619cef4..23900d674daa 100644 --- a/version_latest.txt +++ b/version_latest.txt @@ -1 +1 @@ -5.7.2 \ No newline at end of file +5.7.3 \ No newline at end of file