Skip to content

Commit e4a34ff

Browse files
authored
Merge pull request #429 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 8bd3ef1 + dd57785 commit e4a34ff

File tree

13 files changed

+132
-62
lines changed

13 files changed

+132
-62
lines changed

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,31 @@ function Get-CippAuditLogSearches {
1313
[Parameter()]
1414
[switch]$ReadyToProcess
1515
)
16-
16+
$AuditLogSearchesTable = Get-CippTable -TableName 'AuditLogSearches'
1717
if ($ReadyToProcess.IsPresent) {
18-
$AuditLogSearchesTable = Get-CippTable -TableName 'AuditLogSearches'
1918
$15MinutesAgo = (Get-Date).AddMinutes(-15).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
2019
$1DayAgo = (Get-Date).AddDays(-1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
21-
$PendingQueries = Get-CIPPAzDataTableEntity @AuditLogSearchesTable -Filter "Tenant eq '$TenantFilter' and (CippStatus eq 'Pending' or (CippStatus eq 'Processing' and Timestamp le datetime'$15MinutesAgo')) and Timestamp ge datetime'$1DayAgo'" | Sort-Object Timestamp
20+
$PendingQueries = Get-CIPPAzDataTableEntity @AuditLogSearchesTable -Filter "PartitionKey eq 'Search' and Tenant eq '$TenantFilter' and (CippStatus eq 'Pending' or (CippStatus eq 'Processing' and Timestamp le datetime'$15MinutesAgo')) and Timestamp ge datetime'$1DayAgo'" | Sort-Object Timestamp
21+
} else {
22+
$7DaysAgo = (Get-Date).AddDays(-7).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
23+
$PendingQueries = Get-CIPPAzDataTableEntity @AuditLogSearchesTable -Filter "Tenant eq '$TenantFilter' and Timestamp ge datetime'$7DaysAgo'"
24+
}
2225

23-
$BulkRequests = foreach ($PendingQuery in $PendingQueries) {
24-
@{
25-
id = $PendingQuery.RowKey
26-
url = 'security/auditLog/queries/' + $PendingQuery.RowKey
27-
method = 'GET'
28-
}
26+
$BulkRequests = foreach ($PendingQuery in $PendingQueries) {
27+
@{
28+
id = $PendingQuery.RowKey
29+
url = 'security/auditLog/queries/' + $PendingQuery.RowKey
30+
method = 'GET'
2931
}
30-
if ($BulkRequests.Count -eq 0) {
31-
return @()
32-
}
33-
$Queries = New-GraphBulkRequest -Requests @($BulkRequests) -AsApp $true -TenantId $TenantFilter | Select-Object -ExpandProperty body
32+
}
33+
if ($BulkRequests.Count -eq 0) {
34+
return @()
35+
}
36+
$Queries = New-GraphBulkRequest -Requests @($BulkRequests) -AsApp $true -TenantId $TenantFilter | Select-Object -ExpandProperty body
37+
38+
if ($ReadyToProcess.IsPresent) {
3439
$Queries = $Queries | Where-Object { $PendingQueries.RowKey -contains $_.id -and $_.status -eq 'succeeded' }
35-
} else {
36-
$Queries = New-GraphGetRequest -uri 'https://graph.microsoft.com/beta/security/auditLog/queries' -AsApp $true -tenantid $TenantFilter
3740
}
41+
3842
return $Queries
3943
}

Modules/CIPPCore/Public/AuditLogs/New-CippAuditLogSearch.ps1

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,26 @@ function New-CippAuditLogSearch {
157157
if ($PSCmdlet.ShouldProcess('Create a new audit log search for tenant ' + $TenantFilter)) {
158158
$Query = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/security/auditLog/queries' -body ($SearchParams | ConvertTo-Json -Compress) -tenantid $TenantFilter -AsApp $true
159159

160+
160161
if ($ProcessLogs.IsPresent -and $Query.id) {
161-
$Entity = [PSCustomObject]@{
162-
PartitionKey = [string]'Search'
163-
RowKey = [string]$Query.id
164-
Tenant = [string]$TenantFilter
165-
DisplayName = [string]$DisplayName
166-
StartTime = [datetime]$StartTime.ToUniversalTime()
167-
EndTime = [datetime]$EndTime.ToUniversalTime()
168-
Query = [string]($Query | ConvertTo-Json -Compress)
169-
CippStatus = [string]'Pending'
170-
}
171-
$Table = Get-CIPPTable -TableName 'AuditLogSearches'
172-
Add-CIPPAzDataTableEntity @Table -Entity $Entity -Force | Out-Null
162+
$CippStatus = 'Pending'
163+
} else {
164+
$CippStatus = 'N/A'
165+
}
166+
167+
$Entity = [PSCustomObject]@{
168+
PartitionKey = [string]'Search'
169+
RowKey = [string]$Query.id
170+
Tenant = [string]$TenantFilter
171+
DisplayName = [string]$DisplayName
172+
StartTime = [datetime]$StartTime.ToUniversalTime()
173+
EndTime = [datetime]$EndTime.ToUniversalTime()
174+
Query = [string]($Query | ConvertTo-Json -Compress)
175+
CippStatus = [string]$CippStatus
173176
}
177+
$Table = Get-CIPPTable -TableName 'AuditLogSearches'
178+
Add-CIPPAzDataTableEntity @Table -Entity $Entity -Force | Out-Null
179+
174180
return $Query
175181
}
176182
}

Modules/CIPPCore/Public/CippQueue/Invoke-ListCippQueue.ps1

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,22 @@ function Invoke-ListCippQueue {
1212
Write-LogMessage -headers $Request.Headers -API $APINAME -message 'Accessed this API' -Sev 'Debug'
1313
}
1414

15+
$QueueId = $Request.Query.QueueId
16+
1517
$CippQueue = Get-CippTable -TableName 'CippQueue'
1618
$CippQueueTasks = Get-CippTable -TableName 'CippQueueTasks'
1719
$3HoursAgo = (Get-Date).ToUniversalTime().AddHours(-3).ToString('yyyy-MM-ddTHH:mm:ssZ')
18-
$CippQueueData = Get-CIPPAzDataTableEntity @CippQueue -Filter "PartitionKey eq 'CippQueue' and Timestamp ge datetime'$3HoursAgo'" | Sort-Object -Property Timestamp -Descending
20+
21+
if ($QueueId) {
22+
$Filter = "PartitionKey eq 'CippQueue' and RowKey eq '$QueueId'"
23+
} else {
24+
$Filter = "PartitionKey eq 'CippQueue' and Timestamp ge datetime'$3HoursAgo'"
25+
}
26+
27+
$CippQueueData = Get-CIPPAzDataTableEntity @CippQueue -Filter $Filter | Sort-Object -Property Timestamp -Descending
1928

2029
$QueueData = foreach ($Queue in $CippQueueData) {
21-
$Tasks = Get-CIPPAzDataTableEntity @CippQueueTasks -Filter "PartitionKey eq 'Task' and QueueId eq '$($Queue.RowKey)'" | Where-Object { $_.Name } | Select-Object @{n = 'Timestamp'; exp = { $_.Timestamp.DateTime.ToUniversalTime() } }, Name, Status
30+
$Tasks = Get-CIPPAzDataTableEntity @CippQueueTasks -Filter "PartitionKey eq 'Task' and QueueId eq '$($Queue.RowKey)'" | Where-Object { $_.Name } | Select-Object @{n = 'Timestamp'; exp = { $_.Timestamp } }, Name, Status
2231
$TaskStatus = @{}
2332
$Tasks | Group-Object -Property Status | ForEach-Object {
2433
$TaskStatus.$($_.Name) = $_.Count
@@ -54,9 +63,9 @@ function Invoke-ListCippQueue {
5463
PercentComplete = [math]::Round(((($TotalCompleted + $TotalFailed) / $Queue.TotalTasks) * 100), 1)
5564
PercentFailed = [math]::Round((($TotalFailed / $Queue.TotalTasks) * 100), 1)
5665
PercentRunning = [math]::Round((($TotalRunning / $Queue.TotalTasks) * 100), 1)
57-
Tasks = @($Tasks)
66+
Tasks = @($Tasks | Sort-Object -Descending Timestamp)
5867
Status = $Queue.Status
59-
Timestamp = $Queue.Timestamp.DateTime.ToUniversalTime()
68+
Timestamp = $Queue.Timestamp
6069
}
6170

6271
}

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Graph Requests/Push-ListGraphRequestQueue.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ function Push-ListGraphRequestQueue {
3535
ReverseTenantLookupProperty = $Item.ReverseTenantLookupProperty
3636
ReverseTenantLookup = $Item.ReverseTenantLookup
3737
AsApp = $Item.AsApp ?? $false
38+
Caller = 'Push-ListGraphRequestQueue'
3839
SkipCache = $true
3940
}
4041

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ListGraphRequest.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function Invoke-ListGraphRequest {
8181
}
8282

8383
if ($Request.Query.manualPagination) {
84-
$GraphRequestParams.NoPagination = [System.Boolean]$Request.Query.manualPagination
84+
$GraphRequestParams.ManualPagination = [System.Boolean]$Request.Query.manualPagination
8585
}
8686

8787
if ($Request.Query.nextLink) {
@@ -139,7 +139,7 @@ function Invoke-ListGraphRequest {
139139
if ($Results.Queued -eq $true) {
140140
$Metadata.Queued = $Results.Queued
141141
$Metadata.QueueMessage = $Results.QueueMessage
142-
$Metadata.QueuedId = $Results.QueueId
142+
$Metadata.QueueId = $Results.QueueId
143143
$Results = @()
144144
}
145145
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Administration/Invoke-ListMailboxRules.ps1

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ListMailboxRules {
3+
function Invoke-ListMailboxRules {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -28,18 +28,15 @@ Function Invoke-ListMailboxRules {
2828

2929
$Metadata = @{}
3030
# If a queue is running, we will not start a new one
31-
if ($RunningQueue) {
31+
if ($RunningQueue -and !$Rows) {
3232
$Metadata = [PSCustomObject]@{
3333
QueueMessage = "Still loading data for $TenantFilter. Please check back in a few more minutes"
34+
QueueId = $RunningQueue.RowKey
3435
}
3536
[PSCustomObject]@{
3637
Waiting = $true
3738
}
3839
} elseif ((!$Rows -and !$RunningQueue) -or ($TenantFilter -eq 'AllTenants' -and ($Rows | Measure-Object).Count -eq 1)) {
39-
# If no rows are found and no queue is running, we will start a new one
40-
$Metadata = [PSCustomObject]@{
41-
QueueMessage = "Loading data for $TenantFilter. Please check back in 1 minute"
42-
}
4340

4441
if ($TenantFilter -eq 'AllTenants') {
4542
$Tenants = Get-Tenants -IncludeErrors | Select-Object defaultDomainName
@@ -49,6 +46,12 @@ Function Invoke-ListMailboxRules {
4946
$Type = $TenantFilter
5047
}
5148
$Queue = New-CippQueueEntry -Name "Mailbox Rules ($Type)" -Reference $QueueReference -TotalTasks ($Tenants | Measure-Object).Count
49+
# If no rows are found and no queue is running, we will start a new one
50+
$Metadata = [PSCustomObject]@{
51+
QueueMessage = "Loading data for $TenantFilter. Please check back in 1 minute"
52+
QueueId = $Queue.RowKey
53+
}
54+
5255
$Batch = $Tenants | Select-Object defaultDomainName, @{Name = 'FunctionName'; Expression = { 'ListMailboxRulesQueue' } }, @{Name = 'QueueName'; Expression = { $_.defaultDomainName } }, @{Name = 'QueueId'; Expression = { $Queue.RowKey } }
5356
if (($Batch | Measure-Object).Count -gt 0) {
5457
$InputObject = [PSCustomObject]@{
@@ -66,6 +69,9 @@ Function Invoke-ListMailboxRules {
6669
$Rows = $Rows | Where-Object -Property Tenant -EQ $TenantFilter
6770
$Rows = $Rows
6871
}
72+
$Metadata = [PSCustomObject]@{
73+
QueueId = $RunningQueue.RowKey ?? $null
74+
}
6975
$GraphRequest = $Rows | ForEach-Object {
7076
$NewObj = $_.Rules | ConvertFrom-Json -ErrorAction SilentlyContinue
7177
$NewObj | Add-Member -NotePropertyName 'Tenant' -NotePropertyValue $_.Tenant -Force

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Email-Exchange/Spamfilter/Invoke-ListMailQuarantine.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function Invoke-ListMailQuarantine {
2929
if ($RunningQueue) {
3030
$Metadata = [PSCustomObject]@{
3131
QueueMessage = 'Still loading data for all tenants. Please check back in a few more minutes'
32+
QueueId = $RunningQueue.RowKey
3233
}
3334
[PSCustomObject]@{
3435
Waiting = $true
@@ -39,6 +40,7 @@ function Invoke-ListMailQuarantine {
3940
$Queue = New-CippQueueEntry -Name 'Mail Quarantine - All Tenants' -Reference $QueueReference -TotalTasks ($TenantList | Measure-Object).Count
4041
$Metadata = [PSCustomObject]@{
4142
QueueMessage = 'Loading data for all tenants. Please check back in a few minutes'
43+
QueueId = $Queue.RowKey
4244
}
4345
$InputObject = [PSCustomObject]@{
4446
OrchestratorName = 'MailQuarantineOrchestrator'
@@ -57,6 +59,9 @@ function Invoke-ListMailQuarantine {
5759
Waiting = $true
5860
}
5961
} else {
62+
$Metadata = [PSCustomObject]@{
63+
QueueId = $RunningQueue.RowKey ?? $null
64+
}
6065
$messages = $Rows
6166
foreach ($message in $messages) {
6267
$messageObj = $message.QuarantineMessage | ConvertFrom-Json

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-ExecJITAdmin.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,15 @@ function Invoke-ExecJITAdmin {
7575
if ($RunningQueue) {
7676
$Metadata = [PSCustomObject]@{
7777
QueueMessage = 'Still loading JIT Admin data for all tenants. Please check back in a few more minutes.'
78+
QueueId = $RunningQueue.RowKey
7879
}
7980
} elseif (!$Rows -and !$RunningQueue) {
8081
$TenantList = Get-Tenants -IncludeErrors
8182
$Queue = New-CippQueueEntry -Name 'JIT Admin List - All Tenants' -Link '/identity/administration/jit-admin?tenantFilter=AllTenants' -Reference $QueueReference -TotalTasks ($TenantList | Measure-Object).Count
8283

8384
$Metadata = [PSCustomObject]@{
8485
QueueMessage = 'Loading JIT Admin data for all tenants. Please check back in a few minutes.'
86+
QueueId = $Queue.RowKey
8587
}
8688
$InputObject = [PSCustomObject]@{
8789
OrchestratorName = 'JITAdminOrchestrator'
@@ -97,6 +99,9 @@ function Invoke-ExecJITAdmin {
9799
}
98100
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress)
99101
} else {
102+
$Metadata = [PSCustomObject]@{
103+
QueueId = $RunningQueue.RowKey ?? $null
104+
}
100105
# There is data in the cache, so we will use that
101106
Write-Information "Found $($Rows.Count) rows in the cache"
102107
foreach ($row in $Rows) {

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Security/Invoke-ExecAlertsList.ps1

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ExecAlertsList {
3+
function Invoke-ExecAlertsList {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -68,6 +68,7 @@ Function Invoke-ExecAlertsList {
6868
if ($RunningQueue) {
6969
$Metadata = [PSCustomObject]@{
7070
QueueMessage = 'Still loading data for all tenants. Please check back in a few more minutes'
71+
QueueId = $RunningQueue.RowKey
7172
}
7273
[PSCustomObject]@{
7374
Waiting = $true
@@ -78,6 +79,7 @@ Function Invoke-ExecAlertsList {
7879
$Queue = New-CippQueueEntry -Name 'Alerts List - All Tenants' -Reference $QueueReference -TotalTasks ($TenantList | Measure-Object).Count
7980
$Metadata = [PSCustomObject]@{
8081
QueueMessage = 'Loading data for all tenants. Please check back in a few minutes'
82+
QueueId = $Queue.RowKey
8183
}
8284
$InputObject = [PSCustomObject]@{
8385
OrchestratorName = 'AlertsOrchestrator'
@@ -97,6 +99,10 @@ Function Invoke-ExecAlertsList {
9799
InstanceId = $InstanceId
98100
}
99101
} else {
102+
$Metadata = [PSCustomObject]@{
103+
QueueId = $RunningQueue.RowKey ?? $null
104+
}
105+
100106
$Alerts = $Rows
101107
$AlertsObj = foreach ($Alert in $Alerts) {
102108
$AlertInfo = $Alert.Alert | ConvertFrom-Json

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Security/Invoke-ExecIncidentsList.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ExecIncidentsList {
3+
function Invoke-ExecIncidentsList {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -52,13 +52,15 @@ Function Invoke-ExecIncidentsList {
5252
if ($RunningQueue) {
5353
$Metadata = [PSCustomObject]@{
5454
QueueMessage = 'Still loading data for all tenants. Please check back in a few more minutes'
55+
QueueId = $RunningQueue.RowKey
5556
}
5657
} elseif (!$Rows -and !$RunningQueue) {
5758
# If no rows are found and no queue is running, we will start a new one
5859
$TenantList = Get-Tenants -IncludeErrors
5960
$Queue = New-CippQueueEntry -Name 'Incidents - All Tenants' -Link '/security/reports/incident-report?customerId=AllTenants' -Reference $QueueReference -TotalTasks ($TenantList | Measure-Object).Count
6061
$Metadata = [PSCustomObject]@{
6162
QueueMessage = 'Loading data for all tenants. Please check back in a few minutes'
63+
QueueId = $Queue.RowKey
6264
}
6365
$InputObject = [PSCustomObject]@{
6466
OrchestratorName = 'IncidentOrchestrator'
@@ -74,6 +76,9 @@ Function Invoke-ExecIncidentsList {
7476
}
7577
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Depth 5 -Compress) | Out-Null
7678
} else {
79+
$Metadata = [PSCustomObject]@{
80+
QueueId = $RunningQueue.RowKey ?? $null
81+
}
7782
$Incidents = $Rows
7883
foreach ($incident in $Incidents) {
7984
$IncidentObj = $incident.Incident | ConvertFrom-Json

0 commit comments

Comments
 (0)