[ZBXNEXT-3444] Simplify item key referencing in aggregated item keys and calculated item formulas Created: 2016 Sep 19  Updated: 2021 Nov 16  Resolved: 2021 Nov 16

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: Server (S)
Affects Version/s: 3.4.0alpha1
Fix Version/s: None

Type: Change Request Priority: Minor
Reporter: Glebs Ivanovskis (Inactive) Assignee: Unassigned
Resolution: Fixed Votes: 5
Labels: aggregate, calculateditems, syntax, usability
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by ZBXNEXT-6374 Unified syntax for trigger expression... Closed
is duplicated by ZBX-15195 Calculated item fails when item key c... Closed

 Description   

Suppose we need to count log messages containing "," on hosts of group ",", then count log messages containing "]" on hosts of group "]", and finally calculate the ratio of these two numbers.

On host group "," we have:

  • agent item: log.count[/path/to/file,","]
  • aggregated item: grpsum[",","log.count[/path/to/file,\",\"]",last]

On host group "]" we have:

  • agent item: log.count[/path/to/file,"]"]
  • aggregated item: grpsum["]","log.count[/path/to/file,\"]\"]",last]

And we also need a calculated item:

last("grpsum[\",\",\"log.count[/path/to/file,\\",\\"]\",last]") /
last("grpsum[\"]\",\"log.count[/path/to/file,\\"]\\"]\",last]")

Note how quickly expressions get populated with double quotes and backslashes. That's because Zabbix treats any comma as parameter delimiter. To pass a parameter containing "," or "]" one needs to quote whole parameter. And then escape all double quotes with backslashes inside this parameter. Manually...

I think we can do better. There is a precedent when Zabbix processes parameters wisely. For example, no quoting and escaping needed to pass an array of host groups to aggregated item:

grpavg[["Servers A","Servers B","Servers C"],system.cpu.load,last]

This saves 8 characters in quotes and backslashes compared to this syntax:

grpavg["[\"Servers A\",\"Servers B\",\"Servers C\"]",system.cpu.load,last]

I think, Zabbix can be clever enough to treat unquoted item keys as a single parameter:

item.key[parameter_1,valid.item.key[valid,"item",params],parameter_3]
         ^         ^ ^                                 ^ ^         ^
         |         | |                                 | |         |
         '----1----' '----------------2----------------' '----3----'

If one wants Zabbix to treat this as 5 parameters one can always put some quoting and escaping (but I assume this situation is less frequent):

item.key[parameter_1,"valid.item.key[valid","\"item\"","params]",parameter_3]

With such new feature my example would look like so.

On host group "," we have:

  • agent item: log.count[/path/to/file,","]
  • aggregated item: grpsum[",",log.count[/path/to/file,","],last]

On host group "]" we have:

  • agent item: log.count[/path/to/file,"]"]
  • aggregated item: grpsum["]",log.count[/path/to/file,"]"],last]

And we also need a calculated item:

last(grpsum[",",log.count[/path/to/file,","],last]) /
last(grpsum["]",log.count[/path/to/file,"]"],last])

Note that I simply copy-pasted item keys and we saved 24 characters in redundant quotes and backslashes in calculated item formula.

P.S. Same approach is applicable to context-based user macros with undesirable characters in the context used in item key and trigger function parameters. Currently one needs to write them like dummy.echo["{$MACRO:\",}\"}"]. Simplified dummy.echo[{$MACRO:",}"}] notation would save 4 characters. To force parameter separation one would need to add two extra characters dummy.echo["{$MACRO:\",}\"}"]. Assuming the former meaning is at least twice as frequent as the latter we will be using less characters with new syntax.



 Comments   
Comment by Glebs Ivanovskis [ 2020 Feb 16 ]

P.P.S. Another example with macro function was inspired by ZBX-17317:

dummy.echo["{{#MACRO}.regsub(\"\\"(.*)\\"\",\1)}"]

vs.

dummy.echo[{{#MACRO}.regsub("\"(.*)\"",\1)}]

The difference is 6 characters.

Comment by Alexei Vladishev [ 2021 Nov 16 ]

cyclone  I believe the next syntax of trigger expressions and calculated items introduced in Zabbix 5.4 fully covers proposed functionality. Please confirm and close this ticket if needed.

Comment by Glebs Ivanovskis [ 2021 Nov 16 ]

alexei, issue is reported by glebs.ivanovskis (note the Inactive), not me. At least it is a different account, so I have no control over this ticket. Please take care of closing it if deemed necessary.

Comment by Alexei Vladishev [ 2021 Nov 16 ]

Thanks, I am closing it then. Feel free to re-open if needed.

Generated at Wed Apr 17 00:35:55 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.