What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general. You are invited to get involved by asking and answering questions!

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
300.000 administrators have chosen PRTG to monitor their network. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Rest Custom Sensor - Count Items in JSON Array

Votes:

0

Your Vote:

Up

Down

Hi All

I try to creat a REST custom sensor that counts the number of items in the response array.

Response:

{
    "TicketID": [
        "156319",
        "156312",
        "156050",
        "155987",
        "155929",
        "155897",
        "155895",
        "155887",
        "155050",
        "154801",
        "154369",
        "136742"
    ]
}

**Template (not working):**
{
  "prtg": {
    "result": [
     {
          "channel": "Total count" ,
          "value": len($.*),
          "unit": "Count"
    }
    ]
  }
}

Problem: In PRTG it counts as "1"

If I try without len() -> "value": $.* I get the array of TicketID:

Could not create channel Total count0: expected number but got [156319 156312 156310 156254 156242 156228 156158 156094 156050 155987 155929 155897 155895 155887 155738 155667 155476 155466 155412 155376 155050 154801 154369 154344 153803 152947 152107 150923 150558 147733 143883 143180 136742] ([]interface {}).

Is "len()" the wrong function and how can I count the entries in this array?

Thanks and best regards Manuel

array count rest sensor template

Created on Jul 16, 2021 7:37:41 AM by  Manu (0) 1

Last change on Jul 16, 2021 8:30:55 AM by  Felix Wiesneth [Paessler Support]



3 Replies

Accepted Answer

Votes:

1

Your Vote:

Up

Down

Hi there,

According to the description of the function len(): https://www.paessler.com/manuals/prtg/rest_custom_sensor
I would try { "prtg": { "result": [ { "channel": "Total count" , "value": len($..*), "unit": "Count" } ] } }

The additional dot should trigger that you don't count the amount of arrays instead the amount of item in the array

Created on Jul 19, 2021 1:38:19 PM by  Moritz Heller [Paessler Support]

Last change on Jul 19, 2021 1:39:53 PM by  Moritz Heller [Paessler Support]



Votes:

0

Your Vote:

Up

Down

Hi Moritz

It works now with "len($..)"

Still a bit confused with the amount of dots needed in this templates :)

Thank you and best regards

Manuel

Created on Jul 20, 2021 6:06:26 PM by  Manu (0) 1



Votes:

0

Your Vote:

Up

Down

Hi Manuel,

Thank you for the update.

The manual says "len(object/array/string)" so the "$" is the object, the first dot is the "array" and the second dot is the "string". You had only one dot so you referred to the "array" and not to the string. Therefore, a second dot was required.

Created on Jul 22, 2021 8:09:37 AM by  Moritz Heller [Paessler Support]



Please log in or register to enter your reply.


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.