mickeybyte / PRTG

PRTG Custom Sensor Powershell class and Horizon Monitoring sensors
5 stars 0 forks source link

Non valid json output for PRTG with a single result #17

Closed metroidfox closed 2 years ago

metroidfox commented 3 years ago

Hi,

Really simple issue and fix. When returning a single result through this tool, PRTG reports en error parsing the JSON.

What happens is that when using the pipeline to feed ConvertTo-Json, even if the object passed is an array, the function only receives a single item. Because of that, ConvertTo-Json doesn't output brackets [ ] in the output, whichi PRTG requires even for a single item.

To fix this, instead of using "$this.Channels | ConvertTo-Json", the script should use "ConvertTo-Json @($this.Channels)", which forces the value to be treated as an array and always outputting the brackets [ ].

And that makes PRTG really happy.

mickeybyte commented 3 years ago

Thanks for reporting this. Looks like I haven't created any sensors with just a single channel ;-) I'll fix it.

mickeybyte commented 2 years ago

Fixed (finally ;-))