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


How can I test if parameters are correctly transmitted to my script when using an EXE/Script sensor?

Votes:

0

Your Vote:

Up

Down

I want to set up an EXE/Script sensor in PRTG. As start parameters, I can enter several values into the Parameters field.

How do I enter more than one parameter, and how can I make sure that parameters are correctly forwarded to my script?

custom-exe exe help parameters powershell prtg script variables visual-basic

Created on Nov 4, 2010 3:54:42 PM by  Daniel Zobel [Paessler Support]

Last change on Nov 24, 2011 4:50:30 PM by  Daniel Zobel [Paessler Support]



4 Replies

Accepted Answer

Votes:

0

Your Vote:

Up

Down

This article applies to PRTG Network Monitor 19 or later, as well as to previous (deprecated) versions in part

Using Parameters with EXE/Script Sensors

To correctly pass one or more parameters to a script, or when using placeholders, put every single parameter in quotes:

  • For PowerShell scripts, use single quotation marks ' '
  • For all other scripts, use double quotes " "

If you do not use quotes, every space will be regarded as a separator, thus dividing one parameter into two.

To test how parameters are passed to a script, you can set up an EXE/Script sensor using one of the following simple scripts.

Return EXE Parameters Using PowerShell

Save the following script as Demo PowerShell Script - Check EXE Sensor Parameters.ps1 to the Custom Sensors\EXE subfolder of your PRTG program directory.

foreach ($arg in $args)
{
   $s += """" + $arg + """ "
}

$x = [string]$args.Length + ":" + $s
write-Host $x

Once set up as an EXE/Script sensor, you will see that the parameters you have entered in the Settings tab of this sensor are returned in the sensor's Last Message field. In this output, every single value is put in quotes.

See Also

Powershell 32bit or 64Bit and Execution Policy


Return EXE Parameters Using VBScript

Save the following script as Demo VBScript - Check EXE Sensor Parameters.vbs to the Custom Sensors\EXE subfolder of your PRTG program directory.

Dim i,c, str

c = WScript.Arguments.Count


if c = 0 then

 WScript.echo c&":No Arguments"

else

  for i = 0 to c - 1
     str = str + """" + WScript.Arguments(i) +""" "
  next
  WScript.echo c & ":" & str

end if

Once set up as an EXE/Script sensor, you will see that the parameters you have entered in the Settings tab of this sensor are returned in the sensor's Last Message field. In this output, every single value is put in quotes.


More

A detailed description of EXE/Script sensors can be found in PRTG Manual: Custom Sensors.

Created on Nov 4, 2010 4:11:36 PM by  Daniel Zobel [Paessler Support]

Last change on May 20, 2019 10:51:41 AM by  Brandy Mauff [Paessler Support]



Votes:

0

Your Vote:

Up

Down

EXAMPLE for POWERSHELL:

Parameter field: '%device' '%name' '%status' '%down' '%message'

First line in powershell to receive those parameters: param([string]$IPServer = "N/A",[string]$IPService = "N/A",[string]$IPStatus = "N/A", [string]$IPDown = "N/A",[string]$IPMessage = "N/A")

After that all of the powershell variables will be filled in from Network Monitor. If there is a failure for some reason, then you will get N/A as your value.

Created on Aug 12, 2011 4:09:10 PM by  Mike Bujnowski (0) 1

Last change on Nov 24, 2011 4:37:29 PM by  Daniel Zobel [Paessler Support]



Votes:

0

Your Vote:

Up

Down

You will run into a problem when the message of the sensor has a single quote in it. This will break the script (since it's going to cut the message into multiple parts).

I have a notification PowerShell script in place, which automatically creates tickets in our ticket system. However, when the sensor message contains a single quote, it'll break my script (example sensor message: Error by lookup value 'Critical (2)' in channel 'Belt Unit' (Belt End Soon ) ). The notification script cannot create a ticket for this sensor, because it breaks up the '%message' parameter in the script.

The parameters for the script: '%sensor' '%sensorid' '%status' '%message' '%device' '%since' '%lastup' '' '' '' '%prio'

Created on Jul 21, 2017 9:10:42 AM by  Corné van den Bosch (40) 1 1



Votes:

0

Your Vote:

Up

Down

Hi Corné,

via https://stackoverflow.com/a/11231504: 'Escape a single quote '' using a double single quote'

See the help for the quoting rules. Check out the help in the powershell command line by typing:

Get-Help about_Quoting_Rules It explains that backticks are interpreted literally in single-quoted strings:

-- Because the contents of single-quoted strings are interpreted literally, you cannot use the
-- backtick character to force a literal character interpretation in a single-quoted string.


Kind regards,
Stephan Linke, Tech Support Team

Created on Jul 21, 2017 9:51:26 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.