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

Dynamic REST Custom channel Name

Votes:

0

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!

api custom-sensor json prtg rest

Created on Apr 16, 2019 7:48:30 AM



2 Replies

Accepted Answer

Votes:

2

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.

Created on Apr 16, 2019 11:17:31 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Works Thanks for your help

Created on Apr 16, 2019 2:14:35 PM




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.