PRTG Manual: REST Custom Sensor
This sensor is in beta status. The operating methods and the available settings can change at any time. Do not expect that all functions work properly, or that this sensor works as expected at all. Be aware that this sensor can be removed from PRTG at any time.
The REST Custom sensor queries a Representational State Transfer (REST) application programming interface (API) endpoint and maps the JavaScript Object Notation (JSON) or Extensible Markup Language (XML) result to sensor values. The mapping rule has to be available as a REST configuration file in JSON template (*.template) format according to the PRTG API definition for custom sensors.
The sensor can show the following:
- Values returned by a REST API in multiple channels
For details about the return value format, see section Custom Sensors.
- Dutch: REST Aangepast
- French: REST personnalisé
- German: REST (Benutzerdef.)
- Japanese: REST カスタム
- Portuguese: REST (Customizado)
- Russian: Специальные настройки REST
- Simplified Chinese: REST 自定义
- Spanish: REST personalizado
- You must store the REST configuration file that contains the mapping rules on the probe system. In a cluster, copy the file to every cluster node.
- This sensor does not officially support more than 50 channels. Depending on the data used with this sensor, you might exceed the maximum number of supported channels. In this case, PRTG tries to display all channels. Be aware, however, that you experience limited usability and performance. If you have more than 50 channel mappings in your REST configuration file, the sensor shows an error.
- This sensor supports the IPv6 protocol.
- This sensor has a medium performance impact.
- In a cluster, status changes triggered by limits only work on the master node.
You cannot add this sensor to the hosted probe of a PRTG hosted by Paessler instance. If you want to use this sensor, add it to a remote probe device.
The Add Sensor dialog appears when you manually add a new sensor to a device. It only shows the setting fields that are required for creating the sensor. Therefore, you do not see all setting fields in this dialog. You can change (nearly) all settings in the sensor's Settings tab later.
The following settings in the Add Sensor dialog differ in comparison to the sensor's Settings tab.
REST Specific
Setting |
Description |
---|---|
REST Configuration |
Select a REST configuration file from the list. The sensor uses it to map the JSON or XML result from the REST query to sensor values. The default is channelDiscovery. If you select this REST configuration, the sensor parses the returned JSON or XML and automatically creates channels based on available values: one channel for each number and boolean for strings if they are convertible into numbers. This list shows all available files in the \Custom Sensors\rest subfolder of the PRTG program directory on the probe system. To appear in this list, store the files as JSON template (*.template) in this subfolder.
To show the expected values and sensor status, your files must return the expected JSON format. Channels, values, and messages must be embedded in valid JSON using JSONPath. For details, see section Define Channels and Select Channel Values.
|
Click the Settings tab of a sensor to change its settings.
Usually, a sensor connects to the IP Address or DNS Name of the parent device on which you created the sensor. See the device settings for details. For some sensors, you can explicitly define the monitoring target in the sensor settings. See below for details on available settings.
Setting |
Description |
---|---|
Sensor Name |
Enter a meaningful name to identify the sensor. By default, PRTG shows this name in the device tree, as well as in alarms, logs, notifications, reports, maps, libraries, and tickets.
|
Parent Tags |
Shows tags that the sensor inherits from its parent device, parent group, and parent probe. This setting is shown for your information only and cannot be changed here. |
Tags |
Enter one or more tags. Confirm each tag with the Spacebar key, a comma, or the Enter key. You can use tags to group objects and use tag-filtered views later on. Tags are not case-sensitive. Tags are automatically inherited.
The sensor has the following default tags that are automatically predefined in the sensor's settings when you add the sensor:
|
Priority |
Select a priority for the sensor. This setting determines the position of the sensor in lists. The highest priority is at the top of a list. Choose from the lowest priority ( |
Setting |
Description |
---|---|
Timeout (Sec.) |
Enter a timeout in seconds for the request. If the reply takes longer than this value, the sensor cancels the request and shows a corresponding error message. Enter an integer value. The maximum value is 900 seconds (15 minutes). |
Request Method |
Select an HTTP request method to determine how the sensor requests the REST API.
|
Postdata |
This setting is only visible if you enable POST above. Enter the data part for the POST request here.
|
Request Protocol |
Define the security protocol of the HTTP request:
|
Certificate Acceptance |
This setting is only visible if you enable HTTPS above. Select the kind of certificates that you want the sensor to accept for the connection:
|
Authentication Method |
Select the authentication method for access to the REST API:
|
User |
This setting is only visible if you enable Basic authentication above. Enter a username for the REST API. Enter a string. |
Password |
This setting is only visible if you enable Basic authentication above. Enter a password for the REST API. Enter a string. |
Token |
This setting is only visible if you enable Token above. Enter a JWT or OAuth2 Bearer Token that is required by the REST API for authentication. |
HTTP Headers |
Define if you want to send custom HTTP headers to the target URL:
|
Custom HTTP Headers |
This setting is only visible if you select Use custom HTTP headers above. Enter a list of custom HTTP headers with their respective values that you want to transmit to the URL you defined above, each pair in one line. The syntax of a header-value pair is header1:value1.
|
REST Query |
This field shows the REST query that this sensor executes. To change it, enter a valid query for the target REST API. The syntax is: [:port]/path[?var1=val1&...]
For example, if you add the sensor to a probe device, a query to the REST API of your PRTG installation that returns the number of sensors on the probe would look like this: /api/table.json?id=1&passhash=<passhash>&username=<username>&content=sensorxref&noraw=1&filter_basetype=probe&columns=totalsens=textraw |
REST Configuration |
Shows the REST configuration file that the sensor uses to map returned JSON or XML into sensor values. Once you have created the sensor, you cannot change this value. It is shown for reference purposes only. If you need to change this value, add the sensor anew. |
Setting |
Description |
---|---|
Result Handling |
Define what PRTG does with the sensor result:
|
Setting |
Description |
---|---|
Primary Channel |
Select a channel from the list to define it as the primary channel. In the device tree, the last value of the primary channel is always displayed below the sensor's name. The available options depend on what channels are available for this sensor.
|
Graph Type |
Define how different channels are shown for this sensor:
|
Stack Unit |
This setting is only visible if you enable Stack channels on top of each other as Graph Type. Select a unit from the list. All channels with this unit are stacked on top of each other. By default, you cannot exclude single channels from stacking if they use the selected unit. However, there is an advanced procedure to do so. |
By default, all of the following settings are inherited from objects that are higher in the hierarchy. You should change them centrally in the root group settings if necessary. To change a setting for this object only, click under the corresponding setting name to disable the inheritance. You then see the options described below.
For more information, see section Inheritance of Settings.
Proxy Settings for HTTP Sensors
Click to interrupt the inheritance.
The proxy settings determine how a sensor connects to a URL. You can enter data for an HTTP proxy server that sensors use when they connect via HTTP or HTTPS.
This setting only applies to HTTP sensors and how they monitor. To change the proxy settings for the PRTG core server, see section Core & Probes.
Setting |
Description |
---|---|
Name |
Enter the IP address or Domain Name System (DNS) name of the proxy server. If you leave this field empty, HTTP sensors do not use a proxy. |
Port |
Enter the port number of the proxy. The default is 8080. Enter an integer value. |
User |
If the proxy requires authentication, enter the username for the proxy login.
|
Password |
If the proxy requires authentication, enter the password for the proxy login.
|
Click to interrupt the inheritance.
Setting |
Description |
---|---|
Scanning Interval |
Select a scanning interval from the dropdown list. The scanning interval determines the amount of time that the sensor waits between two scans. Choose from:
|
If a Sensor Query Fails |
Select the number of scanning intervals that the sensor has time to reach and to check a device again if a sensor query fails. Depending on the option that you select, the sensor can try to reach and to check a device again several times before the sensor shows the Down status. This can avoid false alarms if the monitored device only has temporary issues. For previous scanning intervals with failed requests, the sensor shows the Warning status. Choose from:
|
Schedules, Dependencies, and Maintenance Window
You cannot interrupt the inheritance for schedules, dependencies, and maintenance windows. The corresponding settings from the parent objects are always active. However, you can define additional schedules, dependencies, and maintenance windows. They are active at the same time as the parent objects' settings.
Setting |
Description |
---|---|
Schedule |
Select a schedule from the list. You can use schedules to monitor during a certain time span (days or hours) every week. Choose from:
|
Maintenance Window |
Select if you want to set up a one-time maintenance window. During a maintenance window, monitoring stops for the selected object and all child objects. They show the Paused status instead. Choose between:
|
Maintenance Begins |
This setting is only visible if you enable Set up a one-time maintenance window above. Use the date time picker to enter the start date and time of the one-time maintenance window. |
Maintenance Ends |
This setting is only visible if you enable Set up a one-time maintenance window above. Use the date time picker to enter the end date and time of the one-time maintenance window. |
Dependency Type |
Select a dependency type. You can use dependencies to pause monitoring for an object depending on the status of a different object. You can choose from:
|
Dependency |
This setting is only visible if you enable Select a sensor above. Click |
Dependency Delay (Sec.) |
This setting is only visible if you enable Select a sensor above. Define a time span in seconds for the dependency delay. After the master sensor for this dependency returns to the Up status, PRTG additionally delays the monitoring of the dependent objects by the time span you define. This can prevent false alarms, for example, after a server restart or to give systems more time for all services to start. Enter an integer value.
|
Click to interrupt the inheritance.
Setting |
Description |
---|---|
User Group Access |
Define the user groups that have access to the sensor. You see a table with user groups and group access rights. The table contains all user groups in your setup. For each user group, you can choose from the following group access rights:
|
Click to interrupt the inheritance.
Setting |
Description |
---|---|
Channel Unit Types |
For each type of channel, select the unit in which PRTG displays the data. If you define this setting on probe, group, or device level, these settings can be inherited to all sensors underneath. You can set units for the following channel types (if available):
|
Define Channels and Select Channel Values
In your REST configuration file, you have to define which values of the returned JSON or XML are mapped to which channels.
- A channel is defined by the channel key in your REST configuration. See the JSON Return Format: Minimum Example in section Custom Sensors.
- A channel value is defined by an expression that retrieves and processes the value from the JSON source. The expression can contain JSONPath, gval operators, and functions.
For this example, we take PRTG as REST endpoint and query the sensor status statistics for the local probe. The REST query that we enter in the sensor settings looks like this: /api/table.json?id=1&passhash=<passhash>&username=<username>&content=sensorxref&
This REST query returns some JSON, for example: { Your REST configuration has to translate this JSON for the sensor. It has to be available as JSON template (*template) in the \Custom Sensors\rest subfolder of the PRTG program directory on the probe system. See section Custom Sensors for details about the JSON return format. The following example returns two channels from the JSON resource that are added to the sensor in PRTG, Total (total sensor count) and Alarms (sensors in the Down status), each selected by their keys in the returned JSON. { The channel values are the values of the corresponding properties of the REST result defined in JSONPath notation, $.sensorxref[0].totalsens (28) and $.sensorxref[0].downsens (0). Each value's property (destination) and the text property is set to the appropriate transformation rules from source to destination. This is the JSON path of the source. The sensor replaces each path with the value from the source. |
Several REST configuration files are available in the \Custom Sensors\rest subfolder by default. They are ready for use. You can also analyze them to see how to write your own REST configuration.
The REST Custom sensor uses JSONPath to assign values from the returned JSON to channels. With JSONPath, you provide the path to the value in the JSON source that you want to monitor in a channel.
The JSONPath implementation that PRTG uses for the REST Custom sensor might differ from other JSONPath implementations. You can test and debug your definitions using the command line. To test simple JSONPath expressions and calculations, you can also use JSONPath Online Evaluator, for example. Note that this tool might not work properly with complex JSONPath expressions that PRTG supports.
To demonstrate the practical usage of JSONPath, we use this JSON example that a REST query might have returned as reference in this section. { |
Root |
The dollar sign ($) matches the root element of the JSON data. |
Child |
You can match a child with .<key> or [<key>]
This expression matches 35985021 in the example above: $.devices.0.networks.a.rx_bytes You get the same result with this expression: $["devices"][0]["networks"]["a"]["rx_bytes"] If an element contains a hyphen (-), the .<key> notation does not work. Use the [<key>] notation in this case: $["data"][0]["system-stats"]["temps"]["Board (CPU)"] |
Wildcard |
To match multiple values, you can use the asterisk symbol (*).
This expression matches 35985021 and 40085321 in the example above: $.devices[0].networks.*.rx_bytes |
Recursive Descent |
You can match all subitems of a node with two dots (..).
This expression matches 7229493 and 55294975 and 7229472 in the example above: $..tx_bytes |
Union |
You can match multiple children with [<key1>,<key2>,<...>].
This expression matches 35985021 and 7229493 in the example above: $.devices.0.networks.a["rx_bytes","tx_bytes"] |
Slice |
You can match multiple children of an array with [<begin>:<end>] or [<begin>:<end>:<step>].
This expression matches 63685865 in the example above: $.devices[-1:].networks.a.rx_bytes |
Current |
The @ symbol matches the current element.
This expression matches 40.085321 and 55.294975 in the example above and can be used to receive a percentage value: $.devices[1].networks.a.["rx_bytes","tx_bytes"](@/100000000*100) |
Filter |
You can filter matches with [?<expression>].
This expression matches 35985021 in the example above because the first device is the only one with a beta channel: $.devices[[email protected]=="beta"].networks.a.rx_bytes |
Script |
You can modify matches with (<expression>) and keys with [<expression>].
This expression matches true and false in the example above because only the first device has a beta channel: $.devices[*](@.firmware.channel=="beta") |
Placeholder |
Placeholders give access to values of wildcards in a match. A placeholder #n (where n is a natural number) represents the value of the nth wildcard. You can use this in the keys of JSON arrays.
This expression creates a JSON map from ids to the corresponding firmware channel and matches {"0.7":"beta"} in the example above: {$.devices[#0].id:$.devices[*].channel}
|
Constant |
|
Operator |
|
Calculating Channel Values and Functions
You can perform calculations with the values of the source JSON or XML. The sensor uses the Paessler gval package for the calculations. For details, refer to the gval documentation.
The following operators and functions are available to calculate channel values.
|
Operator |
Description |
Operand Type |
Output Type |
Infix Modifiers |
+ |
plus |
number |
number |
- |
minus |
number |
number |
|
* |
times |
number |
number |
|
** |
power of |
number |
number |
|
% |
modulo |
number |
number |
|
/ |
divide |
number |
number |
|
& |
bitwise and |
number |
number |
|
| |
bitwise or |
number |
number |
|
^ |
bitwise xor |
number |
number |
|
<< |
shift left |
number |
number |
|
>> |
shift right |
number |
number |
|
Logical Infix Operators |
> |
greater than |
number/string |
bool |
>= |
equal or greater than |
number/string |
bool |
|
< |
less than |
number/string |
bool |
|
<= |
equal or less than |
number/string |
bool |
|
== |
equal |
any |
bool |
|
!= |
not equal |
any |
bool |
|
=~ |
match regular expression |
string |
bool |
|
!~ |
mismatch regular expression |
string |
bool |
|
in |
contains element |
any, array |
bool |
|
&& |
and |
and |
bool |
|
|| |
or |
or |
bool |
|
?? |
coalescence |
any |
any |
|
Prefix Operators |
- |
negative |
number |
number |
~ |
bitwise not |
number |
number |
|
! |
not |
bool |
bool |
duration(start,end) |
duration($.devices[0].firmware.date, "017-05-18T17:11:43.7049944Z") |
now() |
duration($.devices[0].firmware.date, now()) |
number(string, [base]) |
number("10.5") |
len(object/array/string) |
len($..(number(@))) This expression counts every number or string that can be converted into a number. It returns 13 in the example above. |
sum(array-/object-of-numbers) |
sum([1,2,3]) This expression returns 6. |
mean(array-/object-of-numbers) |
mean([1,2,3]) This expression returns 2. |
lookup(string, string, string, ...) |
lookup($.device[0].firmware.channel, "stable", "beta", "alpha") This expression returns 1 because $.device[0].firmware.channel resolves to beta. |
implode(array-/object-of-string, string) |
implode($..tx_bytes, ",") This expression returns 7229493,7229472. |
You can create a template in your REST configuration that defines generic channels. Generic channels are created based on the data that the REST endpoint returns. When the returned value is an array or object, the sensor creates a channel for each element and concatenates the corresponding key to the channel name.
Example
Imagine that you want to have a total byte channel for each network card that is defined in the JSON example above. You can do this by creating a dynamic channel like in the following example.
{
"prtg": {
"result":[
{
"value": {
"Total bytes on device" + #0 + " in network " + #1: $.devices.*.networks[*](@.rx_bytes + @.tx_bytes)
},
"CustomUnit": "Bytes"
}
]
}
}
Every channel must have a unique name. You cannot remove channels once they have been added and they keep their last received value. You can add new channels.
If the REST source returns XML instead of JSON, the sensor transforms the XML result to JSON before replacing the value paths with source values. Because of this, you do not know the structure of the source JSON to correctly provide the paths.
In this case, manually execute the sensor executable rest.exe from the \Sensor System subfolder of the PRTG program directory on the probe system. Execute rest.exe with the address of the XML endpoint and the parameter passthrough. The rest executable returns the converted XML to a JSON result that you can use to define the desired paths.
rest.exe <xml-endpoint-url> passthrough
To create a suitable REST configuration for the sensor, you might want to check the returned JSON or XML and see what happens when your mapping rules apply.
The REST Custom sensor is an EXE sensor, so you can test and debug your configuration by executing rest.exe with several parameters. The rest.exe file is located in the \Sensor System subfolder of the PRTG program directory.
The command syntax is as follows:
rest.exe url template|passthrough|channelDiscovery [flags]
rest.exe: Parameters |
|
---|---|
url |
|
template |
|
passthrough |
|
channelDiscovery |
|
rest.exe: Flags |
|
---|---|
-authtoken <string> |
|
-authusername <string> |
|
-authuserpwd <string> |
|
-post <string> |
|
-proxy <string> |
|
-proxyusername <string> |
|
-proxyuserpwd <string> |
|
-tlsignore <string> |
|
-customheaders <string> |
|
-template |
|
-timeout <integer> |
|
PRTG MANUAL
KNOWLEDGE BASE
Can I create a sensor to monitor the number of paused or unknown sensors?
MISCELLANEOUS
Paessler JSONPath
Paessler Gval
JSONPath Online Evaluator
For more information about sensor settings, see the following sections: