[ZBXNEXT-4627] Support of regsub() for LLD macros Created: 2018 Jul 05  Updated: 2024 Apr 10  Resolved: 2018 Aug 24

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: Server (S)
Affects Version/s: None
Fix Version/s: 4.0.0beta1, 4.0 (plan)

Type: Change Request Priority: Trivial
Reporter: Rostislav Palivoda Assignee: Viktors Tjarve
Resolution: Fixed Votes: 3
Labels: None
Σ Remaining Estimate: Not Specified Remaining Estimate: Not Specified
Σ Time Spent: Not Specified Time Spent: Not Specified
Σ Original Estimate: Not Specified Original Estimate: Not Specified

Attachments: PNG File Selection_563.png     XML File zbx_export_hosts(1).xml    
Issue Links:
Duplicate
is duplicated by ZBXNEXT-3556 Support macro functions when using LL... Closed
is duplicated by ZBXNEXT-3757 Add macro function to LLD macroses Closed
Sub-Tasks:
Key
Summary
Type
Status
Assignee
ZBXNEXT-4656 Frontend Support of regsub() for LLD ... Change Request (Sub-task) Closed Ivo Kurzemnieks  
Team: Team A
Team: Team A
Sprint: Sprint 37, Sprint 38, Sprint 39, Sprint 40, Sprint 41
Story Points: 3

 Description   

Zabbix must support regsub() and iregsub() functions for LLD macros. It will allow to extract certain parts of LLD macro using regular expression. The functions will be supported in all locations allowed for LLD macros.

A typical use case

A LLD macro contains customer name and network interface number:

{#IFALIAS}=customername_1

I want to extract and use customer name and interface number in trigger tags "Customer" and "IF", therefore I take advantage of the function regsub():

Customer: {{#IFALIAS}.regsub("(.*)_([0-9]+)", \1)}
IF: {{#IFALIAS}.regsub("(.*)_([0-9]+)", \2)}


 Comments   
Comment by Glebs Ivanovskis [ 2018 Jul 09 ]

This issue duplicates ZBXNEXT-3757 and ZBXNEXT-3556.

Also example in the description looks very very strange... syntax-wise.

And what's the point of iregsub() when Zabbix supports PCRE, where this can be controlled using (?i) inline modifier?

vso thanks, updated. iregsub() removal is out of scope of this task, it might be simpler to use.

Comment by Glebs Ivanovskis [ 2018 Jul 12 ]

There are no capture groups in the first regular expression and only one in the second while \1 and \2 are used in output.

 <viktors.tjarve> You where right. Fixed the example in the description now.

Comment by Viktors Tjarve [ 2018 Aug 10 ]

Released in:

  • 4.0.0alpha10 r83723
Comment by Alexander Vladishev [ 2018 Aug 21 ]

(22) [D] Documentation needs to be updated

martins-v Documentation updates:

RESOLVED

vso I think it's better to also include picture from https://www.zabbix.com/documentation/4.0/manual/config/macros/lld_macros#using_macro_functions in what's new, not just a text

For example, you may want to extract the customer name and interface number from the following LLD macro for the purposes of event tagging:

{#IFALIAS}=customername_1

To do so, the regsub macro function can be used with the macro in the event tag value field of a trigger prototype: 

...

martins-v RESOLVED

vso CLOSED

Comment by Vladislavs Sokurenko [ 2018 Aug 22 ]

(23) [D] Macro functions do not mention enough about possible usage with LLD

For example:

<macro> - the macro to customize (for example {ITEM.VALUE})

Could be changed to:

<macro> - the macro to customize (for example {ITEM.VALUE} or {#MACRO})

This:

 For example:

{{ITEM.VALUE}.regsub(pattern, output)}

To as it is in https://www.zabbix.com/documentation/4.0/manual/config/triggers/event_tags

{{ITEM.VALUE}.regsub(pattern, output)}
{{#LLDMACRO}.regsub(pattern, output)}

martins-v RESOLVED

vso looks good but probably better to replace

{#IFALIAS}=customername_1 	{{#IFALIAS}.regsub("(.*)_([0-9]+)", \1)} 	customername
{#IFALIAS}=customername_1 	{{#IFALIAS}.regsub("(.*)_([0-9]+)", \2)} 	1

to

customername_1 	{{#IFALIAS}.regsub("(.*)_([0-9]+)", \1)} 	customername
customername_1 	{{#IFALIAS}.regsub("(.*)_([0-9]+)", \2)} 	1
customername_1 	{{#IFALIAS}.regsub("(.*)_([0-9]+", \1)} 	{{#IFALIAS}.regsub("(.*)_([0-9]+", \1)} (invalid regular expression) 

martins-v RESOLVED

vso CLOSED

Comment by Vladislavs Sokurenko [ 2018 Aug 22 ]

(24) [D] No mention about LLD macro functions in https://www.zabbix.com/documentation/4.0/manual/appendix/macros/supported_by_location

For example

{ITEM.VALUE<1-9>} 

Says "Customizing the macro value is supported for this macro, starting with Zabbix 3.2.0."

martins-v RESOLVED

vso CLOSED

Comment by Vladislavs Sokurenko [ 2018 Aug 22 ]

(25) [D] No mention about LLD macro functions in https://www.zabbix.com/documentation/4.0/manual/config/triggers/trigger

Says only macro functions: {{ITEM.VALUE}.regsub(pattern, output)}, {{ITEM.VALUE}.iregsub(pattern, output)} are supported in event tags. Low-level discovery macros can be used inside macro context.

User macros, user macro context, low-level discovery macros and macro functions: {{ITEM.VALUE}.regsub(pattern, output)}, {{ITEM.VALUE}.iregsub(pattern, output)} are supported in event tags. Low-level discovery macros can be used inside macro context.

martins-v RESOLVED

vso CLOSED

Comment by Vladislavs Sokurenko [ 2018 Aug 22 ]

(26) [D] Behavior is different for LLD when using macro functions

This should be removed

If pattern is not a correct regular expression 'UNKNOWN' is returned. 

This should be changed

 If a function is used in a supported location, but applied to a macro not supporting macro functions, then the macro evaluates to 'UNKNOWN'.

If a macro function is applied to the macro in locations not supporting macro functions then the function is ignored. 

To:

If a function is used in a supported location excluding LLD, but applied to a macro not supporting macro functions, then the macro evaluates to 'UNKNOWN'.
If pattern is not a correct regular expression then the macro evaluates to 'UNKNOWN', (excluding LLD macros where function will be ignored in that case and macro will remain not expanded)
If a macro function is applied to the macro in locations not supporting macro functions then the function is ignored. 

martins-v RESOLVED

vso sorry one correction since all low level discovery macros support macro functions

If a function is used in a supported location (excluding low-level discovery), but applied to a macro not supporting macro functions, then the macro evaluates to 'UNKNOWN'.

martins-v RESOLVED

vso CLOSED

Generated at Sat Apr 20 03:28:39 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.