I want to send notifications about alarms in PRTG to the messaging app Slack. How can I do this?
How can PRTG send notifications to Slack?
Votes:
0
13 Replies
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:
- Download the script depending on your desired method.
- Save the script file into the \Notifications\EXE subfolder of your PRTG installation.
- Create a new notification in PRTG and choose the script from the Program File list in section Execute Program.
- Adjust the Parameter field as documented on GitHub, depending on the script you use.
- 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.
# ---------------------------------------------------------------------------------------------- # 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
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
Votes:
0
There's now PowerShell V2 versions of the scrips for those not upgraded to v3/v4/v5 yet:
Votes:
0
Thanks for sharing, Mattias!
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?
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
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...
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
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.
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
Votes:
0
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.
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
Add comment