Skip to content

Commit a65b81a

Browse files
notification fixes
1 parent d2aac3e commit a65b81a

File tree

3 files changed

+61
-28
lines changed

3 files changed

+61
-28
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,21 @@ function Invoke-ExecAddAlert {
1717
$Severity = 'Alert'
1818

1919
$Result = if ($Request.Body.sendEmailNow -or $Request.Body.sendWebhookNow -eq $true -or $Request.Body.writeLog -eq $true -or $Request.Body.sendPsaNow -eq $true) {
20+
$sev = ([pscustomobject]$Request.body.Severity).value -join (',')
21+
if ($Request.body.email -or $Request.body.webhook) {
22+
Write-Host 'found config, setting'
23+
$config = @{
24+
email = $Request.body.email
25+
webhook = $Request.body.webhook
26+
onepertenant = $Request.body.onePerTenant
27+
logsToInclude = $Request.body.logsToInclude
28+
sendtoIntegration = $true
29+
sev = $sev
30+
}
31+
Write-Host "setting notification config to $($config | ConvertTo-Json)"
32+
$Results = Set-cippNotificationConfig @Config
33+
Write-Host $Results
34+
}
2035
$Title = 'CIPP Notification Test'
2136
if ($Request.Body.sendEmailNow -eq $true) {
2237
$CIPPAlert = @{

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecNotificationConfig.ps1

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,16 @@ Function Invoke-ExecNotificationConfig {
1414
$Headers = $Request.Headers
1515
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616

17-
18-
1917
$sev = ([pscustomobject]$Request.body.Severity).value -join (',')
20-
$results = try {
21-
$Table = Get-CIPPTable -TableName SchedulerConfig
22-
$SchedulerConfig = @{
23-
'tenant' = 'Any'
24-
'tenantid' = 'TenantId'
25-
'type' = 'CIPPNotifications'
26-
'schedule' = 'Every 15 minutes'
27-
'Severity' = [string]$sev
28-
'email' = "$($Request.Body.email)"
29-
'webhook' = "$($Request.Body.webhook)"
30-
'onePerTenant' = [boolean]$Request.Body.onePerTenant
31-
'sendtoIntegration' = [boolean]$Request.Body.sendtoIntegration
32-
'includeTenantId' = [boolean]$Request.Body.includeTenantId
33-
'PartitionKey' = 'CippNotifications'
34-
'RowKey' = 'CippNotifications'
35-
}
36-
foreach ($logvalue in [pscustomobject]$Request.body.logsToInclude) {
37-
$SchedulerConfig[([pscustomobject]$logvalue.value)] = $true
38-
}
39-
40-
Add-CIPPAzDataTableEntity @Table -Entity $SchedulerConfig -Force | Out-Null
41-
'Successfully set the configuration'
42-
} catch {
43-
"Failed to set configuration: $($_.Exception.message)"
18+
$config = @{
19+
email = $Request.body.email
20+
webhook = $Request.body.webhook
21+
onepertenant = $Request.body.onePerTenant
22+
logsToInclude = $Request.body.logsToInclude
23+
sendtoIntegration = $Request.body.sendtoIntegration
24+
sev = $sev
4425
}
45-
46-
26+
$Results = Set-cippNotificationConfig @Config
4727
$body = [pscustomobject]@{'Results' = $Results }
4828

4929
# Associate values to output bindings by calling 'Push-OutputBinding'.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
function Set-CIPPNotificationConfig {
2+
[CmdletBinding()]
3+
param (
4+
$email,
5+
$webhook,
6+
$onepertenant,
7+
$logsToInclude,
8+
$sendtoIntegration,
9+
$sev,
10+
$APIName = 'Set Notification Config'
11+
)
12+
13+
$results = try {
14+
$Table = Get-CIPPTable -TableName SchedulerConfig
15+
$SchedulerConfig = @{
16+
'tenant' = 'Any'
17+
'tenantid' = 'TenantId'
18+
'type' = 'CIPPNotifications'
19+
'schedule' = 'Every 15 minutes'
20+
'Severity' = [string]$sev
21+
'email' = "$($email)"
22+
'webhook' = "$($webhook)"
23+
'onePerTenant' = [boolean]$onePerTenant
24+
'sendtoIntegration' = [boolean]$sendtoIntegration
25+
'includeTenantId' = $true
26+
'PartitionKey' = 'CippNotifications'
27+
'RowKey' = 'CippNotifications'
28+
}
29+
foreach ($logvalue in [pscustomobject]$logsToInclude) {
30+
$SchedulerConfig[([pscustomobject]$logvalue.value)] = $true
31+
}
32+
33+
Add-CIPPAzDataTableEntity @Table -Entity $SchedulerConfig -Force | Out-Null
34+
return 'Successfully set the configuration'
35+
} catch {
36+
return "Failed to set configuration: $($_.Exception.message)"
37+
}
38+
}

0 commit comments

Comments
 (0)