Skip to content

Commit 848f408

Browse files
committed
Audit log error handling
1 parent cf40591 commit 848f408

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

Modules/CIPPCore/Public/AuditLogs/Get-CippAuditLogSearchResults.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ function Get-CippAuditLogSearchResults {
1818
)
1919

2020
process {
21-
New-GraphGetRequest -uri ('https://graph.microsoft.com/beta/security/auditLog/queries/{0}/records?$top=999' -f $QueryId) -AsApp $true -tenantid $TenantFilter
21+
New-GraphGetRequest -uri ('https://graph.microsoft.com/beta/security/auditLog/queries/{0}/records?$top=999' -f $QueryId) -AsApp $true -tenantid $TenantFilter -ErrorAction Stop
2222
}
2323
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Alerts/Invoke-ListAuditLogSearches.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ function Invoke-ListAuditLogSearches {
2020
} | ConvertTo-Json -Depth 10 -Compress
2121
}
2222
'SearchResults' {
23-
$Results = Get-CippAuditLogSearchResults -TenantFilter $Request.Query.TenantFilter -QueryId $Request.Query.SearchId
23+
try {
24+
$Results = Get-CippAuditLogSearchResults -TenantFilter $Request.Query.TenantFilter -QueryId $Request.Query.SearchId
25+
} catch {
26+
$Results = @{ Error = $_.Exception.Message }
27+
}
2428
$Body = @{
2529
Results = @($Results)
2630
Metadata = @{

Modules/CIPPCore/Public/Webhooks/Test-CIPPAuditLogRules.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ function Test-CIPPAuditLogRules {
3535
}
3636
}
3737
#write-warning 'Getting audit records from Graph API'
38-
$SearchResults = Get-CippAuditLogSearchResults -TenantFilter $TenantFilter -QueryId $SearchId
38+
try {
39+
$SearchResults = Get-CippAuditLogSearchResults -TenantFilter $TenantFilter -QueryId $SearchId
40+
} catch {
41+
Write-Warning "Error getting audit logs: $($_.Exception.Message)"
42+
Write-LogMessage -API 'Webhooks' -message "Error getting audit logs for search $($SearchId)" -LogData (Get-CippException -Exception $_) -sev Error -tenant $TenantFilter
43+
throw $_
44+
}
3945
$LogCount = ($SearchResults | Measure-Object).Count
4046
$RunGuid = New-Guid
4147
Write-Warning "Logs to process: $LogCount - RunGuid: $($RunGuid) - $($TenantFilter)"

0 commit comments

Comments
 (0)