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
Article Comments
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
Jul, 2021 - Permalink
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.
Jul, 2021 - Permalink
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
Jul, 2021 - Permalink