Zabbix template variables
Template variables let you create dynamic, reusable dashboards that switch between host groups, hosts, applications, and items without editing the dashboard. You can populate variable drop-downs with values from Zabbix and reference those variables in queries, panel titles, and text panels.
Before you begin
Supported variable types
Create a query variable
To create a variable that fetches values from Zabbix:
- Open a dashboard and click Dashboard settings (gear icon).
- Click Variables in the left menu.
- Click Add variable.
- Set Variable type to Query.
- Select the Zabbix data source.
- Select a Query Type and fill in the filter fields.
- Click Apply.
Query types
The variable query editor uses a structured form with a Query Type drop-down. Select the type of Zabbix entity you want to populate the variable with.
All filter fields support regex patterns (for example, /.*/ to match all values) and references to other template variables (for example, $group).
For the Item and Item values query types, the editor shows either Application (Zabbix < 5.4) or Item Tag (Zabbix 5.4+) depending on your Zabbix server version. Only one field is visible at a time.
When the Item query type is selected, you can also toggle Show disabled items to include disabled items in the results.
Legacy query format
Older dashboards may use a legacy string-based query format. The Zabbix variable editor displays these as a read-only Legacy Query field and automatically converts them to the structured format.
The legacy format uses four parts wrapped in braces:
{host group}{host}{application}{item name}Each part can be a specific name or * (all values). The number of parts determines what the variable returns:
Use variables in queries
Reference variables in the query editor by prefixing the variable name with $. For example, if you have a variable named host, use $host in the Host field of a Metrics query.
Variables work in most query editor fields, including:
- Group, Host, Application / Item tag, Item
- Service, SLA
- Proxy, Problem, Item Ids, Macros
- Panel and row titles
- Text panel content
Note
When using multi-value variables, the plugin automatically formats the selected values as a regex pattern for Zabbix API queries. For example, selecting
web01andweb02is sent to Zabbix as(web01|web02).
Built-in macros
In addition to the template variables you define, the plugin automatically populates a set of read-only macros for each series returned by a Metrics query. Use them in alias functions (setAlias, setAliasByRegex, replaceAlias) to build readable series names. You don’t create these macros; the plugin sets them per item.
For example, to rename each series to <visible host name> - <item name>, add the following function to a Metrics query:
setAlias($__zbx_host_name - $__zbx_item)Note
$__zbx_hostreturns the host’s technical name, while$__zbx_host_namereturns the visible name. These often differ. Use$__zbx_host_namewhen you want the human-readable name shown in the Zabbix frontend.
Chain variables
You can reference one variable inside another variable’s query to create cascading drop-downs. For example:
- Create a variable named
groupwith Query Type set to Group. - Create a variable named
hostwith Query Type set to Host and set the Group field to$group. - Create a variable named
itemwith Query Type set to Item, set Group to$group, and Host to$host.
When you change the group selection, the host variable automatically updates to show only hosts in that group, and the item variable updates accordingly.
Examples
Build a host picker for a dashboard
Let viewers switch the dashboard between hosts without editing panels.
- Create a variable named
hostwith Query Type set to Host and Group set to the group you want (or/.*/for all hosts). - In each Metrics query, set the Host field to
$host.
Filter a query with a multi-value variable
Show several hosts on one panel from a single drop-down.
- Create the
hostvariable as in the previous example and enable Multi-value. - Set the Host field of your query to
$host.
When you select web01 and web02, the plugin sends (web01|web02) to Zabbix, so the query returns data for both hosts.
Repeat a panel for each selected host
Render one copy of a panel per selected host.
- Create a multi-value
hostvariable. - In the panel’s Repeat options, set Repeat by variable to
host. - Set the query’s Host field to
$host.
Grafana renders a separate panel for each host you select.
Populate a drop-down with current item values
Use the Item values query type to build a variable from the latest values of an item, which is useful for text panels or annotations.
- Create a variable with Query Type set to Item values.
- Set Group, Host, and Item to target the item you want.


