<%NUMBERING1%>.<%NUMBERING2%>.<%NUMBERING3%> PRTG Manual: REST Custom Sensor
The REST Custom sensor queries a REST Application Programming Interface (API) endpoint and maps the JSON or XML result to sensor values. The mapping rule has to be available as a REST configuration file in JSON format according to the PRTG API definition for custom sensors.
- The sensor can show values returned by a REST API in multiple channels.
For details about the return value format, see section Application Programming Interface (API) Definition.
REST Custom Sensor
Click here to enlarge: https://media.paessler.com/prtg-screenshots/REST_Custom.png
Remarks
You cannot add this sensor type to cloud probes in PRTG in the cloud. If you want to use this sensor type, please add it to a remote probe device.
Limited to 50 Sensor Channels
PRTG does not support more than 50 sensor channels officially. Depending on the data used with this sensor type, you might exceed the maximum number of supported sensor channels. In this case, PRTG will try to display all sensor channels. However, please be aware that you will experience limited usability and performance.
Add Sensor
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 will not see all setting fields in this dialog. You can change (nearly) all settings in the sensor's Settings tab later.
The following settings for this sensor differ in the Add Sensor dialog in comparison to the sensor's settings page.
|
REST Configuration
|
Select a REST configuration from the list. The sensor will use it to map the JSON or XML result from the REST query into sensor values.
Default is channelDiscovery. If you choose this REST configuration, the sensor will parse the returned JSON or XML and automatically create 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 sub-directory of the probe system's PRTG program directory (see Data Storage). To appear in this list, store the files in JSON format (*.json) into this folder.
To show the expected values and sensor status, your files must return the expected JSON format. Values and message must be embedded in valid JSON.
For detailed information on how to build custom sensors and for the expected return format, see the API documentation in your PRTG installation. There, find detailed information on the Custom Sensors tab. See also manual section Application Programming Interface (API) Definition for more information.
There are several REST configuration files available by default. They are ready to use. You can also analyze them to see how to write your own REST configuration.
When using custom sensors on the Cluster Probe, please copy your files to every cluster node installation.
|
Sensor Settings
On the details page of a sensor, click the Settings tab to change its settings.
Usually, a sensor connects to the IP Address or DNS Name of the parent device where you created this sensor. See the Device Settings for details. For some sensor types, you can define the monitoring target explicitly in the sensor settings. Please see below for details on available settings.
|
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 this sensor inherits from its parent device, group, and probe. This setting is shown for your information only and cannot be changed here.
|
Tags
|
Enter one or more Tags, separated by spaces or commas. You can use tags to group sensors and use tag–filtered views later on. Tags are not case sensitive. We recommend that you use the default value.
You can add additional tags to the sensor if you like. Other tags are automatically inherited from objects further up in the device tree. These are visible above as Parent Tags.
|
Priority
|
Select a priority for the sensor. This setting determines where the sensor is placed in sensor lists. Top priority is at the top of a list. Choose from one star (low priority) to five stars (top priority).
|
|
Timeout (Sec.)
|
Enter a timeout in seconds for the request. If the reply takes longer than this value defines, the sensor will cancel the request and show a corresponding error message. Please enter an integer value. The maximum value is 900 seconds (15 minutes).
|
Request Method
|
Choose an HTTP request method to determine how the sensor will request the REST API.
- GET (default): Use the GET method to request the REST API.
- POST: Use the POST method to request the REST API.
|
Request Protocol
|
Define the security of the HTTP request. Choose between:
- HTTP (default): Send the REST query via insecure HTTP.
- HTTPS: Send the REST query via secure HTTPS.
|
Authentication Method
|
Select the authentication method for access to the REST API. Choose between:
- No authentication (default): Do not use any authentication for the request.
- Basic authentication: Use simple username and password authentication.
- Token: Use a JSON Web Token (JWT) or OAuth2 Bearer Token for authentication.
|
User
|
This field is only visible if you enable basic authentication above. Enter a username for the REST API. Please enter a string.
|
Password
|
This field is only visible if you enable basic authentication above. Enter a password for the REST API. Please enter a string.
|
Token
|
This field is only visible if you enable token authentication 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. Choose between:
- Do not use custom HTTP headers
- Use custom HTTP headers
|
Custom HTTP Headers
|
This field is only available if you select using custom headers above. Enter a list of custom HTTP headers with theirs respective values that you want to transmit to the URL you define above, each pair in one line. The syntax of a header-value pair is header1:value1
The sensor does not support the header field names user-agent, content-length, host.
Ensure the HTTP header statement is valid! Otherwise, the sensor request will not be successful.
|
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&...]
The first part of the address is always inherited from the parent device's address. Only enter the path to the REST endpoint of the parent device. You can override the port if necessary.
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 a sensor is created, you cannot change this value. It is shown for reference purposes only. If you need to change this, please add the sensor anew.
|
|
Sensor Result
|
Define what PRTG will do with the sensor results. Choose between:
- Discard sensor result: Do not store the sensor result.
- Write sensor result to disk (Filename: "Result of Sensor [ID].txt"): Store the last result received from the sensor to the Logs (Sensor) directory in the PRTG data folder on the probe system the sensor is running on (on the Master node if in a cluster). File names: Result of Sensor [ID].txt and Result of Sensor [ID].Data.txt. This is for debugging purposes. PRTG overrides these files with each scanning interval.
For more information on how to find the folder used for storage, see section Data Storage.
This option is not available on cloud probes in PRTG in the cloud.
|
|
Primary Channel
|
Overview
|
Graph Type
|
Define how different channels will be shown for this sensor.
- Show channels independently (default): Show an own graph for each channel.
- Stack channels on top of each other: Stack channels on top of each other to create a multi-channel graph. This will generate an easy-to-read graph that visualizes the different components of your total traffic.
This option cannot be used in combination with manual Vertical Axis Scaling (available in the Sensor Channels Settings settings).
|
Stack Unit
|
This setting is only available if stacked graphs are selected above. Choose a unit from the list. All channels with this unit will be 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.
|
Inherited Settings
By default, all following settings are inherited from objects higher in the hierarchy and should be changed there, if necessary. Often, best practice is to change them centrally in the Root group's settings. To change a setting only for this object, disable inheritance by clicking the check mark in front of the corresponding setting name. You will then see the options described below.
|
HTTP Proxy Settings
|
The proxy settings determine how a sensor connects to a given URL. You can enter data for an HTTP proxy server that sensors will use when connecting via HTTP or HTTPS.
This setting affects monitoring only and determines the behavior of HTTP sensors. To change proxy settings for the core server, please see System Administration—Core & Probes
The SSL Certificate Sensor and the SSL Security Check Sensor do not support HTTP proxies, but you can configure connections via SOCKS proxies in their sensor settings.
|
Name
|
Enter the IP address or DNS name of the proxy server to use. If you leave this field empty, no proxy will be used.
|
Port
|
Enter the port number of the proxy. Often, port 8080 is used. Please enter an integer value.
|
User
|
If the proxy requires authentication, enter the username for the proxy login.
Only basic authentication is available! Please enter a string or leave the field empty.
|
Password
|
If the proxy requires authentication, enter the password for the proxy login.
Only basic authentication is available! Please enter a string or leave the field empty.
|
|
Scanning Interval
|
Select a scanning interval (seconds, minutes, or hours) from the list. The scanning interval determines the time the sensor waits between two scans. You can change the available intervals in the system administration on PRTG on premises installations.
|
If a Sensor Query Fails
|
Define the number of scanning intervals that a sensor has time reach and check a device again in case a sensor query fails. The sensor can try to re-reach and check a device several times, depending on the option you select here, before it will be set to a Down status. This helps you avoid false alarms if the monitored device has only temporary issues. For previous scanning intervals with failed requests, the sensor will show a Warning status. Choose between:
- Set sensor to "down" immediately: The sensor will show an error immediately after the first failed request.
- Set sensor to "warning" for 1 interval, then set to "down" (recommended): After the first failed request, the sensor will show a yellow warning status. If the following request also fails, the sensor will show an error.
- Set sensor to "warning" for 2 intervals, then set to "down": Show an error status only after three continuously failed requests.
- Set sensor to "warning" for 3 intervals, then set to "down": Show an error status only after four continuously failed requests.
- Set sensor to "warning" for 4 intervals, then set to "down": Show an error status only after five continuously failed requests.
- Set sensor to "warning" for 5 intervals, then set to "down": Show an error status only after six continuously failed requests.
Sensors that monitor via Windows Management Instrumentation (WMI) always wait at least one scanning interval until they show an error. It is not possible to set a WMI sensor to "down" immediately, so the first option will not apply to these sensor types. All other options can apply.
If a sensor has defined error limits for channels, it will always show a Down status immediately, so no "wait" option will apply.
If a channel uses lookup values, it will always show a Down status immediately, so no "wait" options will apply.
|
|
Inheritance for schedules, dependencies, and maintenance windows cannot be interrupted. The corresponding settings from the parent objects will always be active. However, you can define additional settings here. They will be active at the same time as the parent objects' settings.
|
Schedule
|
Select a schedule from the list. Schedules can be used to monitor for a certain time span (days, hours) every week. With the period list option it is also possible to pause monitoring for a specific time span. You can create new schedules and edit existing ones in the account settings.
Schedules are generally inherited. New schedules will be added to existing ones, so all schedules are active at the same time.
|
Maintenance Window
|
- Not set (monitor continuously): No maintenance window will be set and monitoring will always be active.
- Set up a one-time maintenance window: Pause monitoring within a maintenance window. You can define a time span for a monitoring pause below and change it even for a currently running maintenance window.
To terminate a current maintenance window before the defined end date, change the time entry in Maintenance Ends field to a date in the past.
|
Maintenance Begins
|
This field is only visible if you enabled the maintenance window above. Use the date time picker to enter the start date and time of the maintenance window.
|
Maintenance Ends
|
This field is only visible if you enabled the maintenance window above. Use the date time picker to enter the end date and time of the maintenance window.
|
Dependency Type
|
Define a dependency type. Dependencies can be used to pause monitoring for an object depending on the status of another. You can choose between:
- Use parent: Pause the current sensor if the device, where it is created on, is in Down status, or is paused by another dependency.
- Select object: Pause the current sensor if the device, where it is created on, is in Down status, or is paused by another dependency. Additionally, pause the current sensor if a specific other object in the device tree is in Down status, or is paused by another dependency. Select below.
- Master object for parent: Make this sensor the master object for its parent device. The sensor will influence the behavior of the device, where it is created on: If the sensor is in Down status, the device will be paused. For example, it is a good idea to make a Ping sensor the master object for its parent device to pause monitoring for all other sensors on the device in case the device cannot even be pinged. Additionally, the sensor will be paused if the parent group of its parent device is in Down status, or if it is paused by another dependency.
Testing your dependencies is easy! Simply choose Simulate Error Status from the context menu of an object that other objects depend on. A few seconds later all dependent objects should be paused. You can check all dependencies in your PRTG installation by selecting Devices | Dependencies from the main menu bar.
|
Dependency
|
This field is only visible if the Select object option is enabled above. Click on the reading-glasses and use the object selector to choose an object on which the current sensor will depend.
|
Dependency Delay (Sec.)
|
Define a time span in seconds for a dependency delay. After the master object for this dependency goes back to Up status, PRTG will start monitoring the depending objects after this extra delayed. This can help to avoid false alarms, for example, after a server restart, by giving systems more time for all services to start up. Please enter an integer value.
This setting is not available if you choose this sensor to Use parent or to be the Master object for parent. In this case, please define delays in the parent Device Settings or in the superior Group Settings.
|
|
User Group Access
|
Define which user group(s) will have access to the object you're editing. A table with user groups and types of access rights is shown: It contains all user groups from your setup. For each user group you can choose from the following access rights:
- Inherited: Use the access rights settings of the parent object.
- None: Users in this group cannot see or edit the object. The object neither shows up in lists nor in the device tree. Exception: If a child object is visible to the user, the object is visible in the device tree, though not accessible.
- Read: Users in this group can see the object and review its monitoring results.
- Write: Users in this group can see the object, review its monitoring results, and edit the object's settings. They cannot edit access rights settings.
- Full: Users in this group can see the object, review its monitoring results, edit the object's settings, and edit access rights settings.
You can create new user groups in the System Administration—User Groups settings. To automatically set all objects further down in the hierarchy to inherit this object's access rights, set a check mark for the Revert children's access rights to inherited option.
For more details on access rights, please see the section User Access Rights.
|
|
Channel Unit Types
|
- Bandwidth
- Memory
- Disk
- File
- Custom
|
Define Sensor Channels and Select Channel Values
In your REST configuration file, you have to define which values of the returned JSON or XML will be mapped to which sensor channels.
- A sensor channel is defined by the channel key in your REST configuration. See section JSON Return Format: Minimum Example in the PRTG API documentation of your PRTG installation.
- A channel value is selected by its key in the JSON source.
Example
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&noraw=1&filter_basetype=probe
&columns=totalsens=textraw,upsens=textraw,downsens=textraw,partialdownsens=textraw,warnsens=textraw,
pausedsens=textraw,unusualsens=textraw,undefinedsens=textraw,downacksens=textraw
This REST query will return some JSON, for example:
{
"prtg-version": "17.3.33.2517",
"treesize": 1,
"state": "ok",
"sensorxref": [
{
"totalsens": 28,
"upsens": 18,
"downsens": 0,
"partialdownsens": 0,
"warnsens": 0,
"pausedsens": 9,
"unusualsens": 1,
"undefinedsens": 0,
"downacksens": 0
}
]
}
Your REST configuration has to translate this JSON for the sensor. It has to be available in JSON format in the \Custom Sensors\rest sub-directory of your PRTG probe system. See the PRTG API documentation of your PRTG installation for details about the JSON return format.
The following example returns two channels from the JSON resource that will be added to the sensor in PRTG, Total (total sensor count) and Alarms (sensors in error status), each selected by their keys in the returned JSON.
{
"Text": "state",
"prtg": {
"result": [
{
"channel": "Total" ,
"value": "sensorxref[0].totalsens"
},
{
"channel": "Alarms" ,
"value": "sensorxref[0].downsens"
}
]
}
}
The channel values will be the values of the corresponding properties of the REST result, "sensorxref[0].totalsens" (28) and "sensorxref[0].downsens" (0). The sensor message will be the current value of "state" (ok).
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.
|
There are several REST configuration files available in the \Custom Sensors\rest folder by default. They are ready to use. You can also analyze them to see how to write your own REST configuration.
XML Sources
If the REST source returns XML instead of JSON, the sensor will transform the XML result to JSON before replacing the value paths with source values. Because of this, you will 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 sub-folder of the PRTG probe system. Execute rest.exe with the address of the XML endpoint and the parameter passthrough. The rest executable will return the converted XML to JSON result that you can use to define the desired paths..
rest.exe <xml-endpoint-url> passthrough
Calculating Channel Values and Functions
You can also perform calculations with the values of the source JSON or XML. The sensor uses the golang govaluate package for the calculations. Please refer to the govaluate documentation for details. For calculations, your source JSON paths must be surrounded by curly brackets in mustache style. This deviates from the govaluate package docs.
The following calculations are available.
|
Modifiiers
|
|
Comparators
|
|
Logical Operators
|
|
Numeric Constants
|
- 64-bit floating point: 12345.678
|
String Constants
|
|
Date Constants
|
- Single quotes
- Using any permutation of RFC3339, ISO8601, Ruby date, or Unix date
- Date parsing is automatically tried with any string constant.
|
Boolean Constants
|
|
Parentheses
|
- Use parentheses to control the order of evaluation: ()
|
Arrays
|
- Anything separated by comma and surrounded by parentheses: (1, 2, 'foo')
|
Prefixes
|
|
Ternary Conditional
|
|
Null Coalescing
|
|
The following functions are available.
|
duration(start,end)
|
- Calculates the nanoseconds between start and end.
- Both parameters must be RFC3339 date time strings.
Example:
duration({devices[0].firmware.date}, '017-05-18T17:11:43.7049944Z')
|
now()
|
- Returns the current date time in RFC3339.
Example:
duration({devices[0].firmware.date}, now())
|
array(object-array-string-numbers-...)
|
- Converts arguments into an array.
Example:
array(1,2,3)
|
number(string, [base])
|
- Converts a string to a floating point number.
- If the base is not set, it will be detected via the prefix of the string.
- "0": base = 8
- "0X": base = 16
- otherwise: base = 10
- Decimals are only supported at base 10.
Examples:
number('10.5')
number('a', 16)
|
len(object-array-string)
|
- Returns the length of an array or string and counts the number of properties in a JSON object.
Example:
len(devices[0].networks)
|
sum(array-of-numbers)
|
- Returns the sum over an array of numbers.
|
count(array-of-numbers)
|
- Returns the count of none zero values in an array of numbers.
|
mean(array-of-numbers)
|
- Returns the average value of an array of numbers.
|
map({mysource.array-or-object}, property-name-strings-...)
|
- Iterates over a JSON object or an array of objects, collects the values of named properties, and returns an array with these numbers.
Example:
map({devices[0].networks}, 'rx_bytes', 'tx_bytes')
The example might return an array like this: [35985021, 7229493, 40085321, 55294975]
|
lookup({mysource.string}, string, string, ....)
|
- Returns the index of the given string in a string list, or -1 if the string is not found.
Example:
lookup({device[0].firmware.channel}, 'stable', 'beta', 'alpha' )
|
implode(array-of-string, string)
|
- Returns the concatenation of each string in the array, separated by the given string.
|
Combining Functions
|
- You can also combine several functions into one function.
Example: Calculating the sum of total bytes received and sent over all interfaces
sum(map({devices[0].networks}, 'rx_bytes', 'tx_bytes'))
|
Dynamic Channels
You can also define dynamic channels in your REST configuration. A dynamic channel denotes an array or object in the channel property. The sensor will iterate over all entries and append ancillary channels.
For example, imagine you want to have total byte channels for each network card that is defined in the returned JSON. You can do this by creating a dynamic channel.
{
"channel": "Total bytes in network {devices[0].networks}",
"value": "{rx_bytes} + {tx_bytes}"
}
You can also iterate over more than one array or object.
{
"channel": "Total bytes on device {devices} in network {networks}",
"value": "{rx_bytes} + {tx_bytes}"
}
Usage and Debugging
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 is located in the \Sensor System sub-folder of the PRTG program directory.
Command syntax:
rest.exe url config|passthrough|channelDiscovery [flags]
|
url
|
- Address of the REST API endpoint that returns JSON or XML
|
config
|
- Fully qualified path and file name of your REST configuration file in JSON format
|
passthrough
|
- No mapping, only returning the queried JSON or XML
- Useful to analyze XML that has been converted to JSON
|
channelDiscovery
|
- Creates a channel for every number or boolean in the returned JSON or XML
- If possible, it converts string values to number or boolean values.
|
|
authtoken <string>
|
- JWT or OAuth2 Bearer Token to send with the request in authorization header as Bearer
|
authusername <string>
|
- User name for basic authentication
|
authuserpwd <string>
|
- User password for basic authentication
|
post <string>
|
- {1|0}
- Default: 0
- 0 results in a GET request.
- 1 results in a POST request.
|
proxy <string>
|
|
proxyusername <string>
|
- Proxy user name with basic authentication
|
proxyuserpwd <string>
|
- Proxy user password with basic authentication
|
tlsignore <string>
|
- {1|0}
- Default: 0
- 1 will accept self-signed certificates on HTTPS connections
|
customheaders <string>
|
|
More
Golang govaluate package docs:
Edit Sensor Channels
To change display settings, spike filter, and limits, switch to the sensor's Overview tab and click the gear icon of a specific channel. For detailed information, please see the Sensor Channels Settings section.
Notifications
Click the Notifications tab to change notification triggers. For detailed information, please see the Sensor Notifications Settings section.
Others
For more general information about settings, please see the Object Settings section.
Sensor Settings Overview
For information about sensor settings, please see the following sections: