[ZBX-25143] User macros on calculated items are not accepted in host parameter Created: 2024 Aug 31  Updated: 2024 Nov 09  Resolved: 2024 Sep 01

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S), Templates (T)
Affects Version/s: 6.0.33
Fix Version/s: None

Type: Incident report Priority: Trivial
Reporter: LivreAcesso.Pro Assignee: Zabbix Development Team
Resolution: Won't fix Votes: 0
Labels: calculateditems, lastvalue, macro, templates, usermacro
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Add item to template with user macros.png     PNG File Captura de tela de 2024-08-31 17-28-42.png    

 Description   

Steps to reproduce:

  1. Create a new calculated item
  2. Try to last() function to get another host key value with a user macro as a host parameter.

Result:
See screenshot...
Try the get the value without a user macro as a host parameter works as expected, but not with the user macro:

Works: 

last(/myHost/oltPonTxOpticalPower.[472907776])

Don't work: 

last(/{$MYHOST}/oltPonTxOpticalPower.[472907776])

Expected:
Get the value of the key with a user macro as a host parameter.



 Comments   
Comment by LivreAcesso.Pro [ 2024 Aug 31 ]

I manage to get the value through an API call:

{
  "jsonrpc": "2.0",
  "method": "item.get",
  "params": {
    "host": "{$MYHOST}",
    "search": {
      "key_": "oltPonTxOpticalPower.[{$MYHOSTPWID}]"
    }
  },
  "auth": "{$API_TOKEN}", "id":{$MYHOSTPWID}
}

But the HTTP Agent call is overloading my server.

Comment by Alexander Vladishev [ 2024 Sep 01 ]

Zabbix does not support custom macros in this context. This is also reflected in the documentation.

User macros in the formula will be expanded if used to reference a function parameter, item filter parameter, or a constant. User macros will NOT be expanded if referencing a function, host name, item key, item key parameter or operator.

Comment by LivreAcesso.Pro [ 2024 Sep 02 ]

Thanks. Can I use any other function, or aggregate function, to select only one host?

Comment by Alexander Vladishev [ 2024 Sep 02 ]

In this case, you can use the macro {HOST.HOST} or omit the host name. Both of these approaches will work the same way:

last(/{HOST.HOST}/oltPonTxOpticalPower.[472907776])
last(//oltPonTxOpticalPower.[472907776])
Comment by LivreAcesso.Pro [ 2024 Sep 02 ]

Thanks.
In this case, {HOST.HOST} don't work from me. I want to get the value from a key from another host. It is a parent host, in the case.
I can manage to get this value through API, via a HTTP Agent item.

 

{
  "jsonrpc": "2.0",
  "method": "item.get",
  "params":
{     "host": "{$MYHOST}",
    "search":
{       "key_": "oltPonTxOpticalPower.[{$MYHOSTPWID}]" 
   }
  },
  "auth": "{$API_TOKEN}", "id":{$MYHOSTPWID}
}

The parent host is defined by {$MYHOST} macro. I  have a host tag defined as {$MYHOST} too.

Comment by Alexander Vladishev [ 2024 Sep 03 ]

In this case, you need to explicitly specify the hostname. There are no other options.

You can also vote for this functionality in ticket ZBXNEXT-8616.

Comment by LivreAcesso.Pro [ 2024 Oct 01 ]

Can I use a LLD to concatenate the item?

Comment by Alexander Vladishev [ 2024 Oct 01 ]

No, LLD macros cannot be used to concatenate the item key in a calculated item formula. However, in item prototypes, at least one such macro is required in the item key parameter. Here is an example of a formula that contains references to item prototypes:

(last(//vfs.dev.read.time.rate[{#DEVNAME}])/(last(//vfs.dev.read.rate[{#DEVNAME}])+(last(//vfs.dev.read.rate[{#DEVNAME}])=0)))*1000*(last(//vfs.dev.read.rate[{#DEVNAME}]) > 0) 
Comment by LivreAcesso.Pro [ 2024 Nov 09 ]
Details Cannot update item prototype

    Invalid parameter "/1/params": incorrect expression starting from "last(/{#OLT}/oltPonTxOpticalPower.[0])".
Generated at Mon Jun 30 08:45:47 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.