PRTG Manual: Python Script Advanced Sensor

The Python Script Advanced sensor executes a Python script on the probe system. This option is available as part of the PRTG API.

i_round_redThe return value of this sensor must be valid JavaScript Object Notation (JSON) or Extensible Markup Language (XML).

Python Script Advanced Sensor

Python Script Advanced Sensor

i_square_cyanFor a detailed list and descriptions of the channels that this sensor can show, see section Channel List.

Sensor in Other Languages

  • Dutch: Python Script Geavanceerd
  • French: Script Python avancé
  • German: Python-Skript (Erweitert)
  • Japanese: Python スクリプト(上級)
  • Portuguese: Script Python (avançado)
  • Russian: Скрипт Python (дополнительно)
  • Simplified Chinese: Python 脚本高级
  • Spanish: Script Python (avanzado)

Remarks

Consider the following remarks and requirements for this sensor:

Remark

Description

File storage

This sensor requires that you store the script file on the probe system. In a cluster, copy the file to every cluster node.

Windows Server

We recommend Windows Server 2016 on the probe system for best performance of this sensor.

Channels

This sensor does not officially support more than 50 channels.

This sensor does not support channel values greater than 2^62.

Print commands

This sensor does not support print commands in the Python script. They lead to an invalid JSON result.

Exceptions

This sensor does not support exceptions in the Python script.

Python environment

PRTG uses its own Python environment. This is located in the \python subfolder of the PRTG program directory. To avoid issues, we recommend that you do not have other Python environments running on a probe system. We also recommend that you do not uninstall the paesslerag_prtg_sensor_api package.

Timeout

The timeout of the sensor is its scanning interval minus 1 second. Make sure that your Python script does not run longer than this.

Sensor usage

For best sensor usage, we recommend that the return value is JSON encoded.

Performance impact

This sensor has a medium performance impact.

Knowledge Base

Hosted probe

i_podYou cannot add this sensor to the hosted probe of a PRTG Hosted Monitor instance. If you want to use this sensor, add it to a remote probe device.

Basic Sensor Settings

Basic Sensor Settings

Basic Sensor Settings

The sensor has the following default tags that are automatically predefined in the sensor's settings when you add the sensor:

  • json
  • python
  • pythonxml
  • script
  • xml

i_square_cyanFor more information about basic sensor settings, see section Sensor Settings.

Credentials for Script Sensors

Click b_inherited_enabled to interrupt the inheritance.

Credentials for Script Sensors

Credentials for Script Sensors

Setting

Description

Placeholder 1 Description

Enter a description for Placeholder 1, for example information about the purpose or content of the placeholder.

Placeholder 1

Enter a value for the placeholder. PRTG inserts the value for the script execution if you add %scriptplaceholder1 in the argument list. PRTG does not display the value in the sensor log or the sensor's settings.

Placeholder 2 Description

Enter a description for Placeholder 2, for example information about the purpose or content of the placeholder.

Placeholder 2

Enter a value for the placeholder. PRTG inserts the value for the script execution if you add %scriptplaceholder2 in the argument list. PRTG does not display the value in the sensor log or the sensor's settings.

Placeholder 3 Description

Enter a description for Placeholder 3, for example information about the purpose or content of the placeholder.

Placeholder 3

Enter a value for the placeholder. PRTG inserts the value for the script execution if you add %scriptplaceholder3 in the argument list. PRTG does not display the value in the sensor log or the sensor's settings.

Placeholder 4 Description

Enter a description for Placeholder 4, for example information about the purpose or content of the placeholder.

Placeholder 4

Enter a value for the placeholder. PRTG inserts the value for the script execution if you add %scriptplaceholder4 in the argument list. PRTG does not display the value in the sensor log or the sensor's settings.

Placeholder 5 Description

Enter a description for Placeholder 5, for example information about the purpose or content of the placeholder.

Placeholder 5

Enter a value for the placeholder. PRTG inserts the value for the script execution if you add %scriptplaceholder5 in the argument list. PRTG does not display the value in the sensor log or the sensor's settings.

Sensor Settings

Sensor Settings

Sensor Settings

Setting

Description

Script

Select a Python script from the list. The sensor executes it with every scanning interval.

This list shows all Python script files that are available in the \Custom Sensors\python subfolder of the PRTG program directory on the probe system. For the files to appear in this list, store the files in this subfolder with the extension .py.

i_round_redTo show the expected values and sensor status, your files must return the expected XML or JSON format to standard output. The values and message must be embedded in the XML or JSON. We recommend JSON-encoded return values.

i_square_cyanFor more information on how to create custom sensors and for the return format, see section Custom Sensors.

