Skip to content

Zabbix UserParameter

Zabbix UserParameter is a configuration mechanism that extends the monitoring capabilities of the Zabbix agent by allowing users to define custom monitoring keys and execute arbitrary shell commands or scripts to retrieve data^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

Configuration

The directive is defined within the Zabbix agent configuration file (e.g., zabbix_agentd.conf or zabbix_agentd.win.conf)^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

Syntax

The basic format for a UserParameter is: UserParameter=<key>,<shell command>^[600-developer-operation-maintenance-zabbix-zabbix-key.md]

It is also possible to pass arguments to the command using the following syntax: UserParameter=<key[*]>,<shell command>^[600-developer-operation-maintenance-zabbix-zabbix-key.md] When [*] is used in the key, arguments passed from the server (e.g., key[argument]) can be accessed in the shell command using variables like $1, $2, etc^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

To ensure complex scripts or commands execute correctly, the following options are often adjusted in the configuration file alongside UserParameter^[600-developer-operation-maintenance-zabbix-zabbix-key.md]:

  • EnableRemoteCommands: Allows remote commands from the Zabbix server^[600-developer-operation-maintenance-zabbix-zabbix-key.md].
  • UnsafeUserParameters: Allows all characters to be passed in arguments (excluding specific restricted characters like \ ' " * ? [ ] { } ~ $ ! & ; ( ) < > | # @` and newlines)^[600-developer-operation-maintenance-zabbix-zabbix-key.md].
  • Timeout: Defines the maximum execution time for the script; if the script exceeds this time, Zabbix returns a timeout error^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

Usage Example: Monitoring JVMs with PowerShell

A common use case for UserParameter on Windows is monitoring specific Java processes by invoking PowerShell scripts^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

1. Script Execution Policy

Before running PowerShell scripts via the Zabbix agent, the system's execution policy must allow it. This typically requires setting the policy to RemoteSigned using administrator privileges^[600-developer-operation-maintenance-zabbix-zabbix-key.md].

2. Configuration Entry

The following configuration example defines a key mypay.robot that accepts an argument (the robot name), passes it to a PowerShell script, and sets a timeout^[600-developer-operation-maintenance-zabbix-zabbix-key.md]:

Timeout=30
EnableRemoteCommands=1
UnsafeUserParameters=1
UserParameter=mypay.robot[*],C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -File C:\Zabbix\robot.ps1 $1 $2 $3 $4 $5 $6 $7 $8 $9

3. Testing with zabbix_get

After configuring the agent and restarting the service, the parameter can be verified from the Zabbix server using the zabbix_get utility^[600-developer-operation-maintenance-zabbix-zabbix-key.md]:

/usr/bin/zabbix_get -s <target_ip> -p 10050 -k "mypay.robot[robot1047]"

Sources

^[600-developer-operation-maintenance-zabbix-zabbix-key.md]