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 "<"
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+'&username=noc@oursite.com&passhash=123456789' $URI_SensorBP18 = 'https://prtg.oursite.com/api/getsensordetails.json?id='+$SensorIDBP18+'&username=prtg@oursite.com&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 = < 0,01 Mbit/s
Article Comments
Hi Stephan,
Thanks for the reply. Have tried it with Invoke-Webrequest and convertfrom-Json and the result is the same:
< 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?
Aug, 2016 - Permalink
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?
Aug, 2016 - Permalink
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!
Aug, 2016 - Permalink
Hm, apart from this being rather strange - have you tried invoke webrequest instead, combined with convertfrom-json? You could also simply replace the < with -replace '<', '' - but that's not good practice, either :)
Aug, 2016 - Permalink