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): invalid character '$'

Votes:

0

Hello,

We are using PRTG Version 17.4.33.3283+ and we have a lot of different websites we like to monitor with the REST Custom Sensor...

our websites response the health status in JSON like this but all with different services we like to check:

{"meta":{"status":["OK","NOK"],"statusCode":[0,-1]},"data":{"lastUpdated":"2018-04-30T06:53:32.962Z","overall":"OK","overallCode":0,"bundles":{"group":"OK","numTotal":242,"numActive":239,"numInstalled":0,"numResolved":3,"numFailure":0},"services":{"group":"OK","sismedia":"OK","solr":"OK","kachelmann":"OK","geotracks":"OK"}}}

so we did a JSON File in the custom file path to look for all services and convert the status from OK or NOK to 0 and 1

 {
    "prtg": {
      "result": [
        {
          "channel": "Status" ,
          "value": $.meta.statusCode
        },
        {
          "channel": "Overall",
          "value": $.data.overallCode
        },
        {
          "value": {lookup($.data.services.*, "OK", "NOK")}
        }
      ]
    }
  }

sadly , we get back an error could not load config: invalid character '$' looking for beginning of value

someone have an idea what we are doing wrong?

Thank you

json jsonpath rest-custom

Created on Apr 30, 2018 6:56:36 AM

Last change on Apr 30, 2018 8:36:43 AM by  Dariusz Gorka [Paessler Support]



11 Replies

Votes:

0

Hi there,

Please note that the sensor got updated in the recent versions which also changed the definition templates. You are currently using the new syntax, which will not work with the old sensor. Therefore please upgrade PRTG to a more recent version (better the most recent) and the template should work fine.

Best regards.

Created on Apr 30, 2018 8:38:26 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

thanks for reply! is there a way to use it in the old version? is the manual archived for the old version? we could not upgrade actually (need to test before with my colleagues from the pbx team)

Created on Apr 30, 2018 9:07:35 AM



Votes:

0

Hi there,

You should be able to find the old documentation within your webinterface under:

/help/rest_custom_sensor.htm


Best regards.

Created on Apr 30, 2018 9:14:22 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

awesome! thanks alot...

just struggling with Comparators,,, i like to have dynamic channel but without one string "group" done this so far:

"channel": "{data.bundles(?"!= 'data.bundles.group'")}",

any idea?

Created on Apr 30, 2018 12:46:46 PM



Votes:

0

Hi there,

Could you post the monitored JSON and explain what you want to achieve or what you want to monitor specifically?

Best regards.

Created on Apr 30, 2018 2:11:30 PM by  Dariusz Gorka [Paessler Support]



Votes:

0

This is my json, who i like to Monitor:

{
"meta":
	{ 
		"status":["OK","NOK"],
		"statusCode":[0,-1]
	},
		"data":
	{
		"lastUpdated":"2017-12-11T13:33:08.039Z",
		"overall":"OK",
		"overallCode":0,
		"bundles":
			{
				"group":"OK",
				"numTotal":240,
				"numActive":237,
				"numInstalled":0,
				"numResolved":3,
				"numFailure":0
			},
		"services":
			{
				"group":"OK",
				"sismedia":"OK",
				"solr":"OK",
				"kachelmann":"OK",
				"geotracks":"OK"
			}
	}
}

And my Template Looks like this

   {
  "Text": "status",
	"prtg": {
	  "description" : 
	{
      "device": "Stringcheck",
      "comment": "For PRTG Version 17.4.33.3283"
    },
      "result": [
        {
          "channel": "Overall",
          "value": "data.overallCode"
        },
		{
          "channel": "Last Updated",
          "value": "duration({data.lastUpdated}, now())"
        },
	{
		  "channel": "Group Bundles Status",
          "value": "lookup({data.bundles.group}, 'OK')"
		},
			{
		  "channel": "Bundles numTotal",
          "value": "{data.bundles.numTotal}"
		},
		{
		  "channel": "Bundles numActive",
          "value": "{data.bundles.numActive}"
		},
				{
		  "channel": "Bundles numInstalled",
          "value": "{data.bundles.numInstalled}"
		},
				{
		  "channel": "Bundles numResolved",
          "value": "{data.bundles.numResolved}"
		},
				{
		  "channel": "Bundles numFailure",
          "value": "{data.bundles.numFailure}"
		},
		{
		  "channel": "{data.services}",
          "value": "lookup('OK')"
		}
      ]
    }
  }

