How should the XML response:
<prtg> <result> <channel>name</channel> <value>1</value> </result> </prtg>
be formatted in JSON. My first guess was to do it like:
{"prtg": { "result": { "channel": "name", "value": "1" } } }
but it does not seem to work
Article Comments
I am referring to HTTP advanced data sensor returning JSON not XML. We found a format that seems to work:
{ "prtg": { "result": [ { "channel": "name", "value": "1" } ] } }
Ie it seems that 'channel' result objects must be placed in an array even if there is only one channel
Sep, 2015 - Permalink
For reference, this is an multi-channel example XML response supported by the HTTP Data Advanced sensor:
<?xml version="1.0" encoding="utf-8" ?> <prtg> <result> <channel>Channel 1 (float)</channel> <value>12.3456</value> <float>1</float> <unit>custom</unit> <customunit>celsius</customunit> </result> <result> <channel>Channel 2 (integer)</channel> <value>42</value> <limitmode>1</limitmode> <limitmaxwarning>50</limitmaxwarning> <limitmaxerror>60</limitmaxerror> </result> <result> <channel>Channel 3 (lookup)</channel> <value>1</value> <valuelookup>prtg.standardlookups.exchangedag.yesno.stateyesok</valuelookup> </result> <result> <channel>Channel 4 (delta)</channel> <value>123456</value> <mode>difference</mode> <unit>bytesbandwidth</unit> </result> <text>The sensor's message</text> </prtg>
And the same response in JSON for reference:
{ "prtg": { "result": [ { "channel": "Channel 1 (float)", "value": "12.3456", "float": "1", "unit": "custom", "customunit": "celsius" }, { "channel": "Channel 2 (integer)", "value": "42", "limitmode": "1", "limitmaxwarning": "50", "limitmaxerror": "60" }, { "channel": "Channel 3 (lookup)", "value": "1", "valuelookup": "prtg.standardlookups.exchangedag.yesno.stateyesok" }, { "channel": "Channel 4 (delta)", "value": "123456", "mode": "difference", "unit": "bytesbandwidth" } ], "text": "The sensor's message" } }
There are several online XML<->JSON converter tools, for instance:
http://www.utilities-online.info/xmltojson/
Best Regards,
Luciano Lingnau [Paessler Support]
Sep, 2016 - Permalink
I use this tool to convert xml to json. https://jsonformatter.org/xml-to-json and this for formatting JSON https://jsonformatter.org
Nov, 2017 - Permalink
Hi,
are you referring to the output for an EXE Script Advanced sensor? If so, what is the error message when using JSON? Apart from that, the JSON looks correctly and should be picked up by PRTG.
Sep, 2015 - Permalink