[ZBX-16975] Zabbix quoted contextual user macro containing the context of a Zabbix LLD macro function when using quoted regsub not allowed in trigger function parameter Created: 2019 Nov 22  Updated: 2024 Apr 10  Resolved: 2020 Feb 17

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Frontend (F)
Affects Version/s: 4.0.13
Fix Version/s: 5.0 (plan)

Type: Documentation task Priority: Trivial
Reporter: James Cook Assignee: Vladislavs Sokurenko
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Zabbix 4.0.7
PostgreSQL 11


Attachments: XML File ZBX-16975 Template - SNMP IF-MIB SNMPv2.xml    
Team: Team A
Sprint: Sprint 58 (Nov 2019), Sprint 59 (Dec 2019), Sprint 60 (Jan 2020), Sprint 61 (Feb 2020)

 Description   

I use contextual macros in trigger expressions all the time which provides flexibility.

The issue I am finding is when using a contextual user macro with a context including LLD macro + quoted regsub inside an expression it fails syntactically.

This occurs when using double quotes for the contextual macro and also to surround the regular expression in the macro function example:

{$USERMACRO:"{

{#LLDMACRO}.regsub("^(.*)$",\1)}"}

The documentation states for contextual macros we should use a double quote and the same with the macro functions.

The issue here is the fact we are doing this both at the same time and the strings are not being interpreted correctly example:

String1 = {{#LLDMACRO}

.regsub(

Between = ^(.*)$

String2 = ,\1)}

If we were able to use single quotes as well we would be able to work around it example:

{$USERMACRO:"{

{#LLDMACRO}.regsub('^(.*)$',\1)}"}

OR

{$USERMACRO:'{{#LLDMACRO}

.regsub("^(.*)$",\1)}'}

 



 Comments   
Comment by James Cook [ 2019 Nov 22 ]

Hi,

One additional detail is when using this in the Description field in a item or trigger prototype the actual user macro value is not expanded i.e. 

{$USERMACRO:"Some Discovered Thing With Regular Expression Applied"}

Its as if the macro functions need to be applied first then macro substitution

Cheers

James

Comment by Vladislavs Sokurenko [ 2019 Nov 22 ]

Does it work if escaped ?

^(.*)$\",\1

Alternative

^(.*)$\x22,\1
Comment by James Cook [ 2019 Nov 22 ]

Hi Vladislavs,

Interesting suggestion with the Hex as I tried escaping and single quotes for the off chance before I raised this issue...

I tried both and the resulted in the following in the description:

Escaping: {$CISCO_ENVMON_MIB_PSU_STATUS_SAMPLES:"{{#CISCOENVMONSUPPLYSTATUSDESCR}.regsub(\"^([^,]).$\",\1)}"}

Result: {$CISCO_ENVMON_MIB_PSU_STATUS_SAMPLES:"Switch 1 - Power Supply A"}

Expected: #3 as this is what CISCO_ENVMON_MIB_PSU_STATUS_SAMPLES is set to as a macro

Hex Char: {$CISCO_ENVMON_MIB_PSU_STATUS_SAMPLES:"{{#CISCOENVMONSUPPLYSTATUSDESCR}.regsub(\x22^([^,]).$\x22,\1)}"}

Result: {$CISCO_ENVMON_MIB_PSU_STATUS_SAMPLES:"

{Switch 1 - Power Supply A, Normal.regsub(\x22^([^,]*).*$\x22,\1)}

"}

Expected: #3 as this is what CISCO_ENVMON_MIB_PSU_STATUS_SAMPLES is set to as a macro

If I try using any of the above as a function argument in a trigger like last(<Insert above here>) then I get a syntax error.

I think there is two issues here:

  1. The LLD macro function are not being evaluated before the User macro is evaluated
  2. The syntax of using quotes within quotes is breaking the trigger format checking

Cheers

James

Comment by Vladislavs Sokurenko [ 2019 Nov 22 ]

I am sorry but I got a little bit confused.
Here is my example
trigger name:

{$MACRO:"{{#M}.regsub(".*",\0)}"}

value of

{#M}

a

Result:

{$MACRO:"a"}

For expression:

{Zabbix server:trap1["{#M}"].last()}={$MACRO:"{{#M}.regsub(\".*\",\0)}"}

Result:

{Zabbix server:trap1["a"].last()}={$MACRO:"a"}
Comment by James Cook [ 2019 Nov 25 ]

Hi Vladislavs,

I have attached a sample template.

If you assign this to anything that responds to IF-MIB snmp queries it should work.

If you try to update the existing trigger contained in this template you will see it does not work due to a syntax error which I believe is caused by the multiple double quotes.

Cheers

James

Comment by James Cook [ 2019 Nov 25 ]

Note: look i discovered items for further elaboration

Comment by Vladislavs Sokurenko [ 2019 Nov 25 ]

Please try this:

{Windows host:trap1["{#M}"].count("{$MACRO:\"{{#M}.regsub(\\".*\\",\0)}\"}")}=0

Result:

{Windows host:trap1["a"].count("{$MACRO:\"a\"}")}=0
Comment by James Cook [ 2019 Nov 26 ]

Hi Vladislavs,

Great. I have tried and tested your method and it works.

Would it be ok to ask if the documentation may have some notes in regards to escaping in specific scenarios such as:

When using as a expression function parameter: "{$IF_MIB_INT_STATUS_SAMPLES:\"{{#IFNAME}.regsub(\\"(.*)\\",\1)}\"}"

When using as a normal expression value: {$IF_MIB_INT_STATUS_SAMPLES:"{{#IFNAME}.regsub(\"(.*)\",\1)}"}

This may help other people understand potentially? This may be closed.

Cheers

James

Comment by Vladislavs Sokurenko [ 2019 Nov 28 ]

(1) [D] Context macros should be added to macro functions examples

vso RESOLVED, updated pages:
https://www.zabbix.com/documentation/4.0/manual/config/macros/macro_functions
https://www.zabbix.com/documentation/4.4/manual/config/macros/macro_functions
https://www.zabbix.com/documentation/5.0/manual/config/macros/macro_functions

martins-v Thanks, CLOSED

Generated at Mon Jun 30 09:13:16 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.