Skip to content

Commit

Permalink
Merge pull request KelvinTegelaar#832 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
Dev to hotfix
  • Loading branch information
JohnDuprey authored May 20, 2024
2 parents 277b761 + 8c78d94 commit b160a10
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 57 deletions.
87 changes: 47 additions & 40 deletions Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ function Get-GraphRequestList {
[string]$ReverseTenantLookupProperty = 'tenantId'
)

$SingleTenantThreshold = 8000

$TableName = ('cache{0}' -f ($Endpoint -replace '[^A-Za-z0-9]'))[0..62] -join ''
Write-Information "Table: $TableName"
$Endpoint = $Endpoint -replace '^/', ''
Expand All @@ -86,39 +88,64 @@ function Get-GraphRequestList {
$GraphQuery.Query = $ParamCollection.ToString()
$PartitionKey = Get-StringHash -String (@($Endpoint, $ParamCollection.ToString()) -join '-')
Write-Information "PK: $PartitionKey"

Write-Information ( 'GET [ {0} ]' -f $GraphQuery.ToString())

# Perform $count check before caching
$Count = 0
if ($TenantFilter -ne 'AllTenants') {
$GraphRequest = @{
uri = $GraphQuery.ToString()
tenantid = $TenantFilter
ComplexFilter = $true
}

if ($NoPagination.IsPresent) {
$GraphRequest.noPagination = $NoPagination.IsPresent
}
if ($CountOnly.IsPresent) {
$GraphRequest.CountOnly = $CountOnly.IsPresent
}
if ($NoAuthCheck.IsPresent) {
$GraphRequest.noauthcheck = $NoAuthCheck.IsPresent
}
if ($Parameters.'$count' -and !$SkipCache.IsPresent -and !$NoPagination.IsPresent) {
$Count = New-GraphGetRequest @GraphRequest -CountOnly -ErrorAction Stop
if ($CountOnly.IsPresent) { return $Count }
Write-Information "Total results (`$count): $Count"
}
}

try {
if ($QueueId) {
$Table = Get-CIPPTable -TableName $TableName
$Filter = "QueueId eq '{0}'" -f $QueueId
$Rows = Get-CIPPAzDataTableEntity @Table -Filter $Filter
$Type = 'Queue'
} elseif ($TenantFilter -eq 'AllTenants' -or (!$SkipCache.IsPresent -and !$ClearCache.IsPresent -and !$CountOnly.IsPresent)) {
$Table = Get-CIPPTable -TableName $TableName
$Timestamp = (Get-Date).AddHours(-1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss.fffK')
if ($TenantFilter -eq 'AllTenants') {
$Filter = "PartitionKey eq '{0}' and QueueType eq 'AllTenants' and Timestamp ge datetime'{1}'" -f $PartitionKey, $Timestamp
} else {
$Filter = "PartitionKey eq '{0}' and Tenant eq '{1}' and Timestamp ge datetime'{2}'" -f $PartitionKey, $TenantFilter, $Timestamp
Write-Information "Cached: $(($Rows | Measure-Object).Count) rows (Type: $($Type))"
$QueueReference = '{0}-{1}' -f $TenantFilter, $PartitionKey
$RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -ne 'Completed' -and $_.Status -ne 'Failed' }
} elseif (!$SkipCache.IsPresent -and !$ClearCache.IsPresent -and !$CountOnly.IsPresent) {
if ($TenantFilter -eq 'AllTenants' -or $Count -gt $SingleTenantThreshold) {
$Table = Get-CIPPTable -TableName $TableName
$Timestamp = (Get-Date).AddHours(-1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ss.fffK')
if ($TenantFilter -eq 'AllTenants') {
$Filter = "PartitionKey eq '{0}' and QueueType eq 'AllTenants' and Timestamp ge datetime'{1}'" -f $PartitionKey, $Timestamp
} else {
$Filter = "PartitionKey eq '{0}' and Tenant eq '{1}' and Timestamp ge datetime'{2}'" -f $PartitionKey, $TenantFilter, $Timestamp
}
$Rows = Get-CIPPAzDataTableEntity @Table -Filter $Filter
$Type = 'Cache'
Write-Information "Cached: $(($Rows | Measure-Object).Count) rows (Type: $($Type))"
$QueueReference = '{0}-{1}' -f $TenantFilter, $PartitionKey
$RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -ne 'Completed' -and $_.Status -ne 'Failed' }
}
#Write-Information $Filter
$Rows = Get-CIPPAzDataTableEntity @Table -Filter $Filter
$Type = 'Cache'
} else {
$Type = 'None'
$Rows = @()
}
Write-Information "Cached: $(($Rows | Measure-Object).Count) rows (Type: $($Type))"

$QueueReference = '{0}-{1}' -f $TenantFilter, $PartitionKey
$RunningQueue = Invoke-ListCippQueue | Where-Object { $_.Reference -eq $QueueReference -and $_.Status -ne 'Completed' -and $_.Status -ne 'Failed' }
} catch {
Write-Information $_.InvocationInfo.PositionMessage
}

if ($TenantFilter -ne 'AllTenants' -and $Endpoint -match '%tenantid%') {
Write-Information "Replacing TenantId in endpoint with $TenantFilter"
$TenantId = (Get-Tenants -IncludeErrors | Where-Object { $_.defaultDomainName -eq $TenantFilter -or $_.customerId -eq $TenantFilter }).customerId
$Endpoint = $Endpoint -replace '%tenantid%', $TenantId
$GraphQuery = [System.UriBuilder]('https://graph.microsoft.com/{0}/{1}' -f $Version, $Endpoint)
Expand All @@ -127,6 +154,7 @@ function Get-GraphRequestList {
$ParamCollection.Add($Item.Key, $Item.Value)
}
$GraphQuery.Query = $ParamCollection.ToString()
$GraphRequest.uri = $GraphQuery.ToString()
}

if (!$Rows) {
Expand Down Expand Up @@ -208,31 +236,10 @@ function Get-GraphRequestList {
}
}
default {
$GraphRequest = @{
uri = $GraphQuery.ToString()
tenantid = $TenantFilter
ComplexFilter = $true
}

if ($NoPagination.IsPresent) {
$GraphRequest.noPagination = $NoPagination.IsPresent
}

if ($CountOnly.IsPresent) {
$GraphRequest.CountOnly = $CountOnly.IsPresent
}

if ($NoAuthCheck.IsPresent) {
$GraphRequest.noauthcheck = $NoAuthCheck.IsPresent
}

try {
$QueueThresholdExceeded = $false
if ($Parameters.'$count' -and !$SkipCache -and !$NoPagination) {
$Count = New-GraphGetRequest @GraphRequest -CountOnly -ErrorAction Stop
if ($CountOnly.IsPresent) { return $Count }
Write-Information "Total results (`$count): $Count"
if ($Count -gt 8000) {
if ($Count -gt $singleTenantThreshold) {
$QueueThresholdExceeded = $true
if ($RunningQueue) {
Write-Information 'Queue currently running'
Expand Down
13 changes: 7 additions & 6 deletions Modules/CIPPCore/Public/Standards/Get-CIPPStandards.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ function Get-CIPPStandards {
}
}
}
}
foreach ($Standard in $ComputedStandards.Keys) {
[pscustomobject]@{
Tenant = $Tenant.defaultDomainName
Standard = $Standard
Settings = $ComputedStandards.$Standard

foreach ($Standard in $ComputedStandards.Keys) {
[pscustomobject]@{
Tenant = $Tenant.defaultDomainName
Standard = $Standard
Settings = $ComputedStandards.$Standard
}
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions Modules/CippExtensions/NinjaOne/Get-NinjaOneOrgMapping.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ function Get-NinjaOneOrgMapping {
$Mappings | Add-Member -NotePropertyName $_.RowKey -NotePropertyValue @{ label = "$($_.NinjaOneName)"; value = "$($_.NinjaOne)" }
}
#Get Available Tenants

#Get available Ninja clients
$Table = Get-CIPPTable -TableName Extensionsconfig
$Configuration = ((Get-AzDataTableEntity @Table).config | ConvertFrom-Json -ea stop).NinjaOne


$Token = Get-NinjaOneToken -configuration $Configuration

$After = 0
$PageSize = 1000
$NinjaOrgs = do {
Expand All @@ -29,16 +29,16 @@ function Get-NinjaOneOrgMapping {
$ResultCount = ($Result.id | Measure-Object -Maximum)
$After = $ResultCount.maximum

} while ($ResultCount.count -eq $PageSize)
} while ($ResultCount.count -eq $PageSize)

} catch {
$Message = if ($_.ErrorDetails.Message) {
Get-NormalizedError -Message $_.ErrorDetails.Message
} else {
$_.Exception.message
}
$NinjaOrgs = @(@{ name = $Message })

$NinjaOrgs = @(@{ name = 'Could not get NinjaOne Orgs, check your API credentials and try again.'; value = '-1' })
}

$MappingObj = [PSCustomObject]@{
Expand Down
2 changes: 1 addition & 1 deletion Modules/CippExtensions/Private/Get-HaloMapping.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function Get-HaloMapping {
}

Write-LogMessage -Message "Could not get HaloPSA Clients, error: $Message " -Level Error -tenant 'CIPP' -API 'HaloMapping'
$RawHaloClients = @(@{name = "Could not get HaloPSA Clients, error: $Message" })
$RawHaloClients = @(@{name = "Could not get HaloPSA Clients, error: $Message"; value = '-1' })
}
$HaloClients = $RawHaloClients | ForEach-Object {
[PSCustomObject]@{
Expand Down
2 changes: 1 addition & 1 deletion Scheduler_GetQueue/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ $Tasks = foreach ($Tenant in $Tenants) {
Tag = 'AllTenants'
TenantID = $t.customerId
Type = $Tenant.type
RowKey = $Tenant.RowKey
RowKey = $t.RowKey
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion version_latest.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.7.1
5.7.2

0 comments on commit b160a10

Please sign in to comment.