Skip to content

Commit 441a910

Browse files
authored
Merge pull request #1142 from JohnDuprey/dev
Bugfixes
2 parents 4720827 + 67c266a commit 441a910

File tree

9 files changed

+62
-32
lines changed

9 files changed

+62
-32
lines changed

CIPPTimers.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
"PreferredProcessor": "auditlog",
2424
"IsSystem": true
2525
},
26+
{
27+
"Command": "Start-ApplicationOrchestrator",
28+
"Description": "Orchestrator to process application uploads",
29+
"Cron": "0 0 */12 * * *",
30+
"Priority": 2,
31+
"RunOnProcessor": true
32+
},
2633
{
2734
"Command": "Start-WebhookOrchestrator",
2835
"Description": "Orchestrator to process webhooks",

Modules/CIPPCore/Public/Entrypoints/Activity Triggers/Push-ExecOnboardTenantQueue.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ Function Push-ExecOnboardTenantQueue {
275275
$Logs.Add([PSCustomObject]@{ Date = Get-Date -UFormat $DateFormat; Log = 'Clearing tenant cache' })
276276
$y = 0
277277
do {
278-
$Tenant = Get-Tenants -TriggerRefresh -IncludeAll | Where-Object { $_.customerId -eq $Relationship.customer.tenantId } | Select-Object -First 1
278+
$Tenant = Get-Tenants -TriggerRefresh -TenantFilter $Relationship.customer.tenantId | Select-Object -First 1
279279
$y++
280280
Start-Sleep -Seconds 20
281281
} while (!$Tenant -and $y -le 10)

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Endpoint/Applications/Invoke-ExecAppUpload.ps1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ function Invoke-ExecAppUpload {
3131
}
3232
}
3333

34-
$Results = [pscustomobject]@{'Results' = 'Started application queue' }
3534
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
3635
StatusCode = [HttpStatusCode]::OK
3736
Body = $Results

Modules/CIPPCore/Public/Entrypoints/Invoke-ListGraphRequest.ps1

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,15 @@ function Invoke-ListGraphRequest {
116116
$GraphRequestParams.AsApp = $true
117117
}
118118

119-
Write-Host ($GraphRequestParams | ConvertTo-Json)
120-
121119
$Metadata = $GraphRequestParams
122120

123121
try {
124122
$Results = Get-GraphRequestList @GraphRequestParams
125-
123+
if ($Results.nextLink -and $Request.Query.NoPagination) {
124+
$Metadata['nextLink'] = $Results.nextLink | Select-Object -Last 1
125+
#Results is an array of objects, so we need to remove the last object before returning
126+
$Results = $Results | Select-Object -First ($Results.Count - 1)
127+
}
126128
if ($Request.Query.ListProperties) {
127129
$Columns = ($Results | Select-Object -First 1).PSObject.Properties.Name
128130
$Results = $Columns | Where-Object { @('Tenant', 'CippStatus') -notcontains $_ }

Modules/CIPPCore/Public/Entrypoints/Orchestrator Functions/Start-ApplicationOrchestrator.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function Start-ApplicationOrchestrator {
77
Param()
88

99
Write-LogMessage -API 'IntuneApps' -message 'Started uploading applications to tenants' -sev Info
10-
10+
Write-Information 'Started uploading applications to tenants'
1111
$InputObject = [PSCustomObject]@{
1212
OrchestratorName = 'ApplicationOrchestrator'
1313
SkipLog = $true

Modules/CIPPCore/Public/Entrypoints/Timer Functions/Start-CIPPProcessorQueue.ps1

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,26 @@ function Start-CIPPProcessorQueue {
1111

1212
foreach ($QueueItem in $QueueItems) {
1313
if ($PSCmdlet.ShouldProcess("Processing function $($QueueItem.ProcessorFunction)")) {
14-
Remove-AzDataTableEntity @QueueTable -Entity $QueueItem
15-
$Parameters = $QueueItem.Parameters | ConvertFrom-Json -AsHashtable
16-
if (Get-Command -Name $QueueItem.FunctionName -Module CIPPCore -ErrorAction SilentlyContinue) {
17-
& $QueueItem.FunctionName @Parameters
14+
Write-Information "Running queued function $($QueueItem.ProcessorFunction)"
15+
if ($QueueItem.Parameters) {
16+
try {
17+
$Parameters = $QueueItem.Parameters | ConvertFrom-Json -AsHashtable
18+
} catch {
19+
$Parameters = @{}
20+
}
21+
} else {
22+
$Parameters = @{}
23+
}
24+
if (Get-Command -Name $QueueItem.ProcessorFunction -Module CIPPCore -ErrorAction SilentlyContinue) {
25+
try {
26+
Invoke-Command -ScriptBlock { & $QueueItem.ProcessorFunction @Parameters }
27+
} catch {
28+
Write-Warning "Failed to run function $($QueueItem.ProcessorFunction). Error: $($_.Exception.Message)"
29+
}
1830
} else {
19-
Write-Warning "Function $($QueueItem.FunctionName) not found"
31+
Write-Warning "Function $($QueueItem.ProcessorFunction) not found"
2032
}
33+
Remove-AzDataTableEntity @QueueTable -Entity $QueueItem
2134
}
2235
}
2336
}

Modules/CIPPCore/Public/GraphHelper/Write-LogMessage.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ function Write-LogMessage {
3535
'Username' = [string]$username
3636
'Severity' = [string]$sev
3737
'SentAsAlert' = $false
38-
'PartitionKey' = $PartitionKey
39-
'RowKey' = ([guid]::NewGuid()).ToString()
38+
'PartitionKey' = [string]$PartitionKey
39+
'RowKey' = [string]([guid]::NewGuid()).ToString()
40+
'FunctionNode' = [string]$env:WEBSITE_SITE_NAME
4041
'LogData' = [string]$LogData
4142
}
4243

Modules/CIPPCore/Public/GraphRequests/Get-GraphRequestList.ps1

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,11 +295,6 @@ function Get-GraphRequestList {
295295
if ($nextLink) { $GraphRequest.uri = $nextLink }
296296

297297
$GraphRequestResults = New-GraphGetRequest @GraphRequest -Caller 'Get-GraphRequestList' -ErrorAction Stop
298-
if ($GraphRequestResults.nextLink) {
299-
#$Metadata['nextLink'] = $GraphRequestResults.nextLink | Select-Object -Last 1
300-
#GraphRequestResults is an array of objects, so we need to remove the last object before returning
301-
$GraphRequestResults = $GraphRequestResults | Select-Object -First ($GraphRequestResults.Count - 1)
302-
}
303298
$GraphRequestResults = $GraphRequestResults | Select-Object *, @{n = 'Tenant'; e = { $TenantFilter } }, @{n = 'CippStatus'; e = { 'Good' } }
304299

305300
if ($ReverseTenantLookup -and $GraphRequestResults) {

Modules/CippExtensions/Public/NinjaOne/Invoke-NinjaOneDeviceWebhook.ps1

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ function Invoke-NinjaOneDeviceWebhook {
55
$Configuration
66
)
77
try {
8-
Write-LogMessage -user $ExecutingUser -API $APIName -message "Webhook Recieved - Updating NinjaOne Device compliance for $($Data.resourceData.id) in $($Data.tenantId)" -Sev 'Info' -tenant $TenantFilter
98
$MappedFields = [pscustomobject]@{}
109
$CIPPMapping = Get-CIPPTable -TableName CippMapping
1110
$Filter = "PartitionKey eq 'NinjaOneFieldMapping'"
@@ -14,6 +13,7 @@ function Invoke-NinjaOneDeviceWebhook {
1413
}
1514

1615
if ($MappedFields.DeviceCompliance) {
16+
Write-LogMessage -user $ExecutingUser -API $APIName -message "Webhook Recieved - Updating NinjaOne Device compliance for $($Data.resourceData.id) in $($Data.tenantId)" -Sev 'Info' -tenant $TenantFilter
1717
$tenantfilter = $Data.tenantId
1818
$M365DeviceID = $Data.resourceData.id
1919

@@ -24,23 +24,36 @@ function Invoke-NinjaOneDeviceWebhook {
2424
$Device = Get-CIPPAzDataTableEntity @DeviceMapTable -Filter $DeviceFilter
2525

2626
if (($Device | Measure-Object).count -eq 1) {
27-
$Token = Get-NinjaOneToken -configuration $Configuration
27+
try {
28+
$Token = Get-NinjaOneToken -configuration $Configuration
2829

29-
if ($DeviceM365.isCompliant -eq $True) {
30-
$Compliant = 'Compliant'
31-
} else {
32-
$Compliant = 'Non-Compliant'
33-
}
34-
35-
$ComplianceBody = @{
36-
"$($MappedFields.DeviceCompliance)" = $Compliant
37-
} | ConvertTo-Json
30+
if (!$Token.access_token) {
31+
Write-LogMessage -API 'NinjaOneSync' -tenant $tenantfilter -user 'CIPP' -message 'Failed to get NinjaOne Token for Device Compliance Update' -Sev 'Error'
32+
return
33+
}
3834

39-
$Null = Invoke-WebRequest -Uri "https://$($Configuration.Instance)/api/v2/device/$($Device.NinjaOneID)/custom-fields" -Method PATCH -Body $ComplianceBody -Headers @{Authorization = "Bearer $($token.access_token)" } -ContentType 'application/json'
35+
if ($DeviceM365.isCompliant -eq $True) {
36+
$Compliant = 'Compliant'
37+
} else {
38+
$Compliant = 'Non-Compliant'
39+
}
4040

41-
Write-Host 'Updated NinjaOne Device Compliance'
41+
$ComplianceBody = @{
42+
"$($MappedFields.DeviceCompliance)" = $Compliant
43+
} | ConvertTo-Json
4244

45+
$Null = Invoke-WebRequest -Uri "https://$($Configuration.Instance)/api/v2/device/$($Device.NinjaOneID)/custom-fields" -Method PATCH -Body $ComplianceBody -Headers @{Authorization = "Bearer $($token.access_token)" } -ContentType 'application/json'
4346

47+
Write-Host 'Updated NinjaOne Device Compliance'
48+
} catch {
49+
$Message = if ($_.ErrorDetails.Message) {
50+
Get-NormalizedError -Message $_.ErrorDetails.Message
51+
} else {
52+
$_.Exception.message
53+
}
54+
Write-Error "Failed NinjaOne Device Webhook for: $($Data | ConvertTo-Json -Depth 100) Linenumber: $($_.InvocationInfo.ScriptLineNumber) Error: $Message"
55+
Write-LogMessage -API 'NinjaOneSync' -user 'CIPP' -message "Failed NinjaOne Device Webhook Linenumber: $($_.InvocationInfo.ScriptLineNumber) Error: $Message" -Sev 'Error'
56+
}
4457
} else {
4558
Write-LogMessage -API 'NinjaOneSync' -user 'CIPP' -message "$($DeviceM365.displayName) ($($M365DeviceID)) was not matched in Ninja for $($tenantfilter)" -Sev 'Info'
4659
}
@@ -59,4 +72,4 @@ function Invoke-NinjaOneDeviceWebhook {
5972

6073

6174

62-
}
75+
}

0 commit comments

Comments
 (0)