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

Count all child elements 1 level deep

Votes:

0

Is it possible to count all the child elements directly under an icon? All types of child elements should be considered (devices and groups).

customize maps status-icons

Created on Apr 13, 2015 11:42:15 AM



2 Replies

Accepted Answer

Votes:

3

I guess your best starting point is the table.xml API call

http://yourserver/api/table.xml?content=sensortree&username=myuser&password=mypassword

You can limit the result set by including the objectID of the parent 'icon'

http://yourserver/api/table.xml?content=sensortree&id=1234&username=myuser&password=mypassword

'Feeding' the url above to the HTTP XML/Rest Value Sensor using XPath query sensortree/nodes/*[1] and selecting Count Child Nodes will give you the number of child elements +7

The +7 is caused by the additional describing nodes (<name>,<id>,<url>,...) in the xml result.

You might be able to filter out these additional nodes using a more advanced XPath query.

Created on Apr 13, 2015 3:13:29 PM



Votes:

0

Thanks for your response.

However with this approach, we have to create an additional sensor for the counting on each of the affected groups and we lose the status color of the group on the icon.

Based on your suggestions, I have implemented this using jQuery code in the icon template:

<span id="count<@objectid>"/>

<script>
  $(document).ready(function(){
    $.get("https://yourserver/api/table.xml?content=sensortree&id=<@objectid>", function(data) {
      $('#count<@objectid>').text($('sensortree > nodes > :first-child > :has(*)', data).length);
    });
  });
</script>

Created on Apr 16, 2015 4:36:20 PM

Last change on Apr 16, 2015 6:36:31 PM by  Torsten Lindner [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.