Skip to content

Commit

Permalink
Audit log error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnDuprey committed Oct 11, 2024
1 parent cf40591 commit 848f408
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ function Get-CippAuditLogSearchResults {
)

process {
New-GraphGetRequest -uri ('https://graph.microsoft.com/beta/security/auditLog/queries/{0}/records?$top=999' -f $QueryId) -AsApp $true -tenantid $TenantFilter
New-GraphGetRequest -uri ('https://graph.microsoft.com/beta/security/auditLog/queries/{0}/records?$top=999' -f $QueryId) -AsApp $true -tenantid $TenantFilter -ErrorAction Stop
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ function Invoke-ListAuditLogSearches {
} | ConvertTo-Json -Depth 10 -Compress
}
'SearchResults' {
$Results = Get-CippAuditLogSearchResults -TenantFilter $Request.Query.TenantFilter -QueryId $Request.Query.SearchId
try {
$Results = Get-CippAuditLogSearchResults -TenantFilter $Request.Query.TenantFilter -QueryId $Request.Query.SearchId
} catch {
$Results = @{ Error = $_.Exception.Message }
}
$Body = @{
Results = @($Results)
Metadata = @{
Expand Down
8 changes: 7 additions & 1 deletion Modules/CIPPCore/Public/Webhooks/Test-CIPPAuditLogRules.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ function Test-CIPPAuditLogRules {
}
}
#write-warning 'Getting audit records from Graph API'
$SearchResults = Get-CippAuditLogSearchResults -TenantFilter $TenantFilter -QueryId $SearchId
try {
$SearchResults = Get-CippAuditLogSearchResults -TenantFilter $TenantFilter -QueryId $SearchId
} catch {
Write-Warning "Error getting audit logs: $($_.Exception.Message)"
Write-LogMessage -API 'Webhooks' -message "Error getting audit logs for search $($SearchId)" -LogData (Get-CippException -Exception $_) -sev Error -tenant $TenantFilter
throw $_
}
$LogCount = ($SearchResults | Measure-Object).Count
$RunGuid = New-Guid
Write-Warning "Logs to process: $LogCount - RunGuid: $($RunGuid) - $($TenantFilter)"
Expand Down

0 comments on commit 848f408

Please sign in to comment.