Skip to content

Commit 3ae9bd2

Browse files
committed
Improve webhook URL validation and logging
Replaced empty string checks with IsNullOrWhiteSpace for webhook URLs to ensure more robust validation. Added logging for cases where no webhook URL is configured, and moved the success log message inside the conditional block.
1 parent fff912e commit 3ae9bd2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Modules/CIPPCore/Public/Send-CIPPAlert.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function Send-CIPPAlert {
9595
Write-Information 'Trying to send webhook'
9696

9797
try {
98-
if ($Config.webhook -ne '' -or $AltWebhook -ne '') {
98+
if (![string]::IsNullOrWhiteSpace($Config.webhook) -or ![string]::IsNullOrWhiteSpace($AltWebhook)) {
9999
if ($PSCmdlet.ShouldProcess($Config.webhook, 'Sending webhook')) {
100100
$webhook = if ($AltWebhook) { $AltWebhook } else { $Config.webhook }
101101
switch -wildcard ($webhook) {
@@ -121,8 +121,10 @@ function Send-CIPPAlert {
121121
}
122122
}
123123
}
124+
Write-LogMessage -API 'Webhook Alerts' -message "Sent Webhook alert $title to External webhook" -tenant $TenantFilter -sev info
125+
} else {
126+
Write-LogMessage -API 'Webhook Alerts' -message 'No webhook URL configured' -sev warning
124127
}
125-
Write-LogMessage -API 'Webhook Alerts' -message "Sent Webhook alert $title to External webhook" -tenant $TenantFilter -sev info
126128

127129
} catch {
128130
$ErrorMessage = Get-CippException -Exception $_

0 commit comments

Comments
 (0)