@@ -7,6 +7,8 @@ function Test-CIPPAuditLogRules {
77 $Rows
88 )
99
10+ $FunctionStartTime = Get-Date
11+
1012 $Results = [PSCustomObject ]@ {
1113 TotalLogs = 0
1214 MatchedLogs = 0
@@ -55,6 +57,7 @@ function Test-CIPPAuditLogRules {
5557 if ($LogCount -gt 0 ) {
5658 $LocationTable = Get-CIPPTable - TableName ' knownlocationdb'
5759 $ProcessedData = foreach ($AuditRecord in $SearchResults ) {
60+ $RecordStartTime = Get-Date
5861 Write-Host " Processing RowKey $ ( $AuditRecord.id ) "
5962 $RootProperties = $AuditRecord | Select-Object * - ExcludeProperty auditData
6063 $Data = $AuditRecord.auditData | Select-Object * , CIPPAction, CIPPClause, CIPPGeoLocation, CIPPBadRepIP, CIPPHostedIP, CIPPIPDetected, CIPPLocationInfo, CIPPExtendedProperties, CIPPDeviceProperties, CIPPParameters, CIPPModifiedProperties, AuditRecord - ErrorAction SilentlyContinue
@@ -102,7 +105,12 @@ function Test-CIPPAuditLogRules {
102105 $Trusted = $true
103106 }
104107 if (! $Trusted ) {
108+ $CacheLookupStartTime = Get-Date
105109 $Location = Get-CIPPAzDataTableEntity @LocationTable - Filter " RowKey eq '$ ( $Data.clientIp ) '" | Select-Object - Last 1
110+ $CacheLookupEndTime = Get-Date
111+ $CacheLookupSeconds = ($CacheLookupEndTime - $CacheLookupStartTime ).TotalSeconds
112+ Write-Warning " Cache lookup for IP $ ( $Data.clientip ) took $CacheLookupSeconds seconds"
113+
106114 if ($Location ) {
107115 $Country = $Location.CountryOrRegion
108116 $City = $Location.City
@@ -111,7 +119,11 @@ function Test-CIPPAuditLogRules {
111119 $ASName = $Location.ASName
112120 } else {
113121 try {
122+ $IPLookupStartTime = Get-Date
114123 $Location = Get-CIPPGeoIPLocation - IP $Data.clientip
124+ $IPLookupEndTime = Get-Date
125+ $IPLookupSeconds = ($IPLookupEndTime - $IPLookupStartTime ).TotalSeconds
126+ Write-Warning " IP lookup for $ ( $Data.clientip ) took $IPLookupSeconds seconds"
115127 } catch {
116128 # write-warning "Unable to get IP location for $($Data.clientip): $($_.Exception.Message)"
117129 }
@@ -151,6 +163,9 @@ function Test-CIPPAuditLogRules {
151163 # write-warning "Audit log: Error processing data: $($_.Exception.Message)`r`n$($_.InvocationInfo.PositionMessage)"
152164 Write-LogMessage - API ' Webhooks' - message ' Error Processing Audit Log Data' - LogData (Get-CippException - Exception $_ ) - sev Error - tenant $TenantFilter
153165 }
166+ $RecordEndTime = Get-Date
167+ $RecordSeconds = ($RecordEndTime - $RecordStartTime ).TotalSeconds
168+ Write-Warning " Task took $RecordSeconds seconds for RowKey $ ( $AuditRecord.id ) "
154169 }
155170 # write-warning "Processed Data: $(($ProcessedData | Measure-Object).Count) - This should be higher than 0 in many cases, because the where object has not run yet."
156171 # write-warning "Creating filters - $(($ProcessedData.operation | Sort-Object -Unique) -join ',') - $($TenantFilter)"
0 commit comments