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.


Article Comments

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.


Mar, 2018 - Permalink

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.


Mar, 2018 - Permalink

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.


Mar, 2018 - Permalink

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'
)

Mar, 2018 - Permalink

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.


Aug, 2019 - Permalink