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


Article Comments

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,


Jun, 2018 - Permalink

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


Jun, 2018 - Permalink

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.


Jun, 2018 - Permalink

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


Jun, 2018 - Permalink

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?


Jun, 2018 - Permalink