New Question
 
 
PRTG Network Monitor

Intuitive to Use.
Easy to manage.

200.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free PRTG
Download >>

 

What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

 

Top Tags


View all Tags


@channel with slack webhook

Votes:

0

Your Vote:

Up

Down

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 by  droorda (100) 1 1



Best Answer

Accepted Answer

Votes:

0

Your Vote:

Up

Down

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 by  droorda (100) 1 1



3 Replies

Votes:

0

Your Vote:

Up

Down

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

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



Votes:

0

Your Vote:

Up

Down

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

Votes:

0

Your Vote:

Up

Down

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 by  droorda (100) 1 1



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.