Macros are variables that can resolve to a specific value depending on the context and location inside Zabbix. Effective use of macros allows to save time and make Zabbix configuration more transparent.

For example, one macro value can be reused in an unlimited number of triggers. Thus, when you have to make a change to all monitored hosts, for instance, increasing processor usage limit before a trigger fires, all you have to do is alter the macro instead of editing each template separately adding extended control and great flexibility.

A way to customize macro values by applying simple functions was added in Zabbix 3.2. Currently the support macros are {ITEM.VALUE}, {ITEM.LASTVALUE} and functions to extract a part of the macro value by using regular expressions (see documentation).

Let’s say we want to receive a notification whenever a Windows service has been stopped with custom alert messages containing service names. First we setup an item using eventlog key:

Then we add a trigger based on it:

With ‘PROBLEM event generation mode’ set to Multiple a new event will be generated whenever a service has been stopped. As we are interested only in notifications we can set ‘OK event generation’ to None so that trigger always stays in problem state.

Until now it was nothing new – we simply created a trigger to generate event whenever Windows service changes it’s state. But now we can use function macros to extract the service name from item value to use it in the notification subject or message:

This gives us nice compact notification messages like:

  • The SQL Server service has been stopped
  • The Software Protection service has been stopped
If we sparked your interest and you wish to learn more about macros, we encourage you to view a complete list of macros supported by Zabbix, and read the whole Zabbix 3.2 documentation.

While it might not seem a big improvement, the real power of macro functions comes when used in trigger tags. More about it you will find in our upcoming blog post focusing on Zabbix triggers.

Subscribe
Notify of
4 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
theserverguy
7 years ago

Seems like an interesting feature!

hernandss
hernandss
7 years ago

Nice post !!

sarzaminedanesh
7 years ago

I loved the post esp Zabbix 3.2 documentation seems to be well executed.

Sakshi
5 years ago

Zabbix is actually working on good features with every new release 🙂

4
0
Would love your thoughts, please comment.x
()
x