Skip to content

Commit d676afa

Browse files
committed
chore: move audit log processing to separate timer function
1 parent 2577a20 commit d676afa

File tree

3 files changed

+53
-35
lines changed

3 files changed

+53
-35
lines changed

CIPPTimers.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,22 @@
3535
"PreferredProcessor": "auditlog",
3636
"IsSystem": true
3737
},
38+
{
39+
"Id": "01cd512a-15c4-44a9-b8cb-1e5d879cfd2d",
40+
"Command": "Start-AuditLogProcessingOrchestrator",
41+
"Description": "Orchestrator to process audit logs",
42+
"Cron": "0 */15 * * * *",
43+
"Priority": 3,
44+
"RunOnProcessor": true,
45+
"PreferredProcessor": "auditlog",
46+
"IsSystem": true
47+
},
3848
{
3949
"Id": "03475c86-4314-4d7b-90f2-5a0639e3899b",
4050
"Command": "Start-AuditLogSearchCreation",
4151
"Description": "Timer to create audit log searches",
4252
"Cron": "0 */30 * * * *",
43-
"Priority": 3,
53+
"Priority": 4,
4454
"RunOnProcessor": true,
4555
"PreferredProcessor": "auditlog",
4656
"IsSystem": true

Modules/CIPPCore/Public/Entrypoints/Orchestrator Functions/Start-AuditLogOrchestrator.ps1

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,40 +29,6 @@ function Start-AuditLogOrchestrator {
2929
SkipLog = $true
3030
}
3131
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress)
32-
Write-Information 'Starting audit log processing in batches of 1000, per tenant'
33-
$WebhookCacheTable = Get-CippTable -TableName 'CacheWebhooks'
34-
$WebhookCache = Get-CIPPAzDataTableEntity @WebhookCacheTable
35-
$TenantGroups = $WebhookCache | Group-Object -Property PartitionKey
36-
37-
if ($TenantGroups) {
38-
Write-Information "Processing webhook cache for $($TenantGroups.Count) tenants"
39-
#Write-Warning "AuditLogJobs are: $($TenantGroups.Count) tenants. Tenants: $($TenantGroups.name | ConvertTo-Json -Compress) "
40-
#Write-Warning "Here are the groups: $($TenantGroups | ConvertTo-Json -Compress)"
41-
$ProcessQueue = New-CippQueueEntry -Name 'Audit Logs Process' -Reference 'AuditLogsProcess' -TotalTasks ($TenantGroups | Measure-Object -Property Count -Sum).Sum
42-
$ProcessBatch = foreach ($TenantGroup in $TenantGroups) {
43-
$TenantFilter = $TenantGroup.Name
44-
$RowIds = @($TenantGroup.Group.RowKey)
45-
for ($i = 0; $i -lt $RowIds.Count; $i += 1000) {
46-
Write-Host "Processing $TenantFilter with $($RowIds.Count) row IDs. We're processing id $($RowIds[$i]) to $($RowIds[[Math]::Min($i + 999, $RowIds.Count - 1)])"
47-
$BatchRowIds = $RowIds[$i..([Math]::Min($i + 999, $RowIds.Count - 1))]
48-
[PSCustomObject]@{
49-
TenantFilter = $TenantFilter
50-
RowIds = $BatchRowIds
51-
QueueId = $ProcessQueue.RowKey
52-
FunctionName = 'AuditLogTenantProcess'
53-
}
54-
}
55-
}
56-
if ($ProcessBatch) {
57-
$ProcessInputObject = [PSCustomObject]@{
58-
OrchestratorName = 'AuditLogTenantProcess'
59-
Batch = @($ProcessBatch)
60-
SkipLog = $true
61-
}
62-
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($ProcessInputObject | ConvertTo-Json -Depth 5 -Compress)
63-
Write-Information "Started audit log processing orchestration with $($ProcessBatch.Count) batches"
64-
}
65-
}
6632
}
6733
}
6834
} catch {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
function Start-AuditLogProcessingOrchestrator {
2+
<#
3+
.SYNOPSIS
4+
Start the Audit Log Processing Orchestrator
5+
#>
6+
[CmdletBinding(SupportsShouldProcess = $true)]
7+
param()
8+
Write-Information 'Starting audit log processing in batches of 1000, per tenant'
9+
$WebhookCacheTable = Get-CippTable -TableName 'CacheWebhooks'
10+
$WebhookCache = Get-CIPPAzDataTableEntity @WebhookCacheTable
11+
$TenantGroups = $WebhookCache | Group-Object -Property PartitionKey
12+
13+
if ($TenantGroups) {
14+
Write-Information "Processing webhook cache for $($TenantGroups.Count) tenants"
15+
#Write-Warning "AuditLogJobs are: $($TenantGroups.Count) tenants. Tenants: $($TenantGroups.name | ConvertTo-Json -Compress) "
16+
#Write-Warning "Here are the groups: $($TenantGroups | ConvertTo-Json -Compress)"
17+
$ProcessQueue = New-CippQueueEntry -Name 'Audit Logs Process' -Reference 'AuditLogsProcess' -TotalTasks ($TenantGroups | Measure-Object -Property Count -Sum).Sum
18+
$ProcessBatch = foreach ($TenantGroup in $TenantGroups) {
19+
$TenantFilter = $TenantGroup.Name
20+
$RowIds = @($TenantGroup.Group.RowKey)
21+
for ($i = 0; $i -lt $RowIds.Count; $i += 1000) {
22+
Write-Host "Processing $TenantFilter with $($RowIds.Count) row IDs. We're processing id $($RowIds[$i]) to $($RowIds[[Math]::Min($i + 999, $RowIds.Count - 1)])"
23+
$BatchRowIds = $RowIds[$i..([Math]::Min($i + 999, $RowIds.Count - 1))]
24+
[PSCustomObject]@{
25+
TenantFilter = $TenantFilter
26+
RowIds = $BatchRowIds
27+
QueueId = $ProcessQueue.RowKey
28+
FunctionName = 'AuditLogTenantProcess'
29+
}
30+
}
31+
}
32+
if ($ProcessBatch) {
33+
$ProcessInputObject = [PSCustomObject]@{
34+
OrchestratorName = 'AuditLogTenantProcess'
35+
Batch = @($ProcessBatch)
36+
SkipLog = $true
37+
}
38+
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($ProcessInputObject | ConvertTo-Json -Depth 5 -Compress)
39+
Write-Information "Started audit log processing orchestration with $($ProcessBatch.Count) batches"
40+
}
41+
}
42+
}

0 commit comments

Comments
 (0)