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

How do I extract values from XML nodes (with nested tags) using the HTTP XML/REST Value sensor?

Votes:

0

How exactly do I extract values from an XML node using the HTTP XML/REST Value sensor of PRTG?

help http http-xml node restful sensor value xml xml-rest xml-rest-value

Created on Nov 5, 2012 4:01:34 PM by  Daniel Zobel [Product Manager]

Last change on Dec 10, 2020 10:10:45 AM by  Brandy Greger [Paessler Support]



15 Replies

Accepted Answer

Votes:

0

This article applies as of PRTG 22

Extracting XML nodes

The HTTP XML/REST Value sensor can parse different XML outputs. The notation is XPath compatible. See a typical simple XML example below:

<data>
<section1>
    <name>int. Temperature</name>
    <value_float>36.31</value_float>
    <value_int>3631</value_int>
    <value_string>thirty-six</value_string>
    <minimum>36.25</minimum>
    <maximum>46.87</maximum>
    <limit_low>10.00</limit_low>
    <limit_high>50.00</limit_high>
    <function>l</function>
    <alarm1>0</alarm1>
</section1>
</data> 

Data from nested XML tags

To obtain values from nested XML tags, use tag names separated by a slash. For example, to obtain the float value 36.31 from the XML above, you would use the following value in the sensor's XML Node field:

section1/value_float

More

Created on Nov 5, 2012 4:17:27 PM by  Daniel Zobel [Product Manager]

Last change on Jan 3, 2023 8:07:54 AM by  Brandy Greger [Paessler Support]



Votes:

1

When there are multiple nodes within a XML result, you can reference it's occurrence using a number between Brackets.

The following PRTG API Call For example:

/api/table.xml?content=sensors&output=xml&columns=name,uptime&id=DEVICEID

Produces the following output:

<?xml version="1.0" encoding="UTF-8"?>
  <sensors totalcount="2" listend="1">
   <prtg-version>15.2.18.2816</prtg-version>
   <item>
    <name>Ping</name>
    <uptime>95,3760%</uptime>
    <uptime_raw>000000000953760</uptime_raw>
   </item>
   <item>
    <name>Traceroute Hop Count</name>
    <uptime>95,4608%</uptime>
    <uptime_raw>000000000954608</uptime_raw>
   </item>
  </sensors>

If we want to read the uptime for the Traceroute Hop Count in the XML result, we use the following syntax within the XML Node (and optional property) inside PRTG:

item[2]/uptime

That will result in the folowing output within the HTTP XML/REST Value Sensor in PRTG

Node item[2]/uptime_raw holds value 95,4608%.

Created on Jun 26, 2015 11:43:28 AM by  Luciano Lingnau [Paessler]

Last change on Jun 26, 2015 12:02:22 PM by  Luciano Lingnau [Paessler]



Votes:

0

Hi,

With your example, is it possible to get the totalcount value ?

Thanks,

Matthieu

Created on Nov 14, 2016 4:58:13 PM



Votes:

0

Hi there,

It's not possible to get the value of <sensors totalcount="353" listend="1"> because it is not a value of a node. You could however count the number of <item> occurrences.


Best Regards,
Luciano Lingnau [Paessler Support]

Created on Nov 15, 2016 2:39:52 PM by  Luciano Lingnau [Paessler]



Votes:

0

Hi there,

It's not possible to get the value of <sensors totalcount="353" listend="1"> because it is not a value of a node. You could however count the number of <item> occurrences.


Best Regards,
Luciano Lingnau [Paessler Support]

Created on Nov 15, 2016 2:39:52 PM by  Luciano Lingnau [Paessler]



Votes:

0

Hi im trying to add a XML Sensor, with a JSON URL get method, the problem is that i want to get the value from an array of the JSON, in the previous answer i realized that is possible with the XML file using a syntax like this ...

item[2]/uptime

which is the notation that i need to use from a JSON field ? , attached the JSON example, im looking to extrac the headroom value from every hostname.

