[ZBX-11211] Server tries to find functions in macro context when creating LLD calculated items from prototypes Created: 2016 Sep 15  Updated: 2017 May 30  Resolved: 2016 Nov 10

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S)
Affects Version/s: 3.0.5rc1, 3.2.1rc1, 3.4.0alpha1
Fix Version/s: None

Type: Incident report Priority: Minor
Reporter: Glebs Ivanovskis (Inactive) Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: calculateditems, lld, macrocontext
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

ZBX-10797 fixed calculated item formula parsing and evaluation, but creation of LLD calculated items from prototypes is still not aware of context macros and tries to find functions (lowercase letters followed by parentheses with some content) inside macro context.

Look how weird it is:

Prototype formula Item formula Comments
{$MACRO:"{#LLD_MACRO}"}
{$MACRO:"value"}
That's fine, {#LLD_MACRO} got replaced with value
{$MACRO:"a({#LLD_MACRO})"}
{$MACRO:"a({#LLD_MACRO})"}
Zabbix thinks a(...) is a function and expects host:key reference in the first parameter, where LLD macros are not substituted
{$MACRO:"a(,{#LLD_MACRO})"}
{$MACRO:"a(,value)"}
Still, Zabbix thinks a(...) is a function but now resolves LLD macro in its second parameter
{$MACRO:"a(,{#LLD_MACRO})"}
{$MACRO:"a(,"   <-leading and trailing whitespace->   ")"}
Here Zabbix even put double quotes around fake function parameter


 Comments   
Comment by Raymond Kuiper [ 2016 Sep 15 ]

Sounds related to ZBX-10797

Comment by Sergejs Paskevics [ 2016 Sep 20 ]

Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-11211

Comment by Glebs Ivanovskis (Inactive) [ 2016 Sep 21 ]

(1) zbx_user_macro_parse() is tricky, it skips first two characters, so before you call it you must assure that they are '{' and '$'. You can use calcitem_parse_expression() for inspiration.

s.paskevics This case successfully tested in ZBX-11223.
CLOSED

Comment by Glebs Ivanovskis (Inactive) [ 2016 Sep 21 ]

(2) Speaking of calculate_parse_expression() and substitute_formula_macros()... They basically do the same job of parsing calculated item formula searching for functions and their parameters. For some reason they use different functions for that, parse_function() and zbx_function_parse() respectively. And where is code duplication, there are bugs too.

Calculated item prototype:

  • Key: and.or.not[{#M}]
  • Formula: not({#M})and({#M} or {#M})or({#M} and {#M})

Expected discovered calculated item:

  • Key: and.or.not[123]
  • Formula: not(123)and(123 or 123)or(123 and 123)

Actual discovered calculated item:

  • Key: and.or.not[123]
  • Formula: not({#M})and({#M} or {#M})or({#M} and {#M})

Let's put everything in one piece of code.

s.paskevics These cases successfully tested in ZBX-11223.
CLOSED

Comment by Glebs Ivanovskis (Inactive) [ 2016 Sep 21 ]

(3) I guess wiper will agree that for 3.2 and trunk we need a separate fix using zbx_token_find().

s.paskevics Sources has been changed it is overdue
WON'T FIX

Comment by Glebs Ivanovskis (Inactive) [ 2016 Nov 09 ]

I think this problem was completely solved by ZBX-11223 merge (r63620). We should verify this and close the issue if it's the case.

Comment by Sergejs Paskevics [ 2016 Nov 10 ]

Closed by duplicate of ZBX-11223.

Generated at Sat Apr 20 04:52:36 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.