5 User parameters
Overview
You may write a command that retrieves the data you need and include it in the user parameter in the (‘UserParameter’ configuration parameter).
A user parameter has the following syntax:
As you can see, a user parameter also contains a key. The key will be necessary when configuring an item. Enter a key of your choice that will be easy to reference (it must be unique within a host).
Restart the agent or use the agent runtime control option to pick up the new parameter, e. g.:
Then, when , enter the key to reference the command from the user parameter you want executed.
User parameters are commands executed by Zabbix agent. Up to 512KB of data can be returned before item preprocessing steps. Note, however, that the text value that can be eventually stored in database is limited to 64KB on MySQL (see info on other databases in the table).
/bin/sh is used as a command line interpreter under UNIX operating systems. User parameters obey the agent check timeout; if timeout is reached the forked user parameter process is terminated.
- on making use of user parameters
- Command execution
Examples of simple user parameters
A simple command:
UserParameter=ping,echo 1
The agent will always return ‘1’ for an item with ‘ping’ key.
A more complex example:
The agent will return ‘1’, if MySQL server is alive, ‘0’ - otherwise.
Flexible user parameters
Flexible user parameters accept parameters with the key. This way a flexible user parameter can be the basis for creating several items.
Flexible user parameters have the following syntax:
Positional references with the $ sign are searched for and replaced by Zabbix agent only for flexible user parameters. For simple user parameters, such reference processing is skipped and, therefore, any $ sign quoting is not necessary.
Example 1
Something very simple:
UserParameter=ping[*],echo $1
We may define unlimited number of items for monitoring all having format ping[something].
- ping[0] - will always return ‘0’
- ping[aaa] - will always return ‘aaa’
Example 2
Let’s add more sense!
This parameter can be used for monitoring availability of MySQL database. We can pass user name and password:
Example 3
How many lines matching a regular expression in a file?
UserParameter=wc[*],grep -c "$2" $1
This parameter can be used to calculate number of lines in a file.
Command result
The return value of the command is standard output together with standard error.
User parameters that return text (character, log, text type of information) can return whitespace. In case of invalid result the item will become unsupported.