11function Push-AuditLogTenant {
22 Param ($Item )
33
4+ # Get Table contexts
45 $AuditBundleTable = Get-CippTable - tablename ' AuditLogBundles'
56 $SchedulerConfig = Get-CIPPTable - TableName ' SchedulerConfig'
6- $CIPPURL = Get-CIPPAzDataTableEntity @SchedulerConfig - Filter " PartitionKey eq 'webhookcreation'" | Select-Object - First 1 - ExpandProperty CIPPURL
77 $WebhookTable = Get-CippTable - tablename ' webhookTable'
8- $Webhooks = Get-CIPPAzDataTableEntity @WebhookTable - Filter " PartitionKey eq '$ ( $Item.TenantFilter ) ' and Version eq '3'" | Where-Object { $_.Resource -match ' ^Audit' }
9- $ExistingBundles = Get-CIPPAzDataTableEntity @AuditBundleTable - Filter " PartitionKey eq '$ ( $Item.TenantFilter ) ' and ContentType eq '$ContentType '"
108 $ConfigTable = Get-CIPPTable - TableName ' WebhookRules'
9+
10+ # Query CIPPURL for linking
11+ $CIPPURL = Get-CIPPAzDataTableEntity @SchedulerConfig - Filter " PartitionKey eq 'webhookcreation'" | Select-Object - First 1 - ExpandProperty CIPPURL
12+
13+ # Get all webhooks for the tenant
14+ $Webhooks = Get-CIPPAzDataTableEntity @WebhookTable - Filter " PartitionKey eq '$ ( $Item.TenantFilter ) ' and Version eq '3'" | Where-Object { $_.Resource -match ' ^Audit' }
15+
16+ # Get webhook rules
1117 $ConfigEntries = Get-CIPPAzDataTableEntity @ConfigTable
1218
19+ # Date filter for existing bundles
20+ $LastHour = (Get-Date ).AddHours(-1 ).ToUniversalTime().ToString(' yyyy-MM-ddTHH:mm:ss' )
21+
1322 $NewBundles = [System.Collections.Generic.List [object ]]::new()
1423 foreach ($Webhook in $Webhooks ) {
1524 # only process webhooks that are configured in the webhookrules table
@@ -28,6 +37,7 @@ function Push-AuditLogTenant {
2837 EndTime = $Item.EndTime
2938 }
3039 $LogBundles = Get-CIPPAuditLogContentBundles @ContentBundleQuery
40+ $ExistingBundles = Get-CIPPAzDataTableEntity @AuditBundleTable - Filter " PartitionKey eq '$ ( $Item.TenantFilter ) ' and ContentType eq '$LogType ' and Timestamp ge datetime'$ ( $LastHour ) '"
3141
3242 foreach ($Bundle in $LogBundles ) {
3343 if ($ExistingBundles.RowKey -notcontains $Bundle.contentId ) {
@@ -61,5 +71,4 @@ function Push-AuditLogTenant {
6171 $InstanceId = Start-NewOrchestration - FunctionName ' CIPPOrchestrator' - InputObject ($InputObject | ConvertTo-Json - Depth 5 - Compress)
6272 Write-Host " Started orchestration with ID = '$InstanceId '"
6373 }
64-
6574}
0 commit comments