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


Guide for PowerShell-based Custom sensors

Votes:

2

Your Vote:

Up

Down

I have a PowerShell script either from the Knowledge Base, from Support, or from somewhere on the internet. I am a bit lost, though. How do I install this and what do I need to do to get it to work properly?

console executionpolicy powershell script sensors

Created on Sep 22, 2016 7:52:27 AM by  Stephan Linke [Paessler Support]

Last change on Sep 12, 2019 5:01:33 AM by  Maike Behnsen [Paessler Support]



6 Replies

Accepted Answer

Votes:

3

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 19 or later

Guide for PowerShell-Based Custom Sensors

For the installation of PowerShell scripts in PRTG, follow these steps:

1. Configure the Execution Policy of the PRTG Server

The execution policy configured on a host specifies which scripts can be executed on the Windows host. There are several available settings for this:

SettingDescription
RestrictedNo scripts can directly be executed, only within an interactive session.
AllSignedOnly scripts from a trusted author can be executed.
RemoteSignedDownloaded scripts have to be signed prior to execution.
UnrestrictedThere are no restrictions, all codes will be executed.

By default, the execution policy is set to Restricted. It will hinder PRTG from executing scripts, therefore you cannot use them.

So first, you need to set the execution policy. Because the scripts are always executed by the PRTG probe service (the PRTG probe is a 32-bit application), we need to use the 32-bit PowerShell:

  1. Open Windows PowerShell (x86), respectively Windows PowerShell (32-bit) as Administrator.
  2. Set the ExecutionPolicy to RemoteSigned with the following command:
    Set-ExecutionPolicy RemoteSigned

Remember that when the device is located on a remote probe, you need to take the steps on the system where the remote probe is installed, not on the PRTG core server system.

Note: You need to do this only once.

2. Install the PowerShell Script

Next, you will have to check the output of the script. There are only two options:

One lineEXE/Script<PRTG Application Directory>\Custom Sensors\EXE\
XMLEXE/Script (Advanced)<PRTG Application Directory>\Custom Sensors\EXEXML\

If you already know the output type, simply copy the script to the corresponding directory.
Make sure that it has .ps1 as extension. However, if you are unsure what kind of script you have, you have two options:

  1. Open the script and search for something like Write-Host or Out-Host
  2. If the output looks like XML, copy the script to the EXEXML folder.
    Otherwise, copy it to the EXE folder.

3. Test the Script

The script is now installed. The question is how to correctly use it. If the script is documented properly (either via PowerShell or text documentation), this should be no problem. You can show the PowerShell help for a script as follows:

Get-Help <path-to-the-script> -detailed

It will show you a description of the script and which parameters are supported including their description. If the script entirely lacks documentation, simply open the script with a text editor and search for param. The parameters are listed there. You can then call the script as follows:
-parameter1 <testvalue> -parameter2 <testvalue2> You can omit the parameters if you enter them in the correct order. If the script works fine, you can proceed with creating the sensor in PRTG.

4. Create the Sensor in PRTG

Add a new sensor. Select either the EXE/Script sensor or the EXE/Script (Advanced) sensor.

ParameterDescription
EXE/ScriptSelect the script you have just installed.
ParametersEnter the parameters. Remember that you can use placeholders here.
Security ContextChoose if you want PRTG to run the script using the user account of the probe service or the account configured in the device.
Mutex NameIf you have many sensors that run concurrently, you can configure different mutex names so that they do not hinder each other.

First Aid

ProblemResponse not well formed: (File C:\Program Files (x86)\PRTG Network Monitor\custom sensors\EXE\test.ps1 cannot be loaded because the execution of scripts is disabled on this system.
Solution1The execution policy is not correctly configured on the host. Go through Step 1 of this tutorial to resolve this.
Solution2Double-check that the downloaded script file is not Blocked. Right-click the script file. On the General tab, you will see: This File came from another computed and might be blocked to help protect this computer. Click Unblock.
ProblemThe sensor shows the message UnauthorizedAccess.
SolutionThis is probably because of the user account that is configured in the probe service or device, depending on what you selected as security context. Make sure that the user has all necessary permissions to properly execute the sensor.
ProblemThe term '<insert-cmdlet-name-here>' 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.
SolutionThis indicates that either a command or function used by the script is not properly declared within the script or that it uses a cmdlet that is not available on the PRTG server. Most likely, the latter is the case. Make sure that you are running the latest Windows Management Framework.
ProblemThe sensor displayed incorrect results (0) or no values after migrating it to a new or different server or Windows version. You may also get the error message XML: Junk after document element </text> -- JSON: The returned JSON does not match the expected structure (Invalid JSON.). (code: PE231)
SolutionKeep in mind that newer operating systems will usually run a newer PowerShell version, your cmdlets may be missing parameters, or your variables may not be correctly called within text ($($var) instead of $var). Run the script from the command line to confirm that it still works or adjust it if necessary.

Created on Sep 22, 2016 9:16:26 AM by  Stephan Linke [Paessler Support]

Last change on Sep 12, 2019 5:08:18 AM by  Maike Behnsen [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Could you by any chance provide a guide on creating lookup files to turn standard xml output into something PRTG can understand?

Created on Jan 12, 2018 3:00:47 PM by  Samuel Ashdown (60) 1 1



Votes:

0

Your Vote:

Up

Down

Hey Sam,

You might want to check the REST Custom Sensor, as it allow you to properly evaluate XML/JSON into PRTGesque channels :) Or do you require assistance with that?


Kind regards,
Stephan Linke, Tech Support Team

Created on Jan 15, 2018 7:28:56 AM by  Stephan Linke [Paessler Support]



Votes:

0

Your Vote:

Up

Down

I am getting the "Response not well formed ... cannot be loaded because the execution of scripts is disabled on this system" error even though I have tried setting the execution policy to RemoteSigned, Unrestricted, and Bypass on the system where the sensor is located (the probe system itself). I have also tried using the "-Scope LocalMachine" parameter and using both options for Security Context. I can log into the server and run the script from within a PowerShell process myself with no problems. What am I missing?

Created on Mar 7, 2019 10:38:33 PM by  MSchwartz12 (0) 1



Votes:

0

Your Vote:

Up

Down

Hey Sam.

I have been down this path and hopefully I am at my end. There is an Advanced HTTP sensor that I am hoping will fit the bill. Stephan's suggestion sounds pefect, until you get under the hood. It is beta, does not support smart URL lookups (sensor only reports locally). The other option is to write a script or EXE which outputs the format you need and the values you need and that could work with a custom sensor. I would love it to take a remote native json or xml output returned as the deity(ies) intended....

If the Rest sensor mentioned was ever updated to support remote URLs as many other similar sensors are... it would be grand...

Created on May 29, 2019 1:56:10 AM by  TypoProne (0)



Votes:

0

Your Vote:

Up

Down

@TypoProne Thanks for your input. The Sensor is indeed still in beta and likely not make it into a non-beta state, as we're working on a successor that will be easier to handle. But no ETA on that yet :)

Created on May 31, 2019 6:13:39 AM by  Stephan Linke [Paessler Support]

Last change on May 31, 2019 6:13:58 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.