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

Placeholder directly in Powershell

Votes:

1

My aim is to generate a call in our servicemanagementtool whenever PRTG detects low diskspace. For this I need some information about the device, status and message. I use a powershell script to interact with the API of our servicemanagementtool. I can get this set-up to work with parameters (PRTG placeholders) specified in the parameter field of the sensor and a params section in my script.

Working without a seperate parameter setting would make life much easier. I would like to use the PRTG info directly as variables. So, what I don't understand is the use of the option 'Set placeholders as environment values'. Seems to me that with that option enabled I could use any PRTG placeholder as direct variable in my Powershell script. I tried several notations, but no avail. Things like %host or '%host' keeps getting displayed as plain text %host or '%host'.

I've tried the forum, searched online, but I can't seem to find the answer or an example how to go about this.

placeholders powershell variable-

Created on Mar 16, 2018 10:57:22 AM



5 Replies

Votes:

0

Hi there,

It works like any other application, you can give as much parameters as you want to an application, however when the application don't know what to do with it, then the parameters are useless.

So the parameters used in the script have to be declared in the script. In powershell it is actually pretty easy:

param(
$value1 = 1,
$value2 = 2,
$name = "Test"
)

Then just add the following in the parameters field:

-value1=3 -value2=4 -name="TestName"

You can also leave the parameters in the script empty and just fill them by your needs. But, unfortunately there is no way around this.

Best regards.

Created on Mar 16, 2018 5:18:26 PM by  Dariusz Gorka [Paessler Support]



Votes:

0

I got that running already, pretty straight forward.

I was just wondering what the purpose of 'environment variables' is here. That's still not clear to me.

Created on Mar 19, 2018 9:44:02 AM



Votes:

0

Hi there,

Set placeholders as environment values: From within your executable or script, the values of PRTG command line parameters will be available via environment variables. For example, you can then read and use the current host value of the PRTG device this EXE/Script sensor is created on from within your script. This option can mean a security risk, because also credentials are provided in several variables.

You can find an exact list of available environmental variables in your webinterface under:

/api.htm?tabid=7#toc-index-8


Best regards.

Created on Mar 19, 2018 11:06:16 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

OK, I got it to work!

For everybody else the way to make it work. Call the enviroment variables by using a param entry like:

param(
[string]$server='prtg_device',
[string]$sensor='prtg_sensor',
[string]$status='prtg_status',
[string]$message='prtg_message',
$value='prtg_value',
[string]$since='prtg_since'
)

Created on Mar 19, 2018 12:50:37 PM

Last change on Mar 19, 2018 1:49:20 PM by  Dariusz Gorka [Paessler Support]



Votes:

1

Some more info... I was able to get this to work in a Powershell script by using the environment variable names, like this:

$env:prtg_windowsuser
$env:prtg_host
$env:prtg_sensorid 

Passing these as parameters isn't necessary. As troubleshooting, I used this little snippet to see what environment variables were available when the PS script ran:

Start-Transcript -Path c:\temp\somefile.txt
gci env:* | sort-object name
Stop-Transcript

The above will mess up any output to PRTG, so it's just temporary troubleshooting code.

Created on Aug 28, 2019 4:08:40 PM

Last change on Aug 28, 2019 6:03:22 PM by  Dariusz Gorka [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.