Zabbix Documentation 4.2

3.04.04.4 (current)| In development:5.0 (devel)| Unsupported:1.82.02.22.43.23.44.2Guidelines

User Tools

Site Tools


manual:config:items:userparameters

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

manual:config:items:userparameters [2014/04/11 13:35]
127.0.0.1 external edit
manual:config:items:userparameters [2018/01/25 13:02]
Line 1: Line 1:
-==== - #4 User parameters ==== 
- 
-=== Overview === 
- 
-Sometimes you may want to run an agent check that does not come predefined with Zabbix. This is where user parameters come to help. 
- 
-You may write a command that retrieves the data you need and include it in the user parameter in the [[:​2.4/​manual/​appendix/​config/​zabbix_agentd|agent configuration file]] ('​UserParameter'​ configuration parameter). 
- 
-A user parameter has the following syntax: 
- 
-  UserParameter=<​key>,<​command>​ 
- 
-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. 
- 
-Then, when [[:​2.4/​manual/​config/​items/​item|configuring an item]], 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. **/bin/sh** is used as a command line interpreter under UNIX operating systems. This way you can enhance the functionality of Zabbix agents. 
- 
-See a [[:​2.4/​manual/​config/​items/​userparameters/​extending_agent|step-by-step tutorial]] on making use of user parameters. 
- 
-== 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: 
- 
-  UserParameter=mysql.ping,​mysqladmin -uroot ping|grep -c alive 
- 
-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: 
- 
-  UserParameter=key[*],​command 
- 
-^Parameter^Description^ 
-|**Key**|Unique item key. The [*] defines that this key accepts parameters within the brackets.| 
-|**Command**|Command to be executed to evaluate value of the key.\\ Zabbix parses the content of [] and substitutes $1,...,$9 in the command accordingly.\\ $0 will be substituted by the original command (prior to expansion of $0,...,$9) to be run.| 
- 
-<note tip>To use positional references unaltered, specify double dollar sign - for example, awk '​{print $$2}'​.</​note>​ 
- 
-<note important>​Unless [[:​2.4/​manual/​processes/​zabbix_agentd|UnsafeUserParameters]] agent daemon configuration option is enabled, it is not allowed to pass flexible parameters containing these symbols: \ ' " ` * ? [ ] { } ~ $ ! & ; ( ) < > | # @  </​note>​ 
- 
-<​note>​User parameters that return text (character, log, text types of information) now can return whitespace only as well, setting the return value to an empty string (supported since 2.0). If non-valid value is returned, ZBX_NOTSUPPORTED will be sent back by the agent.</​note>​ 
- 
-== 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! 
- 
-  UserParameter=mysql.ping[*],​mysqladmin -u$1 -p$2 ping | grep -c alive 
- 
-This parameter can be used for monitoring availability of MySQL database. We can pass user name and password: 
- 
-  mysql.ping[zabbix,​our_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. 
- 
-  wc[/​etc/​passwd,​root] 
-  wc[/​etc/​services,​zabbix]