Actually i'm struggling at 2 Points: - i like to have the string "bundles" dynamicly but there is Group who Returns an OK and the others are number... in my Code above i changed it to seperated channels because i have no idea how to make a filter in this case

- where i struggle most is on the "Services" part... i like to have them dynamic because in future we like to Monitor different Websites allways whit the same template... the site will respone OK or NOK so i tried to do a dynamic channel with a lookup function that check if the Service is ok (0) or NOK (-1)

Created on Apr 30, 2018 2:19:56 PM



Votes:

0

Hi there,

I added the template in the newest version of PRTG and the sensor is created fine including the dynamic channels for the "services"-part. As mentioned, we can't really support the older version as the newer ones have further options and works better overall. It might be also the case that you have to touch the template again, once it is working with the older version.

I would recommend to setup a trial with the latest version of PRTG and creating the sensor within this trial/freeware so you can see if it works better now with the new documentation:
https://www.paessler.com/download/prtg-download

Best regards.

Created on May 1, 2018 8:05:01 AM by  Dariusz Gorka [Paessler Support]



Votes:

0

i came back here because i'm testing on a newer version... i have following json response:

{
	"meta":
	{
		"status":
		[
			"OK","NOK"
		],
		"statusCode":[0,-1]},
		"data":
			{
			"lastUpdated":"2018-09-11T10:54:54.043Z",
			"overall":"OK",
			"overallCode":0,
			"bundles":
				{
					"group":"OK",
					"numTotal":236,
					"numActive":233,
					"numInstalled":0,
					"numResolved":3,
					"numFailure":0
				}			,
			"services":
				{
					"group":"OK",
					"sismedia":"OK",
					"solr":"OK",
					"kachelmann":"OK",
					"geotracks":"OK"
				}
			}
}

and this prtg rest custom sensor json template:

{
    "prtg": {
      "result": [
        {
          "channel": "Status" ,
          "value": $.meta.statusCode
        },
        {
          "channel": "Overall",
          "value": $.data.overallCode
        },
        {
          "value": {lookup($.data.services.*, "OK", "NOK")}
        }
      ]
    }
  }

in my eyes it looks good, but my dynamic "data.services" Channels get following error:

Parsing error: { "prtg": { "result": [ { "channel": "Status" , "value": $.meta.statusCode }, { "channel": "Overall", "value": $.data.overallCode }, { "value": {lookup($.data.services.*, "OK", "NOK")} } ] } } :14:9 - 14:10 unexpected "}" while scanning extensions.

Created on Sep 13, 2018 2:26:28 PM



Votes:

0

Hi there,

I might have found the reason, why did you put the curly brackets around the lookup? Please try:

{
    "prtg": {
      "result": [
        {
          "channel": "Status" ,
          "value": $.meta.statusCode
        },
        {
          "channel": "Overall",
          "value": $.data.overallCode
        },
        {
          "value": lookup($.data.services.*, "OK", "NOK")
        }
      ]
    }
  }

Does that work?

Best regards.

Created on Sep 14, 2018 12:47:32 PM by  Dariusz Gorka [Paessler Support]



Votes:

0

I tested it and get following error now:

Could no evaluate channel value: expected type string for parameter 0 but got []interface {}.

Created on Sep 24, 2018 8:14:26 AM



Votes:

0

Hi there,

Now I get what you try. Unfortunately, that is not possible as the following part you request is not an array:

		"services": {
			"group": "OK",
			"sismedia": "OK",
			"solr": "OK",
			"kachelmann": "OK",
			"geotracks": "OK"
		}

Therefore PRTG can't iterate through these items and they need to be specified one by one.

Best regards.

Created on Sep 24, 2018 9:11:55 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.