User macros are supported in Zabbix for greater flexibility, in addition to the macros supported out-of-the-box.
User macros can be defined on global, template and host level. These macros have a special syntax:
Zabbix resolves macros according to the following precedence:
In other words, if a macro does not exist for a host, Zabbix will try to find it in the host templates of increasing depth. If still not found, a global macro will be used, if exists.
If a macro with the same name exists on multiple linked templates of the same level, the macro from the template with the lowest ID will be used. Thus having macros with the same name in multiple templates is a configuration risk.
If Zabbix is unable to find a macro, the macro will not be resolved.
Macros (including user macros) are left unresolved in the Configuration section (for example, in the trigger list) by design to make complex configuration more transparent.
User macros can be used in:
It is advisable to use host macros instead of global macros because adding, updating or deleting global macros forces incremental configuration update for all hosts. For more information, see Passive and active agent checks.
To define user macros, go to the corresponding location in the frontend:
A user macro has the following attributes:
Parameter | Description |
---|---|
Macro | Macro name. The name must be wrapped in curly brackets and start with a dollar sign. Example: {$FRONTEND_URL}. The following characters are allowed in the macro names: A-Z (uppercase only) , 0-9 , _ , . |
Value | Macro value. Three value types are supported: Text (default) - plain-text value Secret text - the value is masked with asterisks Vault secret - the value contains a path/query to a vault secret. To change the value type click on the button at the end of the value input field. Maximum length of a user macro value is 2048 characters. |
Description | Text field used to provide more information about this macro. |
When configuring user macros, note the following context-specific behaviors:
Use of host-level macro in the "Status of SSH daemon" item key:
net.tcp.service[ssh,,{$SSH_PORT}]
This item can be assigned to multiple hosts, providing that the value of {$SSH_PORT} is defined on those hosts.
Use of host-level macro in the "CPU load is too high" trigger:
last(/ca_001/system.cpu.load[,avg1])>{$MAX_CPULOAD}
Such a trigger would be created on the template, not edited in individual hosts.
If you want to use the amount of values as the function parameter (for example, max(/host/key,#3)), include hash mark in the macro definition like this: SOME_PERIOD => #3
Use of two macros in the "CPU load is too high" trigger:
min(/ca_001/system.cpu.load[,avg1],{$CPULOAD_PERIOD})>{$MAX_CPULOAD}
Note that a macro can be used as a parameter of trigger function, in this example function min().
Synchronize the agent unavailability condition with the item update interval:
nodata(/ca_001/agent.ping,{$INTERVAL})=1
Centralize configuration of working hours:
1-5,09:00-18:00
;Use host prototype macro to configure items for discovered hosts: