We are using Microsoft Teams to communicate. We would like to get PRTG notifications directly in Microsoft Teams just like messages we receive from each other. Can we integrate this client in notification delivery with PRTG?
[IMPLEMENTED] Can I send notifications to Microsoft Teams with PRTG?
Votes:
6
26 Replies
Votes:
2
This article applies to PRTG Network Monitor 16 or later
Native Teams Notifactions in PRTG 18.3.42.1727
Starting with this version, PRTG has native Teams notifications with the same features and more verbose information :)
Sending PRTG Notifications to Microsoft Teams
Yes, this is possible! Microsoft Teams is a group chat client recently introduced. While testing it, we saw that we could push notifications to it using webhooks and PowerShell. You know what this means? Right, you can send PRTG Notifications with your very own Teams bot! Even better, you have access to the sensor, device, and service URL and can acknowledge it right from within the message.
This is how your push notifications can look like:
A new alert
Let your colleagues know that you're working on it:
The up notification
Requirements
- Microsoft Teams installed and running.
- A webhook connector for your channel (see the section Setup below).
- Working PowerShell notifications. See the Paessler Knowledge Base for a Guide for installing PowerShell based sensors.
Setup
- Open the Channel and click the More Options button which appears as three dots at the top right of the window.
- Select Connectors.
- Scroll down to Incoming Webhook and click the Add button.
- Choose a name you like for the connector as well as an image and finally click Create.
- A new unique URI is automatically generated. Copy this URI string into the script where it says
<insert-your-webhook-url>. - Save the script as C:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE\PRTG-Send-MSTeams-Notification.ps1
- Create a new notification that executes the script using the parameters below and configure it as shown:
Parameters
Parameter | Type | Description |
---|---|---|
sensor | String | The name of the sensor |
sensorID | String | The ID of the sensor |
status | String | The current status of the sensor |
message | String | The current message of the sensor |
device | String | The device of the sensor |
since | String | Timestamp when the problem started |
sensorURL | String | The URL of the sensor |
deviceURL | String | The URL of the device |
serviceURL | String | The service URL of the device |
Parameter Example
-sensor '%sensor' -sensorID '%sensorid' -status '%status' -message '%message' -since '%since' -lastup '%lastup' -device '%device' -sensorURL '%linksensor' -deviceURL '%linkdevice' -serviceURL '%serviceurl'
Configuration
In the configuration area of the script, you need to configure the URL to your PRTG server and the webhook you got when you added it (see step 5 from the Setup above).
#PRTG Server $PRTGServer = "" $PRTGUsername = "" $PRTGPasshash = 123456789 # configure this URL to be your actual webhook URL $uri = "<insert-your-webhook-url>"
Version History
Date | Version | Notes |
---|---|---|
December 2nd, 2016 | 1.0 | Initial Release |
November 10th, 2017 | 1.1 | Fixed acknowledge link handling |
Script
# ___ ___ _____ ___ #| _ \ _ \_ _/ __| #| _/ / | || (_ | #|_| |_|_\ |_| \___| # NETWORK MONITOR #------------------- # Description: This notification script will send to your Microsoft Teams Channel # Parameters: # [string]$sensor - the name of the sensor # [string]$sensorid - the id of the sensor # [string]$status - the status # [string]$message - the message of the sensor # [string]$since - the time since the state is like this # [string]$lastup - the time the sensor was up last # [string]$device - the device of the sensor # [string]$sensorURL - the sensor URL so you can access it directly # [string]$deviceURL - the device URL # [string]$serviceURL - the service URL # # Requirements # ------------------ # - Microsoft Teams installed and running # - A webhook connector for your channel (see Setup) # - Working PowerShell notifications - Guide for installing PowerShell based sensors: https://kb.paessler.com/users/my_answers/71356 # # Full installation guide can be found here: https://kb.paessler.com/en/topic/72306 # # Version History # ------------------ # Version Date Notes # 1.1 10/10/2017 Fixed acknowledgement URL handling # 1.0 12/02/2016 Initial Release # # ------------------ # (c) 2016 Stephan Linke | Paessler AG param( [string]$sensor, [int]$sensorid, [string]$status, [string]$message, [string]$device, [string]$since, [string]$lastup, [string]$sensorURL, [string]$deviceURL, [string]$serviceURL ) ################ # Configuration ################ #PRTG Server $PRTGServer = "" $PRTGUsername = "" $PRTGPasshash = 123456789 #Acknowledgement Message for alerts ack'd via Teams $ackmessage = "Problem has been acknowledged via Teams chat." #Directory for logging $logDirectory = "C:\temp\prtg-notifications-msteam.log" # configure this URL to be your actual webhook URL $uri = "<insert-your-webhook-url>" # the acknowledgement URL $ackURL = [string]::Format("{0}/api/acknowledgealarm.htm?id={1}&ackmsg={2}&username={3}&passhash={4}",$PRTGServer,$sensorID,$ackmessage,$PRTGUsername,$PRTGPasshash); # the title of your message, different templates for not up, up and acknowledged if($status -ne "Up") { $title = [string]::Format("{0} on {1} is in a {2} state!", $sensor, $device, $status) } elseif($status -eq "Up") { $title = [string]::Format("{0} on {1} is up again!", $sensor, $device); $ackURL = ""; } elseif($status -eq "Acknowledged") { $title = [string]::Format("The problem with {0} on {1} has been acknowledged.", $sensor, $device); $ackURL = ""; } # accept all HTTPS certificates, necessary for the webhook add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy ######################## $body = ConvertTo-Json -Depth 6 @{ title = $($title) text = " " sections = @( @{ activityTitle = " " activitySubtitle = " " }, @{ title = 'Details' facts = @( @{ name = 'Current State' value = $($status) }, @{ name = 'Message' value = $($message) }, @{ name = 'Since' value =$($since) }, @{ name = 'Last up' value = $($lastup) }, @{ name = 'Sensor' value = $($sensorURL) }, @{ name = 'Device' value = $($deviceURL) }, @{ name = 'Management URL' value = $($serviceURL) } ) potentialAction = @(@{ '@context' = 'http://schema.org' '@type' = 'ViewAction' name = 'Sensor Page' target = @($sensorURL) }, @{ '@context' = 'http://schema.org' '@type' = 'ViewAction' name = 'Device Page' target = @($deviceURL) }, @{ '@context' = 'http://schema.org' '@type' = 'ViewAction' name = 'Service URL' target = @($serviceURL) }, @{ '@context' = 'http://schema.org' '@type' = 'ViewAction' name = 'Acknowledge Alert' target = @($ackURL) } ) } ) } # We need to encode the body with UTF8, otherwise the send might # fail if the messages contain any characters that cannot be converted $enc = [system.Text.Encoding]::UTF8 $encodedBody = $enc.GetBytes($body) try { Invoke-RestMethod -uri $uri -Method Post -body $encodedBody -ContentType 'application/json'; exit 0; } Catch { $ErrorMessage = $_.Exception.Message (Get-Date).ToString() +" - "+ $ErrorMessage | Out-File -FilePath $LogDirectory -Append exit 2; }
Note: The script is provided as is and may or may not work with your installation.
If you need any further customizations for your environment, feel free to implement them. If you encounter any bugs, feel free to share them :)
Credits
Script and installation steps partially taken from Microsoft Technet.
More
- PRTG Manual: How to setup notifications in PRTG
- Paessler Knowledge Base: Send notifications to Slack with PRTG
- Paessler Knowledge Base: Push Notifications From PRTG
- Paessler Knowledge Base: FAQ for Push Notifications and the PRTG Cloud
Created on Dec 8, 2016 3:50:31 PM by
Martina Wittmann [Paessler Support]
Last change on Aug 10, 2018 9:44:22 AM by
Brandy Greger [Paessler Support]
Votes:
0
Just a quick note that you that you are casting %sensorid as an [int] which is causing the script to fail as it's trying to use it as a string.
Changing the parameter from:
param( [string]$sensor, [int]$sensorid, <----------- this here [string]$status, [string]$message, [string]$device, [string]$since, [string]$lastup, [string]$sensorURL, [string]$deviceURL, [string]$serviceURL )
to this:
param( [string]$sensor, [string]$sensorid, <----------- this here [string]$status, [string]$message, [string]$device, [string]$since, [string]$lastup, [string]$sensorURL, [string]$deviceURL, [string]$serviceURL )
Once changed it worked beautifully!
Created on Oct 13, 2017 1:43:28 AM
Last change on Oct 13, 2017 5:58:52 AM by
Stephan Linke [Paessler Support]
Votes:
0
Hi mhouston100,
You're right, thanks for reporting that one. Fixed :)
Kind regards
Stephan Linke, Tech Support Team
Created on Oct 13, 2017 6:01:54 AM by
Stephan Linke [Paessler Support]
Last change on Oct 13, 2017 6:02:55 AM by
Stephan Linke [Paessler Support]
Votes:
0
Heads up - you are missing some quotes around the variable '%sensorid' in the parameter example. This was causing the notification to fail.
Votes:
0
Thanks Dave, I've updated the post accordingly :)
Kind regards
,
Stephan Linke, Tech Support Team
Votes:
0
Is there any way to add the Probe name to these notifications? As we have many remote sites with a Probe for each, we receive alerts like this; "Probe Health (Probe Health) on Probe Device is in a Down state!"
Sorry if questions like these are not allowed here - thanks!
Votes:
0
Hi Pigle,
The probe name can sure be included. The easiest way would be to use -device '[%probe] %device' in the parameter field instead of just -device '%device' :)
Kind regards,
Stephan Linke, Tech Support Team
Votes:
0
Thank you for this! It's working in our Teams, but when I get the push notification on my phone the text just says "card". What do I change to make the notification text the $title?
Votes:
0
Could you post your parameters for the notification, please? And maybe a screenshot of the notification and the teams message itself :)
Kind regards,
Stephan Linke, Tech Support Team
Votes:
0
Hi Stephan, This is the push notification Alan is referring to - it does not present the device. Would be handy if it did.. https://ibb.co/k4TWRm
Votes:
0
As far as I know, you cannot distinct between different devices when triggering notifications. Probably something Microsoft has to change? It probably simply has to do with the type of message I'm using here. Just using text instead of the card may work here?
Kind regards
Stephan Linke, Tech Support Team
Votes:
0
It worked perfectly on our environment, the only thing I haven´t been able to acomplish is to get the same Buttons (sensor, device, service, aknowledge) included into the teams mobile app, I can only get the message of the sensor in MS Teams for Android.
Kind Regards!
Votes:
0
I'll check that tomorrow and let you know the outcome :)
Votes:
0
@arestrepo
I've tested it with the latest iOS version of Teams (1.077.2018053001) and iOS 11.4 (15F79):
Make sure that the URLs posted to the webhook are actually valid and available publicly. Otherwise, they won't appear.
Kind regards,
Stephan Linke, Tech Support Team
Votes:
0
Thank you, I have Checked the URLs and they seemed fine, I ve checked again the Android Teams Notification and it seems like the details window and the buttons were hidden to the right side of the Card, I´ve scrolled the card leftward and it showed me both, details and buttons.
Thank you for your help Stephan!
Votes:
0
Just as an FYI, the current PRTG Preview 18.2.42.1618 now has native Teams notifications with the same features and more verbose information :)
Kind regards,
Stephan Linke, Tech Support Team
Votes:
0
Is the alert acknowledgement credited to the user defined in the script or will PRTG prompt for a login if the user is not already logged into the PRTG server console?
Votes:
0
The former one. But with the latest stable (being available next week), PRTG will feature native Teams notifications, so you might want to use that instead :)
Kind regards,
Stephan Linke, Tech Support Team
Votes:
0
Hello,
I've configured everything as per this guide. MS Teams Channel displays empty notifications like so:
on is in a state! Details Current State Message Since Last up Sensor Device Management URL
And PRTG displays the following error:
- Response not well-formed: "(param : The term 'param' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXE\PRTG-Send-MSTeams-Notification.ps1:38 char:1 + param( + ~~~~ + CategoryInfo : ObjectNotFound: (param:String) [], CommandNotFou ndException + FullyQualifiedErrorId : CommandNotFoundException 1 )" (code: PE132)*
Any suggestions?
Votes:
0
Please use the native notifications as they're implemented in 18.x.3 and above :)
PRTG Scheduler |
PRTGapi |
Feature Requests |
WMI Issues |
SNMP Issues
Kind regards,
Stephan Linke, Tech Support Team
Created on Oct 10, 2018 10:46:38 AM by
Stephan Linke [Paessler Support]
Last change on Oct 10, 2018 11:00:04 AM by
Stephan Linke [Paessler Support]
Votes:
0
I'm sorry but paying thousands of dollars a year for something that can't even send a customizable notification without me having to run a powershell script is ridiculous. You guys need to implement customizable Teams and Slack alerts already, or allow json payloads from your HTTP Execute option.
Votes:
0
Thanks for your input on the matter, most appreciated!
I just want to state that the script was there before we have had the native notification. Due to the nature of it being a script just retrieving values from PRTG, it's more customizable by nature.
With that said, what exactly would you like to see customizable about the notifications, apart from the buttons? Perhaps you could raise a Feature Request so we can see if other customers would like to see this? That'd be great.
Thanks!
With kind regards,
Stephan Linke, Technical Support Team
Created on Oct 15, 2020 6:04:50 AM by
Stephan Linke [Paessler Support]
Last change on Oct 15, 2020 6:10:25 AM by
Stephan Linke [Paessler Support]
Votes:
0
I would like to be able to make the alert as small as possible, down to 1 line even, and have it sent as a 'text' message into Teams as opposed to a 'card' of some kind that takes up a ton of room. I want the ability to send sleek, streamlined messages from PRTG into my chat channels. I hate that these alerts take up so much real estate and are not customizable. For instance I should be able to remove those "Acknowledge" "Scan now" 5 buttons at the bottom of every alert that comes into Teams. It's maddening. Nobody is going to use those buttons, at least not on my team, when all they do is pop up the PRTG web interface.
Votes:
0
So this is more about having a simple variant of the notification, and a complex one? At least that's what I'm taking away from that. Make sure to put it in the feature request. The easiest way to get this right now would be to modify the $body variable and remove the $sections part. The following would basically only post a small post with a title and the ack URL, saving some space within your channel. Let me know if that suits you for the time being ;)
# ___ ___ _____ ___ #| _ \ _ \_ _/ __| #| _/ / | || (_ | #|_| |_|_\ |_| \___| # NETWORK MONITOR #------------------- # Description: This notification script will send to your Microsoft Teams Channel # Parameters: # [string]$sensor - the name of the sensor # [string]$sensorid - the id of the sensor # [string]$status - the status # [string]$message - the message of the sensor # [string]$since - the time since the state is like this # [string]$lastup - the time the sensor was up last # [string]$device - the device of the sensor # [string]$sensorURL - the sensor URL so you can access it directly # [string]$deviceURL - the device URL # [string]$serviceURL - the service URL # # Requirements # ------------------ # - Microsoft Teams installed and running # - A webhook connector for your channel (see Setup) # - Working PowerShell notifications - Guide for installing PowerShell based sensors: https://kb.paessler.com/users/my_answers/71356 # # Full installation guide can be found here: https://kb.paessler.com/en/topic/72306 # # Version History # ------------------ # Version Date Notes # 1.1.1 16/10/2020 This is the short variant of the script, only posting title and Sensor URL. # 1.1 10/10/2017 Fixed acknowledgement URL handling # 1.0 12/02/2016 Initial Release # # ------------------ # (c) 2020 Stephan Linke | Paessler AG param( [string]$sensor, [int]$sensorid, [string]$status, [string]$message, [string]$device, [string]$since, [string]$lastup, [string]$sensorURL, [string]$deviceURL, [string]$serviceURL ) ################ # Configuration ################ #PRTG Server $PRTGServer = "" $PRTGUsername = "" $PRTGPasshash = 123456789 #Acknowledgement Message for alerts ack'd via Teams $ackmessage = "Problem has been acknowledged via Teams chat." #Directory for logging $logDirectory = "C:\temp\prtg-notifications-msteam.log" # configure this URL to be your actual webhook URL $uri = "<insert-your-webhook-url>" # the acknowledgement URL $ackURL = [string]::Format("{0}/api/acknowledgealarm.htm?id={1}&ackmsg={2}&username={3}&passhash={4}",$PRTGServer,$sensorID,$ackmessage,$PRTGUsername,$PRTGPasshash); # the title of your message, different templates for not up, up and acknowledged if($status -ne "Up") { $title = [string]::Format("{0} on {1} is in a {2} state!", $sensor, $device, $status) } elseif($status -eq "Up") { $title = [string]::Format("{0} on {1} is up again!", $sensor, $device); $ackURL = ""; } elseif($status -eq "Acknowledged") { $title = [string]::Format("The problem with {0} on {1} has been acknowledged.", $sensor, $device); $ackURL = ""; } # accept all HTTPS certificates, necessary for the webhook add-type @" using System.Net; using System.Security.Cryptography.X509Certificates; public class TrustAllCertsPolicy : ICertificatePolicy { public bool CheckValidationResult( ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem) { return true; } } "@ [System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy ######################## $body = ConvertTo-Json -Depth 6 @{ title = $($title) text = "Jump to the Sensor: $($sensorURL)" } # We need to encode the body with UTF8, otherwise the send might # fail if the messages contain any characters that cannot be converted $enc = [system.Text.Encoding]::UTF8 $encodedBody = $enc.GetBytes($body) try { Invoke-RestMethod -uri $uri -Method Post -body $encodedBody -ContentType 'application/json'; exit 0; } Catch { $ErrorMessage = $_.Exception.Message (Get-Date).ToString() +" - "+ $ErrorMessage | Out-File -FilePath $LogDirectory -Append exit 2; }
Votes:
0
Could we have an option to change the beaviour of Acknowlegde Alarm from the native Teams notification? The automatic acknowledge indefinitely is dangerous when some of our users click a noisy alert, if we could restrict that to acknowledge for 24 hours hours would be much better
Votes:
0
Hello, I'm afraid to tell you that this behavior cannot be changed.
Add comment