[ZBXNEXT-5927] Using built-in macros in JavaScript and regular expression preprocessing Created: 2020 Apr 30  Updated: 2024 Jun 25

Status: Reopened
Project: ZABBIX FEATURE REQUESTS
Component/s: Server (S)
Affects Version/s: 4.4.8
Fix Version/s: None

Type: New Feature Request Priority: Trivial
Reporter: Stefano Enrico Mendola Assignee: Zabbix Support Team
Resolution: Unresolved Votes: 39
Labels: javascript, macro, preprocessing, regularexpression
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by ZBXNEXT-5815 Get macro value from JS code of webhook Closed

 Description   

Hi,
Could you please make the built-in macros available for use in preprocessing steps ?

For example, it would be nice to use {HOST.HOST} in regular expression preprocessing,
but it would be nice if I could use it also in JavaScript preprocessing calling
a method of a class ZabbixMacro like the following:

var hostname = ZabbixMacro.get("{HOST.HOST}");

One use case where I encountered this limitation is the following:
I'd like to use Javascript preprocessing to do some GET requests to an API.
This API has the same domain name as the hostname configured on Zabbix,
so I'd like to be able to do a CurlHttpRequest.Get() to it using the value
of the {HOST.HOST} macro.
I'm aware that this macro can be used in the URL field of the HTTP Agent check Item, but going through this path will force me to create a ton of other items in order to achieve my goal, it would be definitely cleaner to throw everything inside a Javascript preprocessing step.



 Comments   
Comment by Stefano Enrico Mendola [ 2020 Apr 30 ]

At the moment, the workaround I'm using is:

>adding a User Macro to the host template
>change the value to the final host
>prepending the user macro value to the item value using a regexp preprocessing step
>passing the regexp output to the JavaScript function

Comment by dimir [ 2020 Sep 18 ]

Re-opening as it appeared to not be duplicate. This issue is specifically about built-in macros.

Comment by dimir [ 2020 Sep 18 ]

Usermacros support was added in ZBXNEXT-5185.

Comment by dimir [ 2020 Sep 18 ]

FYI, there is no term "supported macros". On this page https://www.zabbix.com/documentation/current/manual/appendix/macros/supported_by_location the supported means "what we support out-of-the box". Sometimes we call them "built-in".

Comment by Stefano Enrico Mendola [ 2020 Sep 18 ]

Hi @dimir, thanks for the clarification and for re-opening this issue.

Wouldn't it be nice to let the community know about this nomenclature?
Maybe changing the title of the "Supported macros" manual page to "Built-in supported macros" ?

Should I open a separated documentation issue for this?

Cheers

Comment by dimir [ 2020 Sep 18 ]

martins-v what do you think?

Comment by Dimitri Bellini [ 2020 Oct 27 ]

News about this feature on Zabbix v.5.2?

Thanks

Comment by Matthew Steeves [ 2021 Feb 24 ]

Just want to throw our use-case into the mix as well:

I would really like to be able to know the hostname from within a low-level discovery rule. Being able to use it within a Javascript pre-processing step in an LLD rule would give me the ability to assign it to an LLD Macro, and then reference that macro in Filters and Overrides. This would allow me to write one template that acts differently depending on whether the host is a production host or a dev host.

Example:   
Goal:   

  • Monitor disk space on all servers, but only notify on low space if host is a production server (not Dev or DR)

Steps:

  • LLD rule has a Javascript pre-processing step that adds HOST.NAME as an additional LLD macro called #HOSTNAME to each discovery record.
  • Trigger Prototype has a Tag called Team with the empty string as default value.
  • LLD rule defines an override that compares #HOSTNAME against regex. If matches, then Team tag value is populated with "SysAdmin".
  • Trigger action is used to notify when the above Trigger produces a problem, but only if value of tag Team = "SysAdmin". This is done by simply using a Trigger Action condition.

(Outside the scope of this request, but best case scenario (easiest) would be if I could use HOST.NAME directly on the "left-side" of a Filter or Override condition within a LLD rule, instead of first having to assign the "built-in" macro to an LLD macro, and then reference the LLD macro.)

Comment by Nick [ 2022 Mar 28 ]

I have the same issue when using lld for host prototypes, want to use built-in macros (like: {HOST.CONN}) in JavaScript preprocessing.

Another way, is it possible to set a user macro value with built-in macro? For example, {$XXX_CFG_HOST}: {HOST.CONN}, but that doesn't work either.

Comment by David [ 2024 Jan 09 ]

I have run into this limitation trying to use {HOST.NAME} macro within a JSONPath call in preprocessing.

+1 Vote for this.

Comment by Denis Dion [ 2024 Apr 25 ]

I too have run into this problem and had to use the workaround of using a user macro. I do not understand why user macros work but the built-in not.

+1 at least vote for this.

Comment by Ushakov.Stanislav [ 2024 Jun 25 ]

This feature is really important. Right now, I have to use all kinds of scripts for the API to attach a custom macro to a node with the network node name. Then, I need to pass that macro for JavaScript preprocessing in LLD. If built-in macros were supported directly in preprocessing, it would make things so much easier.

Generated at Wed May 14 09:06:05 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.