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

EXE/Script Advanced sensor

Votes:

0

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?

cusom-sensor exe-script-advanced xml-code

Created on May 31, 2023 11:42:50 AM

Last change on Jun 1, 2023 9:57:10 AM by  Felix Wiesneth [Paessler Support]



2 Replies

Votes:

0

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

Created on Jun 2, 2023 2:34:42 PM by  Felix Wiesneth [Paessler Support]



Votes:

0

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!

Created on Jun 7, 2023 1:52:52 PM by  Ricardo Sanchez [Paessler Technical 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.