[ZBX-20579] No macro expansion in Template > Discovery rule > Item Prototype Created: 2022 Feb 15  Updated: 2022 Feb 17  Resolved: 2022 Feb 17

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Frontend (F), Server (S)
Affects Version/s: 5.4.10
Fix Version/s: None

Type: Problem report Priority: Trivial
Reporter: Tobias Großmann Assignee: Aleksandrs Petrovs-Gavrilovs
Resolution: Commercial support required Votes: 0
Labels: discovery, item, macros, prototype, rule
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File image-2022-02-15-08-14-35-213.png     PNG File image-2022-02-17-18-05-04-916.png    

 Description   

Hi there,

I want to create a discovery rule and items based on a JSON file. The file looks like this:

 

[
   {
      "service":"app1",
      "status":"running"
   },
   {
      "service":"app2",
      "status":"running"
   },
   {
      "service":"app3",
      "status":"running"
   }
]

 

Based on that I and to create an item for each service which returns the status.

I made those steps:

  1. Created item in template to get the JSON data
  2. Created discovery rule
    • Type: "Dependent item" from the item in 1.
    • No preprocessing
    • LLD macros:
      • {{ {#SERVICENAME}

        > $[*].["service"]}}

      • {{ {#STATUS}

        }}> ${{[*].["status"]}}

    • No Filters
  3. Created Item prototype
    • Name: [Discovery] Status {#SERVICENAME}
    • Type : "Dependent item" from the item in 1.
    • Key: something{#SERVICENAME}
    • Preprocessing: JSONPath:
      • $..[?(@.service == '\{#SERVICE}')].status

Now after this is done, I would expect to get something like

  • [Discovery] Status app1
    • Key: something[app1]
    • Result: ["running"]
  • [Discovery] Status app2
    • Key: something[app2]
    • Result: ["running"]
  • [Discovery] Status app3
    • Key: something[app3]
    • Result: ["running"]

 

But it doesn't work because the item prototype isn't expanding the macros. This is what I get as error in the Discovery rules tab in the host:

So why is it not expanding my macros?

 

I was already searching for that problem and I already find related problems with "Zabbix trapper" items - but it does not apply here



 Comments   
Comment by Tobias Großmann [ 2022 Feb 15 ]

Somehow it changed my source code in the description...

Here is the correct code:

LDD Macros:

{#SERVICENAME} > $[*].["service"]
{#STATUS}      > $[*].["status"]

Key:

something[{#SERVICENAME}] 

But the problem is still there!

Comment by Aleksandrs Petrovs-Gavrilovs [ 2022 Feb 17 ]

Hello,

Could you please try to use this path in LLD macros:

$.service
$.status 


And see if that works for you?

Otherwise i don't see a bug here, please let me know if I am missing something.

Best Regards,
Aleksandrs

Comment by Tobias Großmann [ 2022 Feb 17 ]

Ohhh, now it adds the Macros and expands them. That JSONPath is weird...

Now with this error...

Preprocessing failed for: [{"service":"app1","status":"running"},{"service":"app2","status":"running"},{"service":...
1. Failed: cannot extract value from json by path "$..[?(@.service == '{#SERVICE}')].status": no data matches the specified path 

... I realized that I wrote "SERVICE" instead of "SERVICENAME" in the JSONPath. Now it works like charm! Thank you for your help!!!

PS: I found no way to check if the LLD macros are extraced correctly. Do you know how I can do it? And in generall if those macros can be applied in the item prototypes?

Comment by Aleksandrs Petrovs-Gavrilovs [ 2022 Feb 17 ]

Glad it helped, overall most JSON path evaluators should work, if it's a custom JSON, I would recommend to take a look in the documentation:
https://www.zabbix.com/documentation/current/en/manual/discovery/low_level_discovery#custom-macros

But I'm afraid this issue is out of context for this tracker. Please be advised that this section of the tracker is for bug reports only. The case you have submitted can not be qualified as one, so please reach out to [email protected] for commercial support (https://zabbix.com/support) or consultancy services. Alternatively, you can also use our IRC channel or community forum (https://www.zabbix.com/forum) for assistance. With that said, we are closing this ticket. Thank you for understanding. 

Generated at Tue Jul 22 08:38:49 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.