Skip to content

Commit

Permalink
Merge branch 'KelvinTegelaar:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
efiniste authored May 30, 2024
2 parents f2955ff + 494ca06 commit 287c06b
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 74 deletions.
1 change: 0 additions & 1 deletion DomainAnalyser_OrchestrationStarter/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ $InputObject = [PSCustomObject]@{
}
OrchestratorName = 'DomainAnalyser_Tenants'
SkipLog = $true
DurableMode = 'Sequence'
}
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ function Push-DomainAnalyserDomain {
}
} catch {
$Message = 'SPF Error'
Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message $Message -LogData (Get-CippException -Exception $_) -sev Error
throw $Message
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error
return $Message
}

# Check SPF Record
Expand Down Expand Up @@ -185,8 +185,8 @@ function Push-DomainAnalyserDomain {
}
} catch {
$Message = 'DMARC Error'
Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message $Message -LogData (Get-CippException -Exception $_) -sev Error
throw $Message
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error
return $Message
}

# DNS Sec Check
Expand All @@ -203,8 +203,8 @@ function Push-DomainAnalyserDomain {
}
} catch {
$Message = 'DNSSEC Error'
Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message $Message -LogData (Get-CippException -Exception $_) -sev Error
throw $Message
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error
return $Message
}

# DKIM Check
Expand Down Expand Up @@ -232,8 +232,8 @@ function Push-DomainAnalyserDomain {
}
} catch {
$Message = 'DKIM Exception'
Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message $Message -LogData (Get-CippException -Exception $_) -sev Error
throw $Message
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message $Message -LogData (Get-CippException -Exception $_) -sev Error
return $Message
}
# Final Score
$Result.Score = $ScoreDomain
Expand All @@ -248,9 +248,9 @@ function Push-DomainAnalyserDomain {
Add-CIPPAzDataTableEntity @DomainTable -Entity $DomainObject -Force

# Final Write to Output
Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.tenant -message "DNS Analyser Finished For $Domain" -sev Info
Write-LogMessage -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message "DNS Analyser Finished For $Domain" -sev Info
} catch {
Write-LogMessage -API -API 'DomainAnalyser' -tenant $tenant.tenant -message "Error saving domain $Domain to table " -sev Error -LogData (Get-CippException -Exception $_)
Write-LogMessage -API -API 'DomainAnalyser' -tenant $DomainObject.TenantId -message "Error saving domain $Domain to table " -sev Error -LogData (Get-CippException -Exception $_)
}
return $null
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ function Push-DomainAnalyserTenant {
$DomainCount = ($TenantDomains | Measure-Object).Count
if ($DomainCount -gt 0) {
Write-Host "$DomainCount tenant Domains"
$TenantDomainObjects = [System.Collections.Generic.List[object]]::new()
try {
$TenantDomainObjects = foreach ($TenantDomain in $TenantDomains) {
foreach ($TenantDomain in $TenantDomains) {
$TenantDetails = ($TenantDomain | ConvertTo-Json -Compress).ToString()
$Filter = "PartitionKey eq '{0}' and RowKey eq '{1}'" -f $TenantDomain.Tenant, $TenantDomain.Domain
$OldDomain = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter
Expand Down Expand Up @@ -78,19 +79,23 @@ function Push-DomainAnalyserTenant {
}
}
# Return domain object to list
$Domain
$TenantDomainObjects.Add($Domain)
}

# Batch insert tenant domains
try {
Add-CIPPAzDataTableEntity @DomainTable -Entity $TenantDomainObjects -Force
$InputObject = [PSCustomObject]@{
Batch = $TenantDomainObjects | Select-Object RowKey, @{n = 'FunctionName'; exp = { 'DomainAnalyserDomain' } }
QueueFunction = @{
FunctionName = 'GetTenantDomains'
TenantGUID = $Tenant.customerId
}
OrchestratorName = "DomainAnalyser_$($Tenant.defaultDomainName)"
SkipLog = $true
DurableMode = 'Sequence'
}
Start-NewOrchestration -FunctionName 'CIPPOrchestrator' -InputObject ($InputObject | ConvertTo-Json -Compress -Depth 5)
Write-Host "Started analysis for $DomainCount tenant domains in $($Tenant.defaultDomainName)"
Write-LogMessage -API 'DomainAnalyser' -tenant $Tenant.defaultDomainName -message "Started analysis for $DomainCount tenant domains" -sev Info
} catch {
Write-LogMessage -API 'DomainAnalyser' -message 'Domain Analyser GetTenantDomains error' -sev info -LogData (Get-CippException -Exception $_)
}
Expand All @@ -99,7 +104,7 @@ function Push-DomainAnalyserTenant {
}
}
} catch {
Write-Host (Get-CippException -Exception $_ | ConvertTo-Json)
#Write-Host (Get-CippException -Exception $_ | ConvertTo-Json)
Write-LogMessage -API 'DomainAnalyser' -tenant $tenant.defaultDomainName -message 'DNS Analyser GraphGetRequest' -LogData (Get-CippException -Exception $_) -sev Error
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function Push-GetTenantDomains {
Param($Item)
$DomainTable = Get-CippTable -tablename 'Domains'
$Filter = "PartitionKey eq 'TenantDomains' and TenantGUID eq '{0}'" -f $Item.TenantGUID
$Domains = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter -Property RowKey | Select-Object RowKey, @{n = 'FunctionName'; exp = { 'DomainAnalyserDomain' } }
return @($Domains)
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,7 @@ function Push-ExecScheduledCommand {
ScheduledTime = "$nextRunUnixTime"
}
}
Write-LogMessage -API 'Scheduler_UserTasks' -tenant $tenant -message "Successfully executed task: $($task.Name)" -sev Info
if ($TaskType -ne 'Alert') {
Write-LogMessage -API 'Scheduler_UserTasks' -tenant $tenant -message "Successfully executed task: $($task.Name)" -sev Info
}
}
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.3

0 comments on commit 287c06b

Please sign in to comment.