diff --git a/Powershell/send-notification/README.md b/Powershell/send-notification/README.md index ac94d2f89bd8b1756cf1a448fabff0c2766f9a0e..4e5829a76b2179066d7f10c9b67c1aba744dc638 100644 --- a/Powershell/send-notification/README.md +++ b/Powershell/send-notification/README.md @@ -1,6 +1,8 @@ -# send-notification Powershell script - +# send-notification Powershell scripts +- ```send-notification.ps1``` : sending a normal notification +- ```send-targeted-notification.ps1``` : sending a targeted notification - Fill ```channelId``` and ```notifications_bearer``` from Notification service information +- Tip: if content encoding is utf8, don't forget ```-encoding utf8``` parameter on ```get-content``` or equivalent. Use corresponding base uri depending on the target infrastructure: - https://notifications.web.cern.ch/api diff --git a/Powershell/send-notification/send-notification-ps1 b/Powershell/send-notification/send-notification.ps1 similarity index 100% rename from Powershell/send-notification/send-notification-ps1 rename to Powershell/send-notification/send-notification.ps1 diff --git a/Powershell/send-notification/send-targeted-notification.ps1 b/Powershell/send-notification/send-targeted-notification.ps1 new file mode 100644 index 0000000000000000000000000000000000000000..9876a3155c54dd8082c01d64a7ed6b2248ee7920 --- /dev/null +++ b/Powershell/send-notification/send-targeted-notification.ps1 @@ -0,0 +1,16 @@ +# Target Notification channel +$notifications_sendapi = "https://notifications.web.cern.ch/api/notifications" +$notifications_bearer = "......." +$channelId = "......" + +[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + +# Targets array +$targetUsers = [System.Collections.ArrayList]::new() +$targetUsers.Add([pscustomobject]@{email = "john.doe@cern.ch" }) + +$Notification = @{ target=$channelId; summary='Title'; priority='NORMAL'; body='description'; targetUsers=$targetUsers } +$Payload = @{ notification=$Notification} +$headers = @{Authorization = "Bearer $notifications_bearer"} +# convertto-json needs -depth parameter in order to convert also the targetUsers array +Invoke-RestMethod -Uri $notifications_sendapi -Method Post -ContentType 'application/json;charset=utf-8' -Headers $headers -Body (ConvertTo-Json $Payload -Depth 10) \ No newline at end of file