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

REST custom sensor - dynamic channels

Votes:

0

I've been trying to get dynamic channels from a JSON file but been having issues. I need a list of the labels and their error statuses for each entry in my JSON file. There should only be about 7 results so i shouldn't be close to the 50 channel limit. In the simplified file i've included below the more children// sections actually go another 8 or 9 sublevels but i'm only interested in results from the top layer.

{
  "executionTime": {
    "millis": 128,
    "seconds": 0
  },
  "result": {
    "Plan": [
      {
        "error": "OK",
        "TimeOut": 0,
        "label": "Lable 1",
        "planId": 135,
        "planParts": {
          ~more children~ },
        "status": "STOPPED"
      },
      {
        "error": "OK",
        "TimeOut": 0,
        "label": "Label 2",
        "planId": 140,
        "planParts": {
          ~more children~ },
        "status": "STOPPED"
      },
      {
        "error": "OK",
        "TimeOut": 0,
        "label": "Label 3",
        "planId": 141,
        "planParts": {
	  ~more children~ },
        "status": "STOPPED"
      },
    ]
  },
  "returnCode": 0
}

After reading over this and this i've ended up with the below template

{
  "prtg": {
    "result": [
      {
        "value": { #1 : $.. ({ @.label : @.error[0]})}
      }
    ]
  }
}

But this just gives me one channel consisting of the Response Time. Can you help me out on what i'm missing here?

Thanks

dynamic json rest

Created on Jul 8, 2019 2:21:37 AM



8 Replies

Votes:

0

Hi there,

The current state of the sensor is BETA, therefore it is a bit more complicated to get dynamic results. However the following template should work:

{
  "prtg": {
    "result": [
      {
        "value": {
            "Error Status ["+ #1 +"]": $.result.Plan..({ @.label : lookup(@.error, "OK")}).*
        },
        "limitmode": 1,
        "LimitMinError": 0,
        "LimitErrorMsg": "The value for 'error' is not 'Ok'!"
      }
    ]
  }
}

Please note that PRTG can't monitor strings in dedicated channels, therefore I applied a lookup on the "Ok" value. This returns "0" if "OK" is found and "-1" if it is not found.

Best regards.

Created on Jul 8, 2019 10:06:41 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Thanks for the reply. This give me the expected results if I use rest.exe via the command line:

{
  "prtg": {
    "result": [
      {
        "channelid": 0,
        "Value": 164,
        "Unit": "TimeResponse",
        "ShowChart": 0,
        "ShowTable": 0
      },
      {
        "channel": "Error Status [Label 1]",
        "Value": -1,
        "LimitMinError": 0,
        "LimitErrorMsg": "The value for 'error' is not 'Ok'!",
        "LimitMode": 1
      },
      {
        "channel": "Error Status [Label 2]",
        "Value": 0,
        "LimitMinError": 0,
        "LimitErrorMsg": "The value for 'error' is not 'Ok'!",
        "LimitMode": 1
      },
      {
        "channel": "Error Status [Label 3]",
        "Value": 0,
        "LimitMinError": 0,
        "LimitErrorMsg": "The value for 'error' is not 'Ok'!",
        "LimitMode": 1
      }
    ]
  }
}

But when I add it as a PRTG sensor i'm not getting the list of channels:

Pic

Any other suggestions?

Created on Jul 8, 2019 11:26:47 PM



Votes:

0

Hi there,

Does it display any error message?
Have you made sure that the URL is correct (device address + url in the sensor)?

Best regards.

Created on Jul 9, 2019 6:50:33 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Hi, thanks.

Yes I've checked that the details are the same, and added it as a new sensor a couple of times to make sure. There is no error message - the sensor status is OK, log just shows the status as Up.

Created on Jul 9, 2019 11:40:41 PM



Votes:

0

Hi there,

Have you enabled the "Write Result to Disk" option and have you checked the returned logs under ""C:\ProgramData\Paessler\PRTG Network Monitor\Logs (Sensors)\"?

best regards.

Created on Jul 10, 2019 7:16:35 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Thanks. I've enabled that and it's still only giving me one channel.

Result of Sensor 5124.txt

{
  "prtg": {
    "result": [
      {
        "channelid": 0,
        "Value": 13,
        "Unit": "TimeResponse",
        "ShowChart": 0,
        "ShowTable": 0
      }
    ]
  }
}

Created on Jul 10, 2019 7:25:54 AM



Votes:

0

Hi there,

Please add a new HTTP Advanced Sensor under this device with the same URL that the REST Custom Sensor uses and enable the "Store latest HTML result". In the Logs folder of the sensors you should get three logs for the HTTP sensor. Please check them if the correct website is monitored.

best regards.

Created on Jul 10, 2019 6:24:53 PM by  Dariusz Gorka [Paessler Support]



Votes:

0

Hi. I copied the URL from the REST sensor and used it to create a new HTTP Advanced sensor, the logs indicate that it's connecting as expected.

Result of Sensor 5125.txt included sections of the JSON file split up like this (i've replaced url, host:port~ and more children):

Stat Connected.
Sent 7/11/2019 9:27:50 AM: GET ~url~ <EOL>
sensorid: 5125<EOL>
Cookie: UserCulture=en-US<EOL>
Host: ~host:port~ <EOL>
Accept: text/html, */*<EOL>
Accept-Encoding: identity<EOL>
User-Agent: Mozilla/5.0 (compatible; PRTG Network Monitor (www.paessler.com); Windows)<EOL>
<EOL>
Recv 7/11/2019 9:27:50 AM: HTTP/1.1 200 <EOL>
X-Frame-Options: SAMEORIGIN<EOL>
Content-Type: application/json;charset=ISO-8859-1<EOL>
Transfer-Encoding: chunked<EOL>
Date: Wed, 10 Jul 2019 23:27:49 GMT<EOL>
<EOL>
2000<EOL>
{"executionTime":{"millis":91,"seconds":0},"result":{"Plan":[{"error":"OK","TimeOut":0,"label":"Label 1","planId":135,"planParts":{"childParts":[{ ~more children~ ... <EOL>
<EOL>
Stat Disconnected.

Result of Sensor 5125-A.txt just included the whole JSON file.

Thanks

Created on Jul 11, 2019 12:11:30 AM




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.