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 JSON template

Votes:

0

Hello,

I woul like to create a REST custom sensor to monitor a JSON return value.

The return value looks like this:

"imageUrl":"http://my/path/isec_ydufow7v.png",
"legendUrl":null,
"errorCode":0,
"errorMessage":null,
"thumbUrl":"http://my/path/thumbnail_bore.png"

I would like to us a JSON template which looks at "errorCode" and "errorMessage". If errorCode is not 0 than an error occured. I tried:

  "prtg": {
    "error": ($.errorCode == 0) ? "0" : "1",
    "text": $.errorMessage
  }

But I get the following PRTG error:

Parsing error: { "prtg": { "error": ($.errorCode == 0) ? "0" : "1", "text": $.errorMessage } }:6:1 - 6:2 no channels defined.

I know that I didn't create a channel but I don't really have channels in my JSON return value. What is the best way to handle this? I thought that text and error can be used outsid a result section?

Thank you for your help, Carolin

json prtg rest

Created on Jun 21, 2018 1:06:24 PM

Last change on Jun 22, 2018 5:57:29 AM by  Luciano Lingnau [Paessler]



5 Replies

Votes:

0

Hi there,

Unfortunately, the output is not correct as PRTG always requires a channel (as the error message indicates).

Please change output accordingly to the example templates on the Core Server under "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\rest\" and to the documentation:
https://www.paessler.com/manuals/prtg/rest_custom_sensor

Please also note that the following is not valid (check the documentation above):

($.errorCode == 0) ? "0" : "1"



Best regards,

Created on Jun 22, 2018 10:23:35 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Hi there,

thank you for your answer. I assumed that PRTG requires a channel. How can I return the errorCode and errorMessage when defining a channel?

If I only say:

{
	"prtg": {
           "result": [
            {
             "channel": "GST_Section",
             "value": $.errorCode
            }
           ]
          }
}

the sensor remains green ("OK") even when an error occurs. I can set the maximum value manually in the channel settings in PRTG but I can't get the JSON errorMessage. If I try something like:

{
	"prtg": {
           "result": [
            {
             "channel": "GST_Section",
             "value": $.errorCode,
	     "limitmode": 1,
	     "limiterrormsg": $.errorMessage,
	     "limitmaxerror": 1
            }
           ]
          }
}

I get an error saying:

Parsing error: { "prtg": { "result": [ { "channel": "GST_Section", "value": $.errorCode, "limitmode": 1, "limiterrormsg": $.errorMessage, "limitmaxerror": 1 } ] } } :8:36 - 8:37 expected constant.

Thanks for your help, Carolin

Created on Jun 22, 2018 1:31:52 PM



Votes:

0

Hi there,

Is this really all that is returned by the API?

"imageUrl":"http://my/path/isec_ydufow7v.png",
"legendUrl":null,
"errorCode":0,
"errorMessage":null,
"thumbUrl":"http://my/path/thumbnail_bore.png"

You can test the "value definition" ($.errorCode) on the following site to see if the path is correct:
https://jsonlint.com

Additionally, the "limitmax" should be set to "0" when you want to get alerted whenever the value of "errorCode" is above "0". The template itself should work, as long as the path is correct:

{
	"prtg": {
           "result": [
            {
             "channel": "GST_Section",
             "value": $.errorCode,
	     "limitmode": 1,
	     "limiterrormsg": $.errorMessage,
	     "limitmaxerror": 1
            }
           ]
          }
}


Best regards.

Created on Jun 25, 2018 8:15:20 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

Hi,

yes, that is all that is returned.

The path is correct and it works fine if I only use

{
             "channel": "GST_Section",
             "value": $.errorCode
            }

But I want to see the error Message too. But I get the error ":8:36 - 8:37 expected constant". I asume that the $.errorMessage is not the correct type? The errorMessage is only a string if an error occurs, otherwise it says null (not "null"). Might that be a problem?

Thank you, Carolin

Created on Jun 25, 2018 8:32:49 AM



Votes:

0

Hi there,

The following template will create a channel with the value from "$.errorCode" and the displays "$.errorMessage" in the sensor message:

{
  "prtg": {
    "text": $.errorMessage,
    "result": [
      {
        "channel": "GST_Section",
        "value": $.errorCode
      }
    ]
  }
}

Does that work?

Created on Jun 25, 2018 10:45:52 AM by  Dariusz Gorka [Paessler Support]




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.