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

How can PRTG send notifications to Slack?

Votes:

0

I want to send notifications about alarms in PRTG to the messaging app Slack. How can I do this?

custom custom-notification execute-program notifcations prtg script slack

Created on Sep 8, 2015 2:09:52 PM by  Gerald Schoch [Paessler Support]



13 Replies

Accepted Answer

Votes:

0

This article applies as of PRTG 15


Note: As of PRTG 18.3.42, PRTG comes with native Slack integration out of the box.


Sending Notifications from PRTG to a Slack Channel

PRTG provides various options to notify you about alarms in your network. The most common ones are emails, SMS text messages, and push notifications, but you can also create custom notifications. For example, write a small program that PRTG executes if a notification is triggered. This way it is possible to perform an action like a service restart, or you can get notifications on almost any platform (as long as this platform provides some access like a public API).

Custom Script for Notifications to Slack

One of our customers created a PowerShell script that PRTG can use to show notifications in your Slack channel. PRTG can execute the script in case of alarms in your network using the notification type Execute Program. Each time the notification is triggered, PRTG runs this script which sends then the notification to Slack, using the Slack API. This way, you can see any alarms in PRTG which trigger a notification in the defined Slack channel.

Using PRTG Slack Notifications

The customer provides two scripts on GitHub for using PRTG notifications with Slack:

  • PRTGSlackNotification.ps1 uses a user token that you can find on the Slack Web API page.
  • PRTGSlackWebHookNotification.ps1 uses a web hook that you can define on the WebHook page in your Slack account.

Decide which method you prefer and follow the steps below:

  1. Download the script depending on your desired method.
  2. Save the script file into the \Notifications\EXE subfolder of your PRTG installation.
  3. Create a new notification in PRTG and choose the script from the Program File list in section Execute Program.
  4. Adjust the Parameter field as documented on GitHub, depending on the script you use.
  5. Add triggers that use this notification.

For detailed instructions, please see WCOMAB/PRTGSlackNotification on GitHub. Thank you WCOM AB for sharing the scripts!

Note: Please understand that we cannot provide any support for custom notifications.

Created on Sep 8, 2015 2:14:15 PM by  Gerald Schoch [Paessler Support]

Last change on Jun 30, 2023 10:27:06 AM by  Jacqueline Conforti [Paessler Support]



Votes:

7

I have made some cosmetic changes to the Slack message formatting for the WebHook Notification. I took the icon url out of the post, and added it as the icon of the webhook integration in #prtg

You'll need to add two more variables to the Parameter list.

$ColorofState and $LinkSensor

The second smudged text is Device.

Formatted message with attachments

# ----------------------------------------------------------------------------------------------
# Copyright (c) WCOM AB 2015.
# ----------------------------------------------------------------------------------------------
# This source code is subject to terms and conditions of the The MIT License (MIT)
# copy of the license can be found in the LICENSE file at the root of this distribution.
# ----------------------------------------------------------------------------------------------
# You must not remove this notice, or any other, from this software.
# ----------------------------------------------------------------------------------------------
Param(
    [string]$SlackWebHook,
    [string]$SlackChannel,
    [string]$SiteName,
    [string]$Device,
    [string]$Name,
    [string]$Status,
    [string]$Down,
    [string]$DateTime,
    [string]$LinkDevice,
    [string]$Message,
    [string]$ColorofState,
    [string]$LinkSensor	
)


$postSlackMessage = @{
    channel      = $SlackChannel
    unfurl_links = 'true'
    username     = $sitename
	#text 		= "> Timestamp: $DateTime" 
	text 		= "> *New notification* for <$($LinkDevice)|$($Device)>" 
	attachments	 = @( @{
	    #pretext     = "New notification for <$($LinkDevice)|$($Device)>"
	    pretext     = "Timestamp: $DateTime"
		fallback 	= "New notification for $($Device) - $($Name) is $($Status) $($Down). $($LinkDevice)"
        title 		= "${Name}: Status $($Status) $($Down)"
        title_link 	= $LinkSensor
        color 		= $ColorofState
        text 		= $Message
	} )
} | ConvertTo-Json -Depth 2
$postSlackMessage | Out-File -FilePath slack.log
$postSlackMessage.text  | Out-File -FilePath slack.log -Append
Invoke-RestMethod -Method Post -ContentType 'application/json' -Uri $SlackWebHook -Body $postSlackMessage  | Out-File -FilePath slack.log -Append

Created on Dec 2, 2015 10:17:16 AM



Votes:

0

You could also use connect to do it. It might be easier since it doesn't require any additional scripts. See https://connect.x-formation.com/blog/2016/04/how-monitor-health-your-network-receiving-automatic-prtg-notifications-hipchat#article

Created on May 26, 2016 5:07:44 PM



Votes:

0

There's now PowerShell V2 versions of the scrips for those not upgraded to v3/v4/v5 yet:

PRTGSlackNotificationPSv2.ps1

PRTGSlackWebHookNotificationPSv2.ps1

Created on Aug 2, 2016 1:42:26 PM



Votes:

0

Thanks for sharing, Mattias!

Created on Aug 3, 2016 10:27:55 AM by  Gerald Schoch [Paessler Support]



Votes:

0

