Hello,

I'm looking to create a sensor to map the channel name dynamically with a value from json.

My API send :

{
  "application": [
    {
      "applicationName": "App1",
      "applicationParameters": [
        {
          "name": "connectCurrent",
          "count": 0,
        },
        {
          "name": "connectMax",
          "count": 10
        }
      ]
    },
    {
      "applicationName": "App3",
      "applicationParameters": [
        {
          "name": "connectCurrent",
          "count": 2,
        },
        {
          "name": "connectMax",
          "count": 10
        }
      ]
    },
    {
      "applicationName": "App3",
      "applicationParameters": [
        {
          "name": "connectCurrent",
          "count": 0,
        },
        {
          "name": "connectMax",
          "count": 200
        }
      ]
    }
  ]
}

I need to have on PRTG : I need to have:

  • App1 - connectCurrent
  • App1 - connectMax
  • App2 - connectCurrent
  • App2 - connectMax
  • ...

If I add an App4 I need PRTG to add the channel dynamically.

I can do this sensor manually via REST Custom BETA:

{
   "prtg":{
      "description":{
         "device":"http://127.0.0.1",
         "query":"/getApp"
      },
      "result":[
         {
            "channel":$.application[0].applicationParameters[0].name,
            "value":$.application[0].applicationParameters.count,
            "float":1,
            "decimalmode":"Auto",
            "unit":"custom",
            "customunit":"C"
         }
      ],
   }
}

Is it possible to do a foreach to match the Channel Name with a value ? Or another method, but I don't see how to do it?

Thank you!


Article Comments

Attention: This article is a record of a conversation with the Paessler support team. The information in this conversation is not updated to preserve the historical record. As a result, some of the information or recommendations in this conversation might be out of date.

Hi there,

Beside the fact that the above JSON is not valid and that "App3" is available twice, you can use the following syntax. This is not officially documented - due to complexity - but it works:

{
  "prtg": {
    "result": [
      {
        "value": {
            "["+ #1 +"]" + " connectCurrent": $..({ @.applicationName : @.applicationParameters[0].count }).*
        },
        "float":1,
        "decimalmode":"Auto",
        "unit":"custom",
        "customunit":"C"
      },
      {
        "value": {
          "["+ #1 +"]" + " connectMax": $..({ @.applicationName : @.applicationParameters[1].count }).*
        },
        "float":1,
        "decimalmode":"Auto",
        "unit":"custom",
        "customunit":"C"
      }
    ]
  }
}

What it basically does:

"["+ #1 +"]" + " connectMax":

This defines the channel name, "#1" is from the right side (@.applicationName) and it adds "connectMax" to the name.

$..({ @.applicationName : @.applicationParameters[0].count }).*

This matches basically all that is found under the above jsonpath.

Best regards.


Apr, 2019 - Permalink

Works Thanks for your help


Apr, 2019 - Permalink