From 03ae7d095da51eb4627f0ba2a585f4d57402c052 Mon Sep 17 00:00:00 2001 From: Nikita Bykov Date: Wed, 18 Aug 2021 17:43:15 +0300 Subject: [PATCH] add script for slack notification --- .../send-slack-notification-failure.ps1 | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 get-new-tool-versions/send-slack-notification-failure.ps1 diff --git a/get-new-tool-versions/send-slack-notification-failure.ps1 b/get-new-tool-versions/send-slack-notification-failure.ps1 new file mode 100644 index 0000000..2c416ac --- /dev/null +++ b/get-new-tool-versions/send-slack-notification-failure.ps1 @@ -0,0 +1,60 @@ +<# +.SYNOPSIS +Sending messages using Incoming Webhooks + +.PARAMETER Url +Required parameter. Incoming Webhook URL to post a message +.PARAMETER ToolName +Required parameter. The name of tool +.PARAMETER ToolVersion +Required parameter. Specifies the version of tool +.PARAMETER PipelineUrl +Required parameter. The pipeline URL +.PARAMETER ImageUrl +Optional parameter. The image URL +#> + +param( + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [System.Uri]$Url, + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [System.String]$ToolName, + + [Parameter(Mandatory)] + [ValidateNotNullOrEmpty()] + [System.String]$ToolVersion, + + [System.String]$PipelineUrl, + [System.String]$ImageUrl = 'https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png' +) + +# Import helpers module +Import-Module $PSScriptRoot/helpers.psm1 -DisableNameChecking + +# Create JSON body +$text = "Some jobs were not successful for the following detection pipelines of '$ToolName'\nLink to the pipeline: '$pipelineUrl'" + +$jsonBodyMessage = @" +{ + "blocks": [ + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": "$text" + }, + "accessory": { + "type": "image", + "image_url": "$imageUrl", + "alt_text": "$toolName" + } + } + ] +} +"@ + +# Send Slack message +$null = Send-SlackPostMessageIncomingWebHook -Uri $url -Body $jsonBodyMessage