PRTG Notifications for Cisco WebEx Teams

Things slowed down for me quite a bit over the Christmas break so I spent some time working on a rather large project involving PowerShell. It was good to get some more practice scripting and I certainly learnt a lot (and invented some new swear words as well!). The work was done using Visual Studio Code and PowerShell Core 6 and I have to say after getting over a few teething issues I really enjoyed learning these new tools!

A few issues popped up this week involving PRTG and notifications and I was disappointed to see that whilst PRTG has pre canned notification templates for Microsoft Teams and Slack, there is nothing for Cisco WebEx Teams. Time for some scripting!

I have put together a fairly basic PowerShell script that can be used as an “Execute Program” Notification Template. It is very much in development but I will be actively working on this and sharing the changes as I refine it over the coming weeks. I originally wrote the script using PowerShell Core 6 but when I installed it on the PRTG server I had some dramas as it was configured to use PowerShell 5.1 so I had to make a few changes to account for missing cmdlets and parameters. I will be investigating how I can get the PRTG Core service to use PowerShell Core 6 in the not too distant future.

First thing to do is to create a Bot through an existing Cisco WebEx Teams account. This will be used as a Notifier to post messages into Spaces that it has been made a member of. More details are available here.

The important thing is to grab the Access Token that you are issued with when you create the Bot. This is used by the script to authenticate when making REST calls to the Cisco WebEx API.

Copy the script to the /Notifications/EXE sub folder of your PRTG Core server to make it available in the Notification Template – Execute Program – Program File drop down. You will need to change the $AccessToken entry at the top. Future iterations of this script will encrypt this field to keep it safe from prying eyes. You also need to make sure the path for the $DebugLogFilePath entry is valid.

The script takes the Message and Space name as input parameters which you define in the Execute Program section of the Notification Template setup in PRTG. For the Message Parameter, I have currently successfully tested the %device, %name, %status and %down placeholders, I ran into some problems with the %message placeholder which I believe is due to some illegal characters so I will be working on a function to cleanse the input in the future. The Space Parameter is the name of the Space that you wish the posted message to appear in. Your Bot needs to be added as a member of this Space before the script will work.

Example Parameter entry:

-Space 'PRTG Alerts' -Message '%device %name %status %Down'

4 Comments on "PRTG Notifications for Cisco WebEx Teams"


  1. Kirin thank you for your code.

    I have been trying to get this code to work with a Bot I have made however I am unable to get anything from the bot.

    PRTG informs me “Status sending EXE:Ok (Sensor/Source/ID: 3277/0/2)” however I don’t see it in the space I added the BOT to.

    Do you happen to have any insights?

    Reply

  2. Kirin again thank you for your code.

    I was able to get the code to work after adding in a Debug section to output the $Space and $Message variables to further my troubleshooting.

    This is what I added to dump the message to the log to see what was trying to be sent:
    #Write $Space and $Message to $DebugLogFilePath
    try {
    Write-DebugLog “Space used to send notification”
    Write-DebugLog $Space
    Write-DebugLog “Message sent or attempted to send”
    Write-DebugLog $Message
    }
    catch {
    Write-DebugLog “Cannot write message”
    $err=$_
    Write-DebugLog $err.Exception
    }

    I then had an error in the log which was:
    The response content cannot be parsed because the Internet Explorer engine is not available, or Internet Explorer’s first-launch configuration is not complete. Specify the UseBasicParsing parameter and try again.

    To correct this issue I added -UseBasicParsing to the Send-APIRequest function after Invoke-WebRequest. The code is here:
    #API Request Function
    Function Send-APIRequest {
    Param (
    [Parameter(Mandatory=$True)]
    [hashtable]
    $APIQuery
    )
    Invoke-WebRequest @APIQuery -DisableKeepAlive -UseBasicParsing
    }

    I then had a successful test where I was able to use %message in my parameters on PRTG.

    Without your code I would have started at ground zero like you to get this operational.

    Thanks.

    Reply

    1. Nice one Manuel,

      I am glad you got it working.
      I vaguely remember running into this issue early on when configuring our PRTG instance, I believe you can set a Reg key or apply a GPO setting to avoid this error as well.

      Regards
      Kirin

      Reply

  3. Dear Team,

    Thanks for valuable script.

    Since i am a newbie to scripts, can any one help me out to from the below error while executing the same from prtg.

    “System.Net.WebException: The remote server returned an error: (404) Not Found.
    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
    at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()”

    Thanks

    Regards,
    Sathish

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *