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 Data Advanced - JSON response formatting

Votes:

0

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

api custom-sensor http-data-advanced json xml

Created on Sep 28, 2015 4:20:49 PM

Last change on Sep 6, 2016 12:01:53 PM by  Luciano Lingnau [Paessler]



Best Answer

Accepted Answer

Votes:

1

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]

Created on Sep 6, 2016 11:54:17 AM by  Luciano Lingnau [Paessler]

Last change on Jan 17, 2018 10:10:49 AM by  Luciano Lingnau [Paessler]



5 Replies

Votes:

0

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.

Created on Sep 30, 2015 1:27:31 PM by  Konstantin Wolff [Paessler Support]



Votes:

0

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

Created on Sep 30, 2015 4:09:41 PM

Last change on Oct 2, 2015 11:14:33 AM by  Luciano Lingnau [Paessler]



Accepted Answer

Votes:

1

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]

Created on Sep 6, 2016 11:54:17 AM by  Luciano Lingnau [Paessler]

Last change on Jan 17, 2018 10:10:49 AM by  Luciano Lingnau [Paessler]



Votes:

0

Try this: json formatter https://jsonformatter-online.com

Created on Aug 30, 2017 3:56:36 AM



Votes:

0

I use this tool to convert xml to json. https://jsonformatter.org/xml-to-json and this for formatting JSON https://jsonformatter.org

Created on Nov 20, 2017 7:52:41 AM




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.