Awesome script I've been looking for something like this. I am having trouble getting PRTG to run the script though. If I run it directly from powershell it will send the notification to Slack but when I try and run the test from PRTG nothing happens. Any ideas?

Created on Dec 29, 2016 4:24:58 PM



Votes:

0

Hi mbarry,

This might be caused by insufficient access rights of the PRTG Core Server Service. Try to open the services.msc and change the logon user for the mentioned service to an administrative, preferable Domain Admin account.

Does the notification work then?

Best regards, Felix

Created on Dec 29, 2016 9:29:20 PM by  Felix Saure [Paessler Support]



Votes:

5

This is our version of the script - we are using the #colorstatus as well to determine to current issue and we are using actually icons to show the status - this is working pretty well for us. Besides that, reformatted the whole notification a bit so it is easier to read...

Simple Slack example

It is easy to adjust and even use additional statuses/color-codes if needed..

# ----------------------------------------------------------------------------------------------
# Copyright (c) WCOM AB 2016.
# ----------------------------------------------------------------------------------------------
# This source code is subject to terms and conditions of the The MIT License (MIT)
# copy of the license can be found in the LICENSE file at the root of this distribution.
# ----------------------------------------------------------------------------------------------
# You must not remove this notice, or any other, from this software.
# ----------------------------------------------------------------------------------------------
Param(
    [string]$SlackWebHook,
    [string]$SlackChannel,
    [string]$SiteName,
    [string]$Device,
    [string]$Name,
    [string]$Status,
    [string]$Down,
    [string]$DateTime,
    [string]$LinkDevice,
    [string]$Message,
    [string]$Color
)
string $StatusIcon
string $SlackTextFormatting

Switch ($Color)
{
    '#b4cc38'
    {
        #UP
        $StatusIcon = ':white_check_mark:'
        $SlackTextFormatting = '*'
    }
    '#d71920'
    {
        #DOWN
        $StatusIcon = ':name_badge:'
        $SlackTextFormatting = '`'
    }
    '#ffcb05'
    {
        #WARNING
        $StatusIcon = ':radioactive_sign:'
        $SlackTextFormatting = '`'
    }
    '#447fc1'
    {
        #PAUSE
        $StatusIcon = ':double_vertical_bar:'
        $SlackTextFormatting = '~'
    }
    default 
    {
        $StatusIcon = ':interrobang:'
    }
}


Add-Type -AssemblyName System.Web.Extensions
function ConvertTo-Json ([Object] $value)
{
    [System.Web.Script.Serialization.JavaScriptSerializer] $jsSerializer = New-Object 'System.Web.Script.Serialization.JavaScriptSerializer'
    $jsSerializer.Serialize($value)
}

$postSlackMessage = ConvertTo-Json(@{
    channel      = $SlackChannel;
    unfurl_links = "true";
    username     = "PRTG";
    icon_url     = "https://www.paessler.com/common/files/banner/banner_3s_80x80.png"
    text         = "$($StatusIcon) <$($LinkDevice)|$($Device) $SlackTextFormatting$($Name)$SlackTextFormatting> 
>Status *$($Status) $($Down)* on $($DateTime) 
``````$($Message)``````";
    })

$postSlackMessage | Out-File -FilePath slack.log

[System.Net.WebClient] $webclient = New-Object 'System.Net.WebClient'
$webclient.UploadData($SlackWebHook, [System.Text.Encoding]::UTF8.GetBytes($postSlackMessage)) | Out-File -FilePath slack.log -Append

Regards Florian Rossmark

Created on Mar 30, 2017 7:11:21 PM



Votes:

0

Hello,

I am trying to use these scripts to get notifications of PRTG in SLACK, but I am getting errors in many rows of scripts. My PRTG is an old version, so I can't use new WEBHOOK option, that is why trying to use scripts running as .exe. On server(Windows 2016) it is configured to allow ALL scripts to run using Group Policy. So the problem is in script. Also tried to run it on Windows 10, got the same result.

Can you please tell me what is the reason, that these scripts gave an error?? Did these scripts are written for old Windows version with old powershell version?? I am tried to run scripts just changing version of powershell, got the same result.

Maybe a new version of this script announced , please let me know.

Thanks, Hayk.

Created on Nov 28, 2018 3:20:01 PM



Votes:

0

PRTG has native slack notifications in the latest version. Simply update and you can configure it in a notification template :)


PRTG Scheduler | PRTGapi | Feature Requests | WMI Issues | SNMP Issues

Kind regards,
Stephan Linke, Tech Support Team

Created on Nov 28, 2018 3:26:19 PM by  Stephan Linke [Paessler Support]



Votes:

0

Bonus Info: It can also be done with an HTTP Action, see here for details :)

Kind regards,

Erhard

Created on Nov 28, 2018 3:28:41 PM by  Erhard Mikulik [Paessler Support]



Votes:

0

Thanks you for so quick answer!! Execute HTTP Action also does not working.

Did this also mean, that I have an old version ???

Thanks, Hayk.

Created on Nov 28, 2018 4:06:09 PM



Votes:

0

Hello Hayk,

How old is the PRTG version? Also check "Logs | System Events | Notifications" for further details what's going wrong.

Kind regards,

Erhard

Created on Nov 29, 2018 1:38:28 PM by  Erhard Mikulik [Paessler Support]




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.