I an trying to figure out how to add user notification to my slack messages, but cannot find a reasonable way to do it. I have attempted to use the "send slack message" but get a clear error that <> characters are not allowed. I have attempted to use the "execute HTTP action" but it just silently changes <@channel> to {@channel} which causes slack to return a 400 error. are there any options other then writing an executable/custom script to send the message?
Best Answer
Accepted Answer
I ended up writing a powershell script to handle the notifications
[CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='Low')] param ( [string]$SlackURI, [string]$colorofstate, [string]$cumsince, [string]$datetime, [string]$device, [string]$down, [string]$downtime, [string]$group, [string]$homeURI, [string]$lastcheck, [string]$lastdown, [string]$lastup, [string]$lastvalue, [string]$message, [string]$name, [string]$probe, [string]$sensorid, [string]$status, [string]$uptime ) #PRTG Param #-SlackURI = 'https://hooks.slack.com/services/xxx/xxx/xxx' -colorofstate '%colorofstate' -cumsince '%cumsince' -datetime '%datetime' -device '%device' -down '%down' -downtime '%downtime' -group '%group' -homeURI '%home' -lastcheck '%lastcheck' -lastdown '%lastdown' -lastup '%lastup' -lastvalue '%lastvalue' -message '%message' -name '%name' -probe '%probe' -sensorid '%sensorid' -status '%status' -uptime '%uptime' $JSON = @" { "text": "$device $status $down ($message)... <!channel>", "link_names": 1, "attachments": [ { "title": "Sensor: $device $name", "title_link": "${homeURI}sensor.htm?id=$sensorid", "text": "*Status:* $status $down \n*Date/Time:* $datetime (UTC) \n*Last Result:* $lastvalue \n*Last Message:* $message \n*Probe:* $probe \n*Group:* $group \n*Device:* $device () \n*Last Scan:* $lastcheck \n*Last Up:* $lastup \n*Last Down:* $lastdown \n*Uptime:* $uptime \n*Downtime:* $downtime \n*Cumulated since:* $cumsince", "color": "$colorofstate", "mrkdwn_in": ["text", "pretext"] } ] } "@ $return = Invoke-WebRequest -UseBasicParsing $SlackURI -ContentType "application/json" -Method POST -Body $JSON if ($return.StatusCode -eq 200) { exit 0; } else { exit $return.StatusCode; }
3 Replies
Hi Droorda,
In which fields of PRTG's slack notification do you try to add the <> characters? Does slack accept URL encoding, like %[email protected]%3E ?
Kind regards,
Felix Saure, Tech Support Team
I was hopeful that slack would handle that, unfortunately it did not decode it. I am adding the text field of the json that is being posted.
{ "text": "%device %status %down (%message)... <!channel>", "link_names": 1, "attachments": [ { "title": "Sensor: %device %name", "title_link": "%homesensor.htm?id=%sensorid", "text": "*Status:* %status %down \n*Date/Time:* %datetime (UTC) \n*Last Result:* %lastvalue \n*Last Message:* %message \n*Probe:* %probe \n*Group:* %group \n*Device:* %device () \n*Last Scan:* %lastcheck \n*Last Up:* %lastup \n*Last Down:* %lastdown \n*Uptime:* %uptime \n*Downtime:* %downtime \n*Cumulated since:* %cumsince", "color": "%colorofstate", "mrkdwn_in": ["text", "pretext"] } ] }
Created on May 9, 2019 1:06:46 PM by
droorda
(100)
●1
●1
Last change on May 9, 2019 1:22:48 PM by
Erhard Mikulik [Paessler Support]
Accepted Answer
I ended up writing a powershell script to handle the notifications
[CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact='Low')] param ( [string]$SlackURI, [string]$colorofstate, [string]$cumsince, [string]$datetime, [string]$device, [string]$down, [string]$downtime, [string]$group, [string]$homeURI, [string]$lastcheck, [string]$lastdown, [string]$lastup, [string]$lastvalue, [string]$message, [string]$name, [string]$probe, [string]$sensorid, [string]$status, [string]$uptime ) #PRTG Param #-SlackURI = 'https://hooks.slack.com/services/xxx/xxx/xxx' -colorofstate '%colorofstate' -cumsince '%cumsince' -datetime '%datetime' -device '%device' -down '%down' -downtime '%downtime' -group '%group' -homeURI '%home' -lastcheck '%lastcheck' -lastdown '%lastdown' -lastup '%lastup' -lastvalue '%lastvalue' -message '%message' -name '%name' -probe '%probe' -sensorid '%sensorid' -status '%status' -uptime '%uptime' $JSON = @" { "text": "$device $status $down ($message)... <!channel>", "link_names": 1, "attachments": [ { "title": "Sensor: $device $name", "title_link": "${homeURI}sensor.htm?id=$sensorid", "text": "*Status:* $status $down \n*Date/Time:* $datetime (UTC) \n*Last Result:* $lastvalue \n*Last Message:* $message \n*Probe:* $probe \n*Group:* $group \n*Device:* $device () \n*Last Scan:* $lastcheck \n*Last Up:* $lastup \n*Last Down:* $lastdown \n*Uptime:* $uptime \n*Downtime:* $downtime \n*Cumulated since:* $cumsince", "color": "$colorofstate", "mrkdwn_in": ["text", "pretext"] } ] } "@ $return = Invoke-WebRequest -UseBasicParsing $SlackURI -ContentType "application/json" -Method POST -Body $JSON if ($return.StatusCode -eq 200) { exit 0; } else { exit $return.StatusCode; }
Please log in or register to enter your reply.
Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.
Add comment