Can you give an example of how I can create a PowerShell (*.ps1) script to execute custom notifications in PRTG?
How can I use PowerShell scripts with PRTG's 'Execute Program' notification?
Votes:
0
4 Replies
Votes:
0
This article applies to PRTG Network Monitor 12 or later, as well as to previous (deprecated) versions
Demo 'Powershell' Notification for PRTG Network Monitor
PRTG Network Monitor is a network monitoring tool that offers multiple possibilities to send notifications on important events, for example when a device or individual sensors are down, thresholds are breached, devices fail to respond in a timely matter, etc.
If the built-in notification types do not meet your needs PRTG allows you to create your own notification mechanisms using script files like batch files or powershell scripts.
The following powershell demo script has a very basic functionality to demonstrate how powershell scripts work in PRTG. It simply writes the current date/time to a file. You have to pass the filename as parameter to the script. This script may help you troubleshooting your own powershell notifications.
The script must be copied into the notifications\exe sub folder of your PRTG core server program directory (of each node, if in a cluster).
# Demo 'Powershell' Notification for PRTG Network Monitor # Writes current date/time into a file # # How to use it: # # Create a new 'Execute Program' notification in PRTG # and from the 'Program file' drop-down, select 'Demo Exe Notifcation - OutFile.ps1'. # The 'Parameter' section consists of one parameter: # # - Filename # # e.g. # # 'C:\temp\test.txt' # # Note that the directory specified must exist. # Adapt error handling to your needs. # This script comes without any warranty or support. if ($Args.Count -eq 0) { #No Arguments. Filename must be specified. exit 1; }elseif ($Args.Count -eq 1){ $Path = split-path $Args[0]; if (Test-Path $Path) { $Text = Get-Date; $Text | out-File $Args[0]; exit 0; }else { # Directory does not exist. exit 2; } }
Security Issues
It's a good practice to not enter passwords, parameters, etc. directly into your script. Instead, you can use the parameter field in PRTG to hand over these values to your script when calling it.
Information about signing Powershell scripts and the Execution Policy for scripts can be found in the following external resources:
- PowerShell Script Signing
- PowerShell Security
For Powershell notifications, bear in mind, it depends on which version (32bit or 64bit) of the PRTG Core Service is running, if either the 32bit or the 64bit Powershell are used.
Created on Apr 20, 2011 12:42:46 PM by
Daniel Zobel [Product Manager]
Last change on Feb 26, 2014 2:59:30 PM by
Torsten Lindner [Paessler Support]
Votes:
0
Many of the placeholder parameters available to be passed from PRTG to custom notification scripts need to be single-quoted to be passed to the script correctly.
'%location' '%host' '%shortname'
Double-quotes don't seem to work - probably an artifact of whatever command string they're building to execute the script + params.
Votes:
0
Hi,
Is it possible to use the built in SMTP relay server for notifications from a script like this, or does an external SMTP relay server have to be used?
Votes:
0
Hi,
There is no SMTP relay used, the PowerShell will be executed on the PRTG Core Server itself.
Add comment