Skip to content

Commit

Permalink
Merge pull request #1179 from JohnDuprey/dev
Browse files Browse the repository at this point in the history
Bugfixes and cleanup
  • Loading branch information
JohnDuprey authored Nov 12, 2024
2 parents 6267eaf + 8a04b30 commit 4e4491c
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ function Get-CippAuditLogSearches {
if ($ReadyToProcess.IsPresent) {
$AuditLogSearchesTable = Get-CippTable -TableName 'AuditLogSearches'
$15MinutesAgo = (Get-Date).AddMinutes(-15).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
$PendingQueries = Get-CIPPAzDataTableEntity @AuditLogSearchesTable -Filter "Tenant eq '$TenantFilter' and (CippStatus eq 'Pending' or (CippStatus eq 'Processing' and Timestamp le datetime'$15MinutesAgo'))" | Sort-Object Timestamp
$1DayAgo = (Get-Date).AddDays(-1).ToUniversalTime().ToString('yyyy-MM-ddTHH:mm:ssZ')
$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

$BulkRequests = foreach ($PendingQuery in $PendingQueries) {
@{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function Push-DomainAnalyserDomain {
param($Item)
$DomainTable = Get-CippTable -tablename 'Domains'
$Filter = "PartitionKey eq 'TenantDomains' and RowKey eq '{0}'" -f $Item.RowKey
$DomainObject = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter
$DomainObject = Get-CIPPAzDataTableEntity @DomainTable -Filter $Filter | Select-Object * -ExcludeProperty table

try {
$ConfigTable = Get-CippTable -tablename Config
Expand Down Expand Up @@ -35,7 +35,7 @@ function Push-DomainAnalyserDomain {
try {
$Tenant = $DomainObject.TenantDetails | ConvertFrom-Json -ErrorAction Stop
} catch {
$Tenant = @{Tenant = 'None' }
$Tenant = @{ Tenant = 'None' }
}

$Result = [PSCustomObject]@{
Expand Down Expand Up @@ -310,7 +310,13 @@ function Push-DomainAnalyserDomain {
$Result.ScorePercentage = [int](($Result.Score / $Result.MaximumScore) * 100)
$Result.ScoreExplanation = ($ScoreExplanation) -join ', '

$DomainObject.DomainAnalyser = (ConvertTo-Json -InputObject $Result -Depth 5 -Compress).ToString()
$Json = (ConvertTo-Json -InputObject $Result -Depth 5 -Compress).ToString()

if ($DomainObject.PSObject.Properties.Name -notcontains 'DomainAnalyser') {
$DomainObject | Add-Member -MemberType NoteProperty -Name DomainAnalyser -Value $Json
} else {
$DomainObject.DomainAnalyser = $Json
}

try {
$DomainTable.Entity = $DomainObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,13 @@ function Invoke-ExecPartnerWebhook {
}
$Results = New-CIPPGraphSubscription @Webhook

if ($Request.Body.standardsExcludeAllTenants -eq $true) {
$ConfigTable = Get-CIPPTable -TableName Config
$PartnerWebhookOnboarding = [PSCustomObject]@{
PartitionKey = 'Config'
RowKey = 'PartnerWebhookOnboarding'
StandardsExcludeAllTenants = $true
}
Add-CIPPAzDataTableEntity @ConfigTable -Entity $PartnerWebhookOnboarding -Force | Out-Null
$ConfigTable = Get-CIPPTable -TableName Config
$PartnerWebhookOnboarding = [PSCustomObject]@{
PartitionKey = 'Config'
RowKey = 'PartnerWebhookOnboarding'
StandardsExcludeAllTenants = $Request.Body.standardsExcludeAllTenants
}
Add-CIPPAzDataTableEntity @ConfigTable -Entity $PartnerWebhookOnboarding -Force | Out-Null
}
'SendTest' {
$Results = New-GraphPOSTRequest -uri 'https://api.partnercenter.microsoft.com/webhooks/v1/registration/validationEvents' -tenantid $env:TenantID -NoAuthCheck $true -scope 'https://api.partnercenter.microsoft.com/.default'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Function Invoke-ExecRestoreBackup {
Write-Host ($line)
$Table = Get-CippTable -tablename $line.table
$ht2 = @{}
$line.psobject.properties | ForEach-Object { $ht2[$_.Name] = [string]$_.Value }
$line.psobject.properties | Where-Object { $_.Name -ne 'table' } | ForEach-Object { $ht2[$_.Name] = [string]$_.Value }
$Table.Entity = $ht2
Add-CIPPAzDataTableEntity @Table -Force

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function Start-DurableCleanup {
param(
[int]$MaxDuration = 3600
)

$WarningPreference = 'SilentlyContinue'
$StorageContext = New-AzStorageContext -ConnectionString $env:AzureWebJobsStorage
$TargetTime = (Get-Date).ToUniversalTime().AddSeconds(-$MaxDuration)
Expand All @@ -30,15 +31,14 @@ function Start-DurableCleanup {
$ClearQueues = $false
$FunctionName = $Table.TableName -replace 'Instances', ''
$Orchestrators = Get-CIPPAzDataTableEntity @Table -Filter "RuntimeStatus eq 'Running'" | Select-Object * -ExcludeProperty Input
$Orchestrators | Where-Object { $_.CreatedTime.DateTime -lt $TargetTime } | ForEach-Object {
$CreatedTime = [DateTime]::SpecifyKind($_.CreatedTime.DateTime, [DateTimeKind]::Utc)
$LongRunningOrchestrators = $Orchestrators | Where-Object { $_.CreatedTime.DateTime -lt $TargetTime }
foreach ($Orchestrator in $LongRunningOrchestrators) {
$CreatedTime = [DateTime]::SpecifyKind($Orchestrator.CreatedTime.DateTime, [DateTimeKind]::Utc)
$TimeSpan = New-TimeSpan -Start $CreatedTime -End (Get-Date).ToUniversalTime()
$RunningDuration = [math]::Round($TimeSpan.TotalMinutes, 2)
Write-Information "Orchestrator: $($_.PartitionKey), created: $CreatedTime, running for: $RunningDuration minutes"
Write-Information "Orchestrator: $($Orchestrator.PartitionKey), created: $CreatedTime, running for: $RunningDuration minutes"
$ClearQueues = $true
$_.RuntimeStatus = 'Failed'
if ($PSCmdlet.ShouldProcess($_.PartitionKey, 'Terminate Orchestrator')) {
$Orchestrator = Get-CIPPAzDataTableEntity @Table -PartitionKey $_.PartitionKey -RowKey $_.RowKey
$Orchestrator.RuntimeStatus = 'Failed'
Update-AzDataTableEntity @Table -Entity $Orchestrator
$CleanupCount++
Expand Down
2 changes: 1 addition & 1 deletion Modules/CIPPCore/Public/New-CIPPBackup.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function New-CIPPBackup {
)
$CSVfile = foreach ($CSVTable in $BackupTables) {
$Table = Get-CippTable -tablename $CSVTable
Get-AzDataTableEntity @Table | Select-Object *, @{l = 'table'; e = { $CSVTable } } -ExcludeProperty DomainAnalyser
Get-AzDataTableEntity @Table | Select-Object * -ExcludeProperty DomainAnalyser, table | Select-Object *, @{l = 'table'; e = { $CSVTable } }
}
$RowKey = 'CIPPBackup' + '_' + (Get-Date).ToString('yyyy-MM-dd-HHmm')
$CSVfile
Expand Down
10 changes: 10 additions & 0 deletions Modules/CippEntrypoints/CippEntrypoints.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ function Receive-CIPPTimerTrigger {
}
}
try {
if ($FunctionStatus.PSObject.Properties.Name -contains 'ErrorMsg') {
$FunctionStatus.ErrorMsg = ''
}
$Results = Invoke-Command -ScriptBlock { & $Function.Command }
if ($Results -match '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$') {
$FunctionStatus.OrchestratorId = $Results
Expand All @@ -229,10 +232,17 @@ function Receive-CIPPTimerTrigger {
}
} catch {
$Status = 'Failed'
$ErrorMsg = $_.Exception.Message
if ($FunctionStatus.PSObject.Properties.Name -contains 'ErrorMsg') {
$FunctionStatus.ErrorMsg = $ErrorMsg
} else {
$FunctionStatus | Add-Member -MemberType NoteProperty -Name ErrorMsg -Value $ErrorMsg
}
Write-Information "Error in CIPPTimer for $($Function.Command): $($_.Exception.Message)"
}
$FunctionStatus.LastOccurrence = $UtcNow
$FunctionStatus.Status = $Status

Add-CIPPAzDataTableEntity @Table -Entity $FunctionStatus -Force
}
}
Expand Down

0 comments on commit 4e4491c

Please sign in to comment.