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


Can I send notifications to Microsoft Teams with PRTG?

Votes:

6

Your Vote:

Up

Down

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?

custom-script-exe microsoft-teams notifications powershell prtg rest teams

Created on Dec 1, 2016 1:35:44 PM by  Stephan Linke [Paessler Support]

Last change on Dec 8, 2016 3:40:24 PM by  Martina Wittmann [Paessler Support]



20 Replies

Accepted Answer

Votes:

2

Your Vote:

Up

Down

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

A New PRTG Alert in MS Teams Click here to enlarge.

Let your colleagues know that you're working on it:

Tell Your Colleagues Click here to enlarge.

The up notification

Get a PRTG Up Notification in MS Teams Click here to enlarge.

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

  1. Open the Channel and click the More Options button which appears as three dots at the top right of the window.
  2. Select Connectors.
  3. Scroll down to Incoming Webhook and click the Add button.
  4. Choose a name you like for the connector as well as an image and finally click Create.
  5. A new unique URI is automatically generated. Copy this URI string into the script where it says
    <insert-your-webhook-url>.
  6. Save the script as C:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE\PRTG-Send-MSTeams-Notification.ps1
  7. Create a new notification that executes the script using the parameters below and configure it as shown:

Parameters

ParameterTypeDescription
sensorStringThe name of the sensor
sensorIDStringThe ID of the sensor
statusStringThe current status of the sensor
messageStringThe current message of the sensor
deviceStringThe device of the sensor
sinceStringTimestamp when the problem started
sensorURLStringThe URL of the sensor
deviceURLStringThe URL of the device
serviceURLStringThe 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

DateVersionNotes
December 2nd, 20161.0Initial Release
November 10th, 20171.1Fixed 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

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 Mauff [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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 by  mhouston100 (170) 1 2

Last change on Oct 13, 2017 5:58:52 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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

Your Vote:

Up

Down

Heads up - you are missing some quotes around the variable '%sensorid' in the parameter example. This was causing the notification to fail.

Created on Nov 21, 2017 3:05:18 PM by  daverobbins (0)



Votes:

0

Your Vote:

Up

Down

Thanks Dave, I've updated the post accordingly :)


Kind regards
, Stephan Linke, Tech Support Team

Created on Nov 21, 2017 3:47:58 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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!

Created on Nov 21, 2017 10:19:36 PM by  piqle (0) 1



Votes:

0

Your Vote:

Up

Down

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

Created on Nov 22, 2017 6:37:54 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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?

Created on Dec 13, 2017 12:00:10 AM by  Alan Malette (0)



Votes:

0

Your Vote:

Up

Down

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

Created on Dec 13, 2017 7:33:10 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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 Capture

Created on Jan 14, 2018 11:55:07 PM by  tbryant2500 (0)



Votes:

0

Your Vote:

Up

Down

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

Created on Jan 15, 2018 6:51:47 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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!

Created on Jun 14, 2018 8:42:50 PM by  Anderson Restrepo (0) 1



Votes:

0

Your Vote:

Up

Down

I'll check that tomorrow and let you know the outcome :)

Created on Jun 14, 2018 8:50:20 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

@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

Created on Jun 15, 2018 8:30:10 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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!

Created on Jun 27, 2018 4:29:15 PM by  Anderson Restrepo (0) 1



Votes:

0

Your Vote:

Up

Down

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

Created on Jun 28, 2018 6:46:33 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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?

Created on Jul 13, 2018 3:35:11 PM by  alexhoward (0)



Votes:

0

Your Vote:

Up

Down

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

Created on Jul 13, 2018 6:25:32 PM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

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?

Created on Oct 10, 2018 10:36:02 AM by  ITTechW (0)



Votes:

0

Your Vote:

Up

Down

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]



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.