Skip to content

Commit 5579488

Browse files
committed
Fix HaloPSA ticket creation
add _novalidate - thanks to Rewst community Add PSA test option for notification settings
1 parent 02b234e commit 5579488

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

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

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

3-
Function Invoke-ExecAddAlert {
3+
function Invoke-ExecAddAlert {
44
<#
55
.FUNCTIONALITY
66
Entrypoint,AnyTenant
@@ -16,17 +16,17 @@ Function Invoke-ExecAddAlert {
1616

1717
$Severity = 'Alert'
1818

19-
$Result = if ($Request.Body.sendEmailNow -or $Request.Body.sendWebhookNow -eq $true -or $Request.Body.writeLog -eq $true) {
19+
$Result = if ($Request.Body.sendEmailNow -or $Request.Body.sendWebhookNow -eq $true -or $Request.Body.writeLog -eq $true -or $Request.Body.sendPsaNow -eq $true) {
2020
$Title = 'CIPP Notification Test'
21-
if ($Request.Body.sendEmailNow) {
21+
if ($Request.Body.sendEmailNow -eq $true) {
2222
$CIPPAlert = @{
2323
Type = 'email'
2424
Title = $Title
2525
HTMLContent = $Request.Body.text
2626
}
2727
Send-CIPPAlert @CIPPAlert
2828
}
29-
if ($Request.Body.sendWebhookNow) {
29+
if ($Request.Body.sendWebhookNow -eq $true) {
3030
$JSONContent = @{
3131
Title = $Title
3232
Text = $Request.Body.text
@@ -38,7 +38,16 @@ Function Invoke-ExecAddAlert {
3838
}
3939
Send-CIPPAlert @CIPPAlert
4040
}
41-
if ($Request.Body.writeLog) {
41+
if ($Request.Body.sendPsaNow -eq $true) {
42+
$CIPPAlert = @{
43+
Type = 'psa'
44+
Title = $Title
45+
HTMLContent = $Request.Body.text
46+
}
47+
Send-CIPPAlert @CIPPAlert
48+
}
49+
50+
if ($Request.Body.writeLog -eq $true) {
4251
Write-LogMessage -headers $Headers -API 'Alerts' -message $Request.Body.text -Sev $Severity
4352
'Successfully generated alert.'
4453
}

Modules/CIPPCore/Public/Send-CIPPAlert.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ function Send-CIPPAlert {
106106
Write-LogMessage -API 'Webhook Alerts' -message "Could not send alerts to webhook: $($ErrorMessage.NormalizedError)" -tenant $TenantFilter -sev error -LogData $ErrorMessage
107107
}
108108
}
109-
Write-Information 'Trying to send to PSA'
110109

111110
if ($Type -eq 'psa') {
111+
Write-Information 'Trying to send to PSA'
112112
if ($config.sendtoIntegration) {
113113
if ($PSCmdlet.ShouldProcess('PSA', 'Sending alert')) {
114114
try {
@@ -119,7 +119,6 @@ function Send-CIPPAlert {
119119
}
120120
New-CippExtAlert -Alert $Alert
121121
Write-LogMessage -API 'Webhook Alerts' -tenant $TenantFilter -message "Sent PSA alert $title" -sev info
122-
123122
} catch {
124123
$ErrorMessage = Get-CippException -Exception $_
125124
Write-Information "Could not send alerts to ticketing system: $($ErrorMessage.NormalizedError)"

Modules/CippExtensions/Public/Halo/New-HaloPSATicket.ps1

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ function New-HaloPSATicket {
3232
try {
3333
if ($PSCmdlet.ShouldProcess('Add note to HaloPSA ticket', 'Add note')) {
3434
$Action = Invoke-RestMethod -Uri "$($Configuration.ResourceURL)/actions" -ContentType 'application/json; charset=utf-8' -Method Post -Body $body -Headers @{Authorization = "Bearer $($token.access_token)" }
35-
Write-Information "Note added to ticket in HaloPSA: $($Action.id)"
35+
Write-Information "Note added to ticket in HaloPSA: $($ExistingTicket.TicketID)"
3636
}
37-
return
37+
return "Note added to ticket in HaloPSA: $($ExistingTicket.TicketID)"
3838
} catch {
3939
$Message = if ($_.ErrorDetails.Message) {
4040
Get-NormalizedError -Message $_.ErrorDetails.Message
@@ -44,7 +44,7 @@ function New-HaloPSATicket {
4444
Write-LogMessage -message "Failed to add note to HaloPSA ticket: $Message" -API 'HaloPSATicket' -sev Error -LogData (Get-CippException -Exception $_)
4545
Write-Information "Failed to add note to HaloPSA ticket: $Message"
4646
Write-Information "Body we tried to ship: $body"
47-
return
47+
return "Failed to add note to HaloPSA ticket: $Message"
4848
}
4949
}
5050
}
@@ -66,6 +66,7 @@ function New-HaloPSATicket {
6666
details_html = $description
6767
donotapplytemplateintheapi = $true
6868
attachments = @()
69+
_novalidate = $true
6970
}
7071

7172
if ($Configuration.TicketType) {
@@ -93,6 +94,7 @@ function New-HaloPSATicket {
9394
Add-CIPPAzDataTableEntity @TicketTable -Entity $TicketObject -Force
9495
Write-Information 'Ticket added to consolidation table'
9596
}
97+
return "Ticket created in HaloPSA: $($Ticket.id)"
9698
}
9799
} catch {
98100
$Message = if ($_.ErrorDetails.Message) {
@@ -103,5 +105,6 @@ function New-HaloPSATicket {
103105
Write-LogMessage -message "Failed to send ticket to HaloPSA: $Message" -API 'HaloPSATicket' -sev Error -LogData (Get-CippException -Exception $_)
104106
Write-Information "Failed to send ticket to HaloPSA: $Message"
105107
Write-Information "Body we tried to ship: $body"
108+
return "Failed to send ticket to HaloPSA: $Message"
106109
}
107110
}

0 commit comments

Comments
 (0)