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

HTTP API for LastValue returning result with &lt prefix

Votes:

0

Hi

I'm trying to create a sensor compares the last result of two other sensors. One value should be less than 1. The other value should be 200-500

The problem i am having is that when the value of one sensor is less that one, i get the value prefixed with "&lt"

This is REALLY problematic as i need to do a comparison between two numbers!!

How can i get it to return just a number??

The code i'm using looks like this:

		$Method = 'POST'
		$ContentType = 'application/json'
		
		
		$URI_SensorBP17 = 'https://prtg.oursite.com/api/getsensordetails.json?id='+$SensorIDBP17+'&[email protected]&passhash=123456789'
		$URI_SensorBP18 = 'https://prtg.oursite.com/api/getsensordetails.json?id='+$SensorIDBP18+'&[email protected]&passhash=123456789'

		 # This function returns a deserialized object (not JSON!)
		$contentL1 = Invoke-RestMethod -uri $URI_SensorL1 -Method $Method -ErrorVariable errmsg -ErrorAction SilentlyContinue -ContentType $ContentType
		$contentL2 = Invoke-RestMethod -uri $URI_SensorL2 -Method $Method -ErrorVariable errmsg -ErrorAction SilentlyContinue -ContentType $ContentType


		if (($contentL1.sensordata.lastvalue -gt 5) -and ($contentL2.sensordata.lastvalue -lt 5)) {
			# Active on L1
			$xmlToPRTG = @" 
			<prtg>
				<result> 
					<channel> Failover Monitor </channel> 
					<value>50</value> 
					<LimitMode>0</LimitMode>
				</result>
			</prtg>
"@;
			$xmlToPRTG 

And when lastvalue < 1, for the output i get:

$contentL1.sensordata.lastvalue = &lt; 0,01 Mbit/s

api last prtg

Created on Aug 10, 2016 12:44:59 PM

Last change on Aug 10, 2016 12:50:41 PM by  Torsten Lindner [Paessler Support]



5 Replies

Accepted Answer

Votes:

0

Hm, apart from this being rather strange - have you tried invoke webrequest instead, combined with convertfrom-json? You could also simply replace the &lt; with -replace '&lt;', '' - but that's not good practice, either :)

Created on Aug 12, 2016 10:03:44 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hi Stephan,

Thanks for the reply. Have tried it with Invoke-Webrequest and convertfrom-Json and the result is the same:

&lt; 0,01 Mbit/s

True i could do the -replace and i probably will have to.

However, I feel like this is a bug with the API. A numerical field should only contain numerical values. Is this something that can be fixed in the API?

Or is there a way to get the API to round values up/down to nearest integer for example?

Created on Aug 12, 2016 10:50:13 AM



Votes:

0

I'll try the API call as well and let you know what I found out. Is it possible that the actual
value is < 0,01 MBit/s in the sensor?

Created on Aug 12, 2016 11:17:48 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hey Stephan, It probably is. To be honest don't spend any more time checking this. Using the -replace option in powershell fixed it fine. I realized i should have been removing the "Mbit/s" and converting to a number as well in order to do math-based operations as well. So adding in one extra step is not a problem :) thanks for your help!

Created on Aug 12, 2016 11:59:17 AM



Votes:

0

Alright then :)

Created on Aug 12, 2016 12:14:11 PM 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.