i_round_redIf you use custom sensors on the cluster probe, copy your files to every cluster node.

i_round_blueYou cannot change this value after sensor creation.

Security Context

Define the Windows user account that the sensor uses to run the Python interpreter:

  • Use security context of PRTG probe service (default): Run the Python script file under the same Windows user account that the probe system runs under. By default, this is the Windows system user account.
  • Use Windows credentials from parent device: Use the Windows user account from the settings of the parent device.

Device Credentials

PRTG adds the device credentials to the JSON object that is passed to the script as a command-line parameter. Define if you want to transmit device credentials to the Python script:

  • Do not transmit device credentials: Transmit no device credentials to the script.
  • Transmit Windows credentials: Transmit Windows credentials to the script.
  • Transmit Linux credentials: Transmit Linux credentials to the script.
  • Transmit SNMP credentials: Transmit SNMP credentials to the script.
  • Transmit all device credentials: Transmit Windows, Linux, and Simple Network Management Protocol (SNMP) credentials to the script.

i_round_blueThe sensor transmits all parameters in plain text.

Additional Parameters

Define additional parameters to add to the JSON object that is passed to the script as a command-line parameter. Enter a string or leave the field empty.

i_round_blueThe sensor passes a custom JSON object within a dictionary to the script. The dictionary contains the key params that contains all additional parameters in one string.

Use the following command to load the dictionary that the sensor sends to the script:

data = json.loads(sys.argv[1])

Use the following command to load the additional parameters:

params = json.loads(data["params"])

i_round_blueIf the string contains more than one parameter, you can use the Split() function in Python to split the string.

i_round_blueThe sensor transmits all parameters in plain text.

Mutex Name

Define a mutual exclusion (mutex) name for the process. Enter a string or leave the field empty.

i_round_bluePRTG executes all Python Script Advanced sensors that have the same mutex serially, not simultaneously. This is useful if you use a lot of sensors and want to avoid high resource usage because of simultaneously running processes.

i_square_cyanSee the Knowledge Base: What is the Mutex Name in the EXE/Script sensor settings?

Debug Options

Debug Options

Debug Options

Setting

Description

Result Handling

Define what PRTG does with the sensor result:

  • Discard result (default): Do not store the sensor result.
  • Store result: Store the sensor result and the last response in the \Logs\sensors subfolder of the PRTG data directory on the probe system. The file names are Result of Sensor [ID].Data.txt and Result of Sensor [ID].log. This setting is for debugging purposes. PRTG overwrites these files with each scanning interval.

i_round_blueYou can use Store result to inspect the passed JSON object that contains all parameters. This way, you can find out which key you can access when you script.

i_podThis option is not available in PRTG Hosted Monitor.

i_round_bluePRTG masks transmitted passwords in the log file.

i_round_blueIn a cluster, PRTG stores the result in the PRTG data directory of the master node.

Sensor Display

Sensor Display

Sensor Display

Setting

Description

Primary Channel

Select a channel from the list to define it as the primary channel. In the device tree, PRTG displays the last value of the primary channel below the sensor's name. The available options depend on what channels are available for this sensor.

i_round_blueYou can set a different primary channel later by clicking b_channel_primary below a channel gauge on the sensor's Overview tab.

Graph Type

Define how this sensor shows different channels:

  • Show channels independently (default): Show a 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 generates a graph that visualizes the different components of your total traffic.
    i_round_redYou cannot use this option in combination with manual Vertical Axis Scaling (available in the channel settings).

Stack Unit

This setting is only visible if you select Stack channels on top of each other above.

Select a unit from the list. PRTG stacks all channels with this unit 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 of these settings are inherited from objects that are higher in the hierarchy. We recommend that you change them centrally in the root group settings if necessary. To change a setting for this object only, click b_inherited_enabled under the corresponding setting name to disable the inheritance and to display its options.

i_square_cyanFor more information, see section Inheritance of Settings.

Channel List

i_round_blueWhich channels the sensor actually shows might depend on the target device, the available components, and the sensor setup.

Channel

Description

Downtime

In the channel table on the Overview tab, this channel never shows any values. PRTG uses this channel in graphs and reports to show the amount of time in which the sensor was in the Down status.

[Value]

The values that the Python script returns in several channels

i_square_cyanFor more information about the return value format, see section Custom Sensors.

More

i_square_blueKNOWLEDGE BASE

What is the Mutex Name in the EXE/Script sensor settings?

Why do I have to store SQL sensor queries and custom scripts in files on the probe computer?

After updating to PRTG 20.1.55, my Python Script Advanced sensors are down

What security features does PRTG include?