[ZBX-16438] Zabbix LLD rule produces non-expanding application prototypes, when particular macro not present in JSON data set Created: 2019 Jul 31  Updated: 2020 Jun 15  Resolved: 2020 Jun 15

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

Type: Problem report Priority: Trivial
Reporter: Vadims Kurmis Assignee: Kristians Pavars
Resolution: Won't fix Votes: 0
Labels: LLD, application, discovery, macro, prototype
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Steps to reproduce:

  1. Suppose we want to discover item with variable amount of application prototypes
  2. So our JSON data can be as follows:
  3. {data:[{"{#HOST}":"aaa.contoso.com","{#GROUP_1}":"Linux Servers"},{"{#HOST}":"bbb.contoso.com","{#GROUP_1}":"Linux Servers","{#GROUP_2}":"Zabbix Servers"}]}

    So each JSON data set can have multiple different GROUP macros.

  4. Then we create item prototype. Set "Host{#HOST}" for item name and add application prototypes: {#GROUP_1}, {#GROUP_2}, .... {#GROUP_5}
  5. When discovery rule fires, it generates item prototype: Host["aaa.contoso.com"] and in applications field macros are exapanded to:
  6. Linux Servers
  7. {#GROUP_1}
  8. {#GROUP_2}
  9. {#GROUP_3}
  10. {#GROUP_4}
  11. {#GROUP_5}

And for item prototype: Host["bbb.contoso.com"] in applications field macros are expanded to:

  1. Linux Servers
  2. Zabbix Servers
  3. {#GROUP_2}
  4. {#GROUP_3}
  5. {#GROUP_4}
  6. {#GROUP_5}

Non-present macros for application prototypes should not be just placed there, because it's a macro. So the expected behavior is that Zabbix should not generate wrong and incorrect applications for missing macros.

I know, this helps troubleshooting, so that it will be visible to zabbix administrator, that some macro did not expand and something might be missing, but this would be better made another way.

The requirement is to make discovery with variable application prototype amount. 

If I specify only one application prototype, for example like "{#GROUP}" and then send discovery JSON in two parts, then application prototype just gets overwritten.

Also, there is no "filter" option for Item Prototype, which would help in this case as I could simply create 5 items, where 1st item looks for {#GROUP_1} macro non-empty, 2nd looks for {#GROUP_1} and {#GROUP_2} macros non empty and last 5-th item would check if JSON data set has all 5 group macros present.

 

 

Result:
See screenshot...
See log file...
See memory dump...
Expected:
See screenshot....
See attached patch file...



 Comments   
Comment by Vadims Kurmis [ 2019 Jul 31 ]

I was able to implement above logic by creating 2 discovery rules "host.discovery.1" and "host.discovery.2".

Then I send the same JSON to both LLD rules.

LLD rule "host.discovery.1" filters by "{#GROUP_1}" match ".+"

LLD rule "host.discovery.2" filters by "{#GROUP_1}" match .+ and "{#GROUP_2}" match .+

This workaround works.

However, it would be more nice if Zabbix would not generate non-expanding application names, then the same could be achieved by using single LLD rule.

 

Comment by Glebs Ivanovskis [ 2019 Aug 01 ]

What should Zabbix do if application prototype name is "{#GROUP_1} {#GROUP_2}" and there is only {#GROUP_1} value in the data, but no {#GROUP_2} value? Should Zabbix create a half of application?

Comment by Vadims Kurmis [ 2019 Aug 01 ]

For app prototype - "{#GROUP_1} {#GROUP_2}" where macro "{#GROUP_2}" missing - discover as "{#GROUP_1}".
For app prototype - "{#GROUP_1} {#GROUP_2}" where both macros "{#GROUP_1}" and "{#GROUP_2}" are missing - also don't discover app prototype..
If "macro must persist" - strict requirement enabled, something like this, then I would expect error message in LLD rule.

I think it would be better than having erroneous app prototypes generated, without even warning, that macro expansion failed - no error message for LLD rule.

Comment by Glebs Ivanovskis [ 2019 Aug 01 ]

Hm, maybe we need more granular LLD filters? Potentially for every single item/trigger/application/graph prototype.

Comment by Vadims Kurmis [ 2019 Aug 01 ]

That JSON thing is very different for many cases.
Yes, and macro filters for item prototypes, not only in discovery rule. That would save enormous amount of time to administrators, who use Zabbix.
But this is more like future improvements.
I just wanted to discuss, that creating erroneous app prototypes with artifacts like "{#GROUP_2}" or "Server - {#GROUP2}" is not an expected behavior and should produce error in LLD rule. So that zabbix admin will notice, something went wrong, what if there are hundreds of items discovered? Then would be hard to notice that something went wrong, but LLD rule succeeded.

What about expanding missing macro to empty string? Other macros work like this. And from this it could be made that "app prototype", which name is missing macro, expands to empty string and hence - it won't be discovered in this case

Comment by Vadims Kurmis [ 2019 Aug 01 ]

Windows and Linux consoles expand missing macro to empty string

Comment by Vadims Kurmis [ 2019 Oct 24 ]

Any progress on this? Is this considered for next Zabbix releases?

This is a common behavior for most scripting languages that non-existing macros expand to empty string.

I can mention at least: bash, batch, vbscript, powershell - work like this.

 

Comment by Kristians Pavars [ 2020 Jun 12 ]

Hi Vadims,

 

Sorry for the long delay on this ticket. This looks more like a feature request and not a bug with Zabbix, have you raised a feature request for it?

 

Thanks,
Kristiāns

Generated at Thu Mar 28 15:19:41 EET 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.