[ZBX-26339] User macro conflict resolved differently on Frontend vs Server Created: 2025 Apr 22  Updated: 2025 May 21

Status: Ready for QA
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S)
Affects Version/s: 7.0.11, 7.0.12rc1
Fix Version/s: 7.0.14rc1, 7.2.8rc1, 7.4.0rc1 (master)

Type: Problem report Priority: Minor
Reporter: user185953 Assignee: Natalja Romancaka
Resolution: Unresolved Votes: 0
Labels: consistency
Remaining Estimate: Not Specified
Time Spent: 12h 50m
Original Estimate: Not Specified
Environment:

Debian 12, Firefox


Attachments: File macro_conflict_templates First.yaml     File macro_conflict_templates Second.yaml    
Issue Links:
Causes
caused by ZBXNEXT-7553 Create user macro resolver to reduce ... Closed
Team: Team C
Sprint: S25-W20/21
Story Points: 4

 Description   

Steps to reproduce:

  1. Template A has macro {$MY} = "YES"
  2. Template A used {$MY} in LLD filter
  3. Template B has macro {$MY} = "NO"
  4. Both templates linked to host

Result:
Host's "Inherited and host macros" shows value of {$MY} is "NO",
but when LLD rule runs, it works as if value of {$MY} was "YES".

Expected:
Value displayed in Frontend consistent with value used by Server.
Bonus points: Add warning indicator that conflict exists and that this is bad idea.



 Comments   
Comment by user185953 [ 2025 Apr 22 ]

Related to macro conflict resolution: ZBXNEXT-1674 and https://www.zabbix.com/documentation/current/en/manual/config/macros/user_macros for those who look for workarounds.

Comment by Alexander Vladishev [ 2025 Apr 22 ]

What do you mean by "but when LLD rule runs"? Are you referring to the macro being resolved differently in items or triggers created from prototypes?

The procedure for resolving user macros and how such conflicts are handled is described here.

Comment by user185953 [ 2025 Apr 23 ]

I simplifyed too much, sorry.

First template has UUID 2... and macro {$VAL.IGNORE.REGEX} = ^never-ignore$,
+ a LLD rule with a filter like this: {#VAL} does not match {$VAL.IGNORE.REGEX}.
Second template has UUID f... and macro {$VAL.IGNORE.REGEX} = ^2$.
Both templates linked to one host.

When LLD rule runs, it works like described in documentation. First template wins and nothing is filtered.
But in Host > Macros > Inherited and host macros it works differently: It says macro resolves to ^2$.

Maybe it is not worth fixing but caused "My macro is ^2$ so why are these items still discovered?".

Comment by user185953 [ 2025 Apr 23 ]

Looks like maybe order of template import matters in Frontend?

  • When I import Second and then First, I get ^2$.
  • When I delete Second and import and link again I get ^never-ignore$.
  • When I delete First and import and link again I am back to ^2$.
Comment by Alexander Vladishev [ 2025 Apr 23 ]

Yes, the order definitely matters — identical macros are sorted by the template ID (hostmacro.hostid). Here’s an excerpt from our documentation:

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.

The server and frontend should behave the same way. I’ll try to reproduce the issue to confirm.

Comment by user185953 [ 2025 Apr 23 ]

Is that AI-generated? First you agree that link order matters but then continue that conflicts are solved by template ID, not link order.

I hope the attached templates will help with reproducing.

Comment by Alexander Vladishev [ 2025 Apr 23 ]

I meant that the import order matters, not the linking order. If a template is imported first, it will have a lower ID, and therefore its macro will take precedence.

Thank you for the templates — they’ll help reproduce the issue.

Comment by user185953 [ 2025 Apr 23 ]

Oh, I assumed that "template ID" means template UUID that will be carried by export. I see my mistake.

I don't know if attached templates will work here. Let me test the LLD part more thoroughly on my end.

Comment by user185953 [ 2025 Apr 23 ]

Can you please try this:

  • Import Second template first
  • Import First template second
  • Create host "A" and link to both templates - Inherited and host macros should say ^2$ because it was imported first.
  • Create host "B" and link only the "First" template - Inherited and host macros should say ^never-ignore$ because there is no conflict
  • Let Discovery run
  • Host "A" should discover less items than host "B" because of filter
  • Link "Second" template to host "B" - Now inherited and host macros should say ^2$ just like on host "A"
  • Re-run discovery on "B"
  • * Expected: Extra items on "B" become "not discovered anymore"
  • * Actual: Nothing, all items still discovered.
  • Delete all discovered items
  • Re-run discovery on both hosts
  • * Expected: Same number of items discovered on both
  • * Acutal: Host "B" still discovers more items
Comment by user185953 [ 2025 Apr 23 ]

Simpler test:

  • Imported First template first
  • Imported Second template second
  • Created host "C", linked only to "First"
  • Created host "D", linked only to "Second"
  • Link remaining template to both hosts
  • Run discovery on both hosts
  • * Expected: Hosts discover same number of items
  • * Actual: Host "C" discovered more items than host "D"
Comment by Alexander Vladishev [ 2025 Apr 23 ]

Thank you for your input! I can confirm the issue — the server resolves user macros without taking their priority by "hostid" into account.

Generated at Thu May 22 07:07:32 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.