{
   "cdn.headroom" : 63,
   "cdn.machines" : [
      {
         "headroom" : 63,
         "hostname" : "ia1.tp2sfe1d1.cdn",
         "ips" : [ "10.187.9.20" ],
         "max-hedroom" : 100,
         "rack" : "r.mx.sfe.tp2sfe1c1"
      }
   ],
   "cdn.max-hedroom" : 100,
   "external.headroom" : 2263,
   "machines" : [
      {
         "headroom" : 91,
         "hostname" : "hostname1",
         "max-hedroom" : 100,
      },
      {
         "headroom" : 88,
         "hostname" : "hostname2",
         "max-hedroom" : 100,
      },
      {
         "headroom" : 94,
         "hostname" : "hostname3",
         "max-hedroom" : 100,
      },

Created on Mar 17, 2017 7:36:51 PM



Votes:

0

Could you post the entire JSON? The following should work:
//headroom[0]

Created on Mar 20, 2017 6:13:27 AM by  Stephan Linke [Paessler Support]

Last change on Mar 20, 2017 6:13:56 AM by  Stephan Linke [Paessler Support]



Votes:

0

Thanks Stephan nut unfourtunately doesn't work attached the error, the JSON , and the configuration of the sensor.

{
   "cdn.headroom" : 29,
   "cdn.machines" : [
      {
         "headroom" : 29,
         "hostname" : "ia1.tp2sfe1d1.cdn",
         "ips" : [ "10.187.9.20" ],
         "max-headroom" : 100,
         "rack" : "r.mx.sfe.tp2sfe1c1"
      }
   ],
   "cdn.max-headroom" : 100,
   "external.headroom" : 2029,
   "external.machines" : [
      {
         "headroom" : 91,
         "hostname" : “hostname1”,
         "max-headroom" : 100,
      },
      {
         "headroom" : 89,
         "hostname" : "hostname2”,
         "max-headroom" : 100,
      },
      {
         "headroom" : 92,
         "hostname" : "hostname3”,
         "max-headroom" : 100,
      },
      {
         "headroom" : 79,
         "hostname" : "hostname4”,
         "max-headroom" : 100,
      },
      {
         "headroom" : 80,
         "hostname" : "hostname5”,
         "max-headroom" : 100,
      },
      {
         "headroom" : 96,
         "hostname" : "hostname6”,      
         "max-headroom" : 100,
      }
   ],
   "external.max-headroom" : 2600
}

https://ibb.co/iJu3MF

https://ibb.co/fpomaa

Regards !

Created on Mar 21, 2017 10:11:59 PM

Last change on Mar 22, 2017 6:46:57 AM by  Stephan Linke [Paessler Support]



Votes:

0

The JSON is slightly invalid. Here's the corrected version:

{
	"cdn.headroom": 29,
	"cdn.machines": [{
		"headroom": 29,
		"hostname": "ia1.tp2sfe1d1.cdn",
		"ips": ["10.187.9.20"],
		"max-headroom": 100,
		"rack": "r.mx.sfe.tp2sfe1c1"
	}],
	"cdn.max-headroom": 100,
	"external.headroom": 2029,
	"external.machines": [{
		"headroom": 91,
		"hostname": "hostname1",
		"max-headroom": 100
	}, {
		"headroom": 89,
		"hostname": "hostname2",
		"max-headroom": 100
	}, {
		"headroom": 92,
		"hostname": "hostname3",
		"max-headroom": 100
	}, {
		"headroom": 79,
		"hostname": "hostname4",
		"max-headroom": 100
	}, {
		"headroom": 80,
		"hostname": "hostname5",
		"max-headroom": 100
	}, {
		"headroom": 96,
		"hostname": "hostname6",
		"max-headroom": 100
	}],
	"external.max-headroom": 2600
}

What exact value are you trying to extract?

Created on Mar 22, 2017 6:50:30 AM by  Stephan Linke [Paessler Support]



Votes:

0

Im trying to extract the headroom value of each node included in the array of external.machines, the JSON is generated automatically by a vendor Tool, i'll attach the FULL JSON

{
   "cdn.headroom" : 29,
   "cdn.machines" : [
      {
         "headroom" : 29,
         "hostname" : "ia1.tp2sfe1d1.cdn",
         "ips" : [ "10.187.9.20" ],
         "max-headroom" : 100,
         "rack" : "r.mx.sfe.tp2sfe1c1"
      }
   ],
   "cdn.max-headroom" : 100,
   "external.headroom" : 1951,
   "external.machines" : [
      {
         "headroom" : 79,
         "hostname" : "ac1.tp2gdl1d1.cdn",
         "ips" : [ "10.187.5.5" ],
         "max-headroom" : 100,
         "rack" : "r.mx.gdl.tp2gdl1d1"
      },
      {
         "headroom" : 84,
         "hostname" : "ac2.tp2cly1d1.cdn",
         "ips" : [ "10.187.6.5" ],
         "max-headroom" : 100,
         "rack" : "r.mx.cly.tp2cly1d1"
      },
      {
         "headroom" : 92,
         "hostname" : "ac1.tp2cdj1d1.cdn",
         "ips" : [ "10.187.3.20" ],
         "max-headroom" : 100,
         "rack" : "r.mx.cdj.tp2cdj1d1"
      },
      {
         "headroom" : 64,
         "hostname" : "ac2.tp2tla1d2.cdn",
         "ips" : [ "189.203.173.19" ],
         "max-headroom" : 100,
         "rack" : "r.mx.tla.tp2tla1d2"
      },
      {
         "headroom" : 79,
         "hostname" : "ac2.tp2alb1d1.cdn",
         "ips" : [ "10.187.9.37" ],
         "max-headroom" : 100,
         "rack" : "r.mx.alb.tp2alb1d1"
      },
      {
         "headroom" : 93,
         "hostname" : "ac2.tp2tij1d1.cdn",
         "ips" : [ "10.187.1.5" ],
         "max-headroom" : 100,
         "rack" : "r.mx.tij.tp2tij1d1"
      },
      {
         "headroom" : 59,
         "hostname" : "ac1.tp2sfe1d1.cdn",
         "ips" : [ "10.187.9.21" ],
         "max-headroom" : 100,
         "rack" : "r.mx.sfe.tp2sfe1d1"
      },
      {
         "headroom" : 51,
         "hostname" : "ac1.tp2pue1d1.cdn",
         "ips" : [ "10.187.7.5" ],
         "max-headroom" : 100,
         "rack" : "r.mx.pue.tp2pue1d1"
      },
      {
         "headroom" : 95,
         "hostname" : "ac1.tp2chi1d1.cdn",
         "ips" : [ "10.187.3.4" ],
         "max-headroom" : 100,
         "rack" : "r.mx.chi.tp2chi1d1"
      },
      {
         "headroom" : 50,
         "hostname" : "ac3.tp2tla1d1.cdn",
         "ips" : [ "10.187.9.6" ],
         "max-headroom" : 100,
         "rack" : "r.mx.tla.tp2tla1d1"
      },
      {
         "headroom" : 75,
         "hostname" : "ac2.tp2gdl1d1.cdn",
         "ips" : [ "10.187.5.6" ],
         "max-headroom" : 100,
         "rack" : "r.mx.gdl.tp2gdl1d1"
      },
      {
         "headroom" : 89,
         "hostname" : "ac3.tp2tla1d2.cdn",
         "ips" : [ "189.203.173.20" ],
         "max-headroom" : 100,
         "rack" : "r.mx.tla.tp2tla1d2"
      },
      {
         "headroom" : 76,
         "hostname" : "ac3.tp2alb1d1.cdn",
         "ips" : [ "10.187.9.38" ],
         "max-headroom" : 100,
         "rack" : "r.mx.alb.tp2alb1d1"
      },
      {
         "headroom" : 61,
         "hostname" : "ac2.tp2sfe1d1.cdn",
         "ips" : [ "10.187.9.22" ],
         "max-headroom" : 100,
         "rack" : "r.mx.sfe.tp2sfe1d1"
      },
      {
         "headroom" : 55,
         "hostname" : "ac4.tp2tla1d1.cdn",
         "ips" : [ "10.187.9.7" ],
         "max-headroom" : 100,
         "rack" : "r.mx.tla.tp2tla1d1"
      },
      {
         "headroom" : 71,
         "hostname" : "ac3.tp2gdl1d1.cdn",
         "ips" : [ "10.187.5.7" ],
         "max-headroom" : 100,
         "rack" : "r.mx.gdl.tp2gdl1d1"
      },
      {
         "headroom" : 92,
         "hostname" : "ac1.tp2mer1d1.cdn",
         "ips" : [ "10.187.8.4" ],
         "max-headroom" : 100,
         "rack" : "r.mx.mer.tp2mer1d1"
      },
      {
         "headroom" : 60,
         "hostname" : "ac1.tp2tla1d1.cdn",
         "ips" : [ "10.187.9.4" ],
         "max-headroom" : 100,
         "rack" : "r.mx.tla.tp2tla1d1"
      },
      {
         "headroom" : 74,
         "hostname" : "ac4.tp2alb1d1.cdn",
         "ips" : [ "10.187.9.39" ],
         "max-headroom" : 100,
         "rack" : "r.mx.alb.tp2alb1d1"
      },
      {
         "headroom" : 79,
         "hostname" : "ac1.tp2cly1d1.cdn",
         "ips" : [ "10.187.6.4" ],
         "max-headroom" : 100,
         "rack" : "r.mx.cly.tp2cly1d1"
      },
      {
         "headroom" : 70,
         "hostname" : "ac4.tp2gdl1d1.cdn",
         "ips" : [ "10.187.5.8" ],
         "max-headroom" : 100,
         "rack" : "r.mx.gdl.tp2gdl1d1"
      },
      {
         "headroom" : 81,
         "hostname" : "ac1.tp2alb1d1.cdn",
         "ips" : [ "10.187.9.36" ],
         "max-headroom" : 100,
         "rack" : "r.mx.alb.tp2alb1d1"
      },
      {
         "headroom" : 86,
         "hostname" : "ac1.tp2tla1d2.cdn",
         "ips" : [ "189.203.173.18" ],
         "max-headroom" : 100,
         "rack" : "r.mx.tla.tp2tla1d2"
      },
      {
         "headroom" : 95,
         "hostname" : "ac1.tp2tij1d1.cdn",
         "ips" : [ "10.187.1.4" ],
         "max-headroom" : 100,
         "rack" : "r.mx.tij.tp2tij1d1"
      },
      {
         "headroom" : 87,
         "hostname" : "ac2.tp2mer1d1.cdn",
         "ips" : [ "10.187.8.5" ],
         "max-headroom" : 100,
         "rack" : "r.mx.mer.tp2mer1d1"
      },
      {
         "headroom" : 54,
         "hostname" : "ac2.tp2tla1d1.cdn",
         "ips" : [ "10.187.9.5" ],
         "max-headroom" : 100,
         "rack" : "r.mx.tla.tp2tla1d1"
      }
   ],
   "external.max-headroom" : 2600
}

In this case im looking for this values.

"headroom" : 79, "headroom" : 84, "headroom" : 92, etc etc

Created on Mar 22, 2017 11:41:19 PM



Votes:

0

//external.machines[1]/headroom

...but only one value per sensor. That's a bit of work I'm afraid.

Created on Mar 23, 2017 8:03:41 AM by  Stephan Linke [Paessler Support]



Votes:

0

Nice is there any way to add all the values ? or i need to add a sensor for each node ?

Created on Mar 23, 2017 7:44:01 PM



Votes:

0

One sensor per node, yep. Sorry, the sensor doesn't support converting multiple nodes into channels :(

Created on Mar 24, 2017 5:40:17 AM by  Stephan Linke [Paessler Support]



Votes:

0

Is there a way to get negative values from this type of sensor? I am seeing that whenever the node value is negative the result becomes 0. When the node value is above 0 the result is the proper value.

Created on Jul 21, 2017 2:52:26 PM



Votes:

0

Negative values should work, just tested it. Can you provide me with a sample XML? I won't publish it. We're currently working on a reimplementation of this sensor that will have quite a bit more features.

Stay tuned ;)

Created on Jul 24, 2017 5:04:06 AM by  Stephan Linke [Paessler Support]

Last change on Jul 24, 2017 6:19:42 AM 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.