What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

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

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 [Product Manager]

Last change on Jan 4, 2023 9:13:20 AM by  Brandy Greger [Paessler Support]



4 Replies

Accepted Answer

Votes:

0

This article applies as of PRTG 22

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 is 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 and use one of the following simple scripts.

Note: We recommend that you not edit the demo files in the \Custom Sensors\EXE subfolder of the PRTG program directory. Create your own new files and make sure to give them unique names that do not start with Demo, for example.

Return EXE parameters using PowerShell

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

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

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

After you have set up the 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 32-bit or 64-Bit and Execution Policy


Return EXE parameters using VBScript

Save the following script as Check EXE Sensor Parameters.vbs to the Custom Sensors\EXE subfolder of the 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

After you have set up the EXE/Script sensor, you 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

Created on Nov 4, 2010 4:11:36 PM by  Daniel Zobel [Product Manager]

Last change on Dec 29, 2022 3:16:05 PM by  Brandy Greger [Paessler Support]



Votes:

1

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

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



Votes:

0

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



Votes:

0

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]




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.