Hello, I have a question about EXE/Script Advanced sensor and its XML structure to create sensor channels. I customaze my own .ovl file that works fine but is there a way how to specify via XML that channel use this .ovl file at Lookup?

I thought that it should work like this but dont:

# Get data from shelly plug to variable $result
$result = Invoke-RestMethod -Uri $url -Method Get

# Get relay state value to variable for later use (could be use directly in code)

$relayState = $result.relays[0].ison

# Converting Shelly Plug relay state from True/False to 1/0 so PRTG can understand that

$translatedState = if ($result.relays.ison -eq "True") { "1" } else { "0" }

# Parsing and creating XML output for PRTG to create sensor and its parameters


        $prtgresult=""

		$prtgresult+="<prtg>"

		$prtgresult+="  <result>"
		$prtgresult+="    <channel>Status</channel>"
		$prtgresult+="      <value>$translatedState</value>"
		$prtgresult+="    <float>0</float>"
		$prtgresult+="  </result>"
                $prtgresult+="  <ValueLookup>id='$file'</ValueLookup>"

		$prtgresult+="</prtg>"

		Write-Output $prtgresult

Powershell return this:

<prtg>  <result>    <channel>Status</channel>      <value>0</value>    <float>0</float>  </result>  <ValueLookup>id='prtg.standardlookups.shellyplugs.status'</ValueLooku
p></prtg>

So where do I make mistake or is it even possible to specify .ovl file within sensors channel creation?


Article Comments

Hi there,

Following code should work for the output:

$prtgresult="

	<prtg>
	 <result>
	<channel>Status</channel>
	<value>$translatedState</value>
	<float>0</float>
	</result>
    <ValueLookup>id='$file'</ValueLookup>
	</prtg>"

Write-Output $prtgresult

Jun, 2023 - Permalink

Hello dear customer,

To properly pass parameters to the PowerShell script in PRTG, you need to format the parameter input correctly. Here's how you can modify your code to handle the parameter properly:

{{{# Shelly Plug S XML param ( [string]$url = "" )

  1. Get data from shelly plug to variable $result $result = Invoke-RestMethod -Uri $url -Method Get
  1. Parsing and creating XML output for PRTG to create sensor and its parameters $prtgresult = "<prtg>"
  1. Channel for actual power in Watts $prtgresult += "<result>" $prtgresult += "<channel>Power</channel>" $prtgresult += "<value>$($result.meters.power)</value>" $prtgresult += "<unit>Custom</unit>" $prtgresult += "<customunit>Watt</customunit>" $prtgresult += "<float>1</float>" $prtgresult += "</result>"
  1. Channel for power consumption in kWh $prtgresult += "<result>" $prtgresult += "<channel>Power consumption</channel>" $prtgresult += "<value>$([long]($result.meters.total/60)/10)/100)</value>" $prtgresult += "<unit>Custom</unit>" $prtgresult += "<customunit>kWh</customunit>" $prtgresult += "<mode>Absolute</mode>" $prtgresult += "<float>1</float>" $prtgresult += "</result>"
  1. Channel relay state True/False translated to 1/0 $prtgresult += "<result>" $prtgresult += "<channel>Relay Status</channel>" $prtgresult += "<value>$(if ($result.relays.ison -eq 'True') { '1' } else { '0' })</value>" $prtgresult += "<float>0</float>" $prtgresult += "<ValueLookup>id='prtg.standardlookups.shellyplugs.status'</ValueLookup>" $prtgresult += "</result>"

$prtgresult += "</prtg>"

Write-Output $prtgresult}}}

Make sure you replace the existing PowerShell code in your PRTG EXE/Script Advanced sensor with this modified code.

To pass the parameter in PRTG, you should use the following format in the sensor's "Parameters" field:

-url=%host

Ensure that the sensor is configured to use the parameter -url and the appropriate host variable is defined in PRTG.

This format will substitute %host with the value you provide as the parameter when configuring the sensor.

Let me know if you have any further questions!


Jun, 2023 - Permalink