New macros supported in Zabbix network maps

Zabbix 4.2 comes with the long awaited support of multiple macros for map element labels and URLs. In this blog post we will discuss what new features Zabbix provides and how to use them to make Zabbix network maps more awesome. For starters though, let me remind you what is a macro in Zabbix and how it’s typically used.

What are macros in Zabbix

As described in the documentation, macros are variables which are replaced by value depending on context in which they are used. Sounds great! You can use macros and Zabbix replaces those variables by values it calculated or you have specified somewhere else. If you already knew this, call yourself a Zabbix macros ninja 😉

So what does Zabbix 4.2 bring us?

Numerous macros are already supported in map element labels and URLs for a while. In order to make them even more useful, we decided to add support of macros for host inventory attributes. We also added various macros in places they were not supported previously.

Host inventory macros

If you’re dealing with thousands of hosts, keeping a track of them all can be challenging at times. That’s why hosts in Zabbix have various attributes you can define in host inventory tab, including, for example, admin’s contact information for emergencies.

Host’s Primary POC inventory fields

Once you’ve made sure your host has primary POC name and email address fields filled in host inventory tab, you may define the following URL in your network map properties:

Name: Send email to POC ({INVENTORY.POC.PRIMARY.NAME})
URL: mailto:{INVENTORY.POC.PRIMARY.EMAIL}?subject={HOST.NAME}
Element: Host

Save changes and check your network map. The host element’s context menu now has the newly defined URL containing a contact person’s name in the label of URL and properly formatted link to send a message to email. Next time you see a problem in your Zabbix network map, getting in touch with the right person will be much easier.

Custom URL in network map element context menu
Custom URL in network map element context menu

Having a shortcut to email is great, and you can use any communication channel, just remember that Zabbix validates URLs and it might be necessary to whitelist new schema to comma separated list defined in “ZBX_URI_VALID_SCHEMES”.

Before we move further, it’s worth mentioning that using macros in map element URL, you will still have to pass the validation of URL since macros are primarily expected to be used as attributes. The exception is inventory URL macro {INVENTORY.URL.<A-C>} which is assumed to be valid URL.

Possibilities to customize maps using inventory macros are virtually unlimited. You can customize the labels of host and trigger map elements, including such attributes as name and version of OS, applications and websites hosted on a particular machine etc. Check out the full list of inventory macros supported in map element labels and URLs in Zabbix documentation.

Other macros supported in maps

While we were reworking support of macros in map element labels and URLs, we also made multiple macros available in places they were previously not supported. Macros like {HOST.NAME}, {HOST.ID} and all interface related macros (e.g. {HOST.IP} and {HOST.CONN}) are now available in both map element labels and URLs. This allows us to pass host’s IP address or domain name to external services like whois or various online domain tools. Support of macros {MAP.ID}, {MAP.NAME} and {HOSTGROUP.ID} is also extended in the same fashion. Use them to automatically populate various Zabbix filters or share your discoveries with coworkers through the URLs. See the full list of macros supported in network maps in the Zabbix documentation.

Use Zabbix host macros to create custom URLs to external services

Conclusion

Zabbix 4.2 comes with great customization improvements for map element labels and URLs. What’s even better – performance of maps was greatly improved so dealing with thousands of hosts included directly or through sub-maps will be a breeze.

Author: Miks

Developer at Zabbix

Leave a Reply