What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

@channel with slack webhook

Votes:

0

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?

prtg slack webhook

Created on May 8, 2019 8:06:10 PM



Best Answer

Accepted Answer

Votes:

0

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;
}

Created on May 9, 2019 3:46:32 PM



3 Replies

Votes:

0

Hi Droorda,

In which fields of PRTG's slack notification do you try to add the <> characters? Does slack accept URL encoding, like %3C@channel%3E ?


Kind regards,
Felix Saure, Tech Support Team

Created on May 9, 2019 7:30:56 AM by  Felix Saure [Paessler Support]



Votes:

0

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

Last change on May 9, 2019 1:22:48 PM by  Erhard Mikulik [Paessler Support]



Accepted Answer

Votes:

0

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;
}

Created on May 9, 2019 3:46:32 PM




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.