[ZBXNEXT-3262] Enhance Zabbix regexp functions to return regexp compilation error message Created: 2016 Apr 29  Updated: 2018 Nov 01

Status: Open
Project: ZABBIX FEATURE REQUESTS
Component/s: Agent (G), Proxy (P), Server (S)
Affects Version/s: 3.2.0alpha1
Fix Version/s: None

Type: Change Request Priority: Trivial
Reporter: Andris Mednis Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: errorreporting, regexps
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Recently Zabbix regexp functions have been improved to return ZBX_REGEXP_MATCH, ZBX_REGEXP_NO_MATCH or FAIL.
Let's add a regexp compilation error message returned in case of FAIL (see make_logfile_list() for a working example). This will make users life easier.



 Comments   
Comment by Andris Zeila [ 2016 May 05 ]

Recently the regular expression processing was extended to include better error handling. However it was done by two separate issues touching two paths of regular expression processing (ZBXNEXT-1638, ZBXNEXT-1250) and as result has a different approach:

static char	*zbx_regexp(const char *string, const char *pattern, int *len, int flags)
and
static int	regexp_sub(const char *string, const char *pattern, const char *output_template, int flags, char **out)

zbx_regexp() returns pointer to matched string or NULL if the string doesn't match or the pattern was invalid. If NULL is returned, then len contains either SUCCEED (pattern was valid) or FAIL (otherwise).

regexp_sub() returns FAIL if pattern is invalid and SUCCEED otherwise. If SUCSEED is returned then out contains either substituted output string or NULL if there is no match.

In reality the zbx_regexp() len parameter is used only to return error code, so we can simply use similar signature to regexp_sub() function:

static int	zbx_regexp(const char *string, const char *pattern, int flags, char **output)
Comment by Andris Zeila [ 2016 May 05 ]

Also complex return codes usually aren't used in Zabbix. It might be better to return simply SUCCEED/FAIL based on regular expression compilation success (with optional error message output parameter) and use additional output parameter to return match/not match.

Comment by Glebs Ivanovskis (Inactive) [ 2016 May 05 ]

Functions zbx_regexp() and regexp_sub() (especially with changes proposed by wiper) will be virtually identical. I think it is a good idea to merge them into one.

However, there are difficulties with higher level functions. Suggested solution (SUCCEED/FAIL + NULL/matched string) won't be particularly convenient in regexp_match_ex() where we are not interested in matched string but only in match/not match.

Comment by Andris Mednis [ 2018 Nov 01 ]

Maybe this feature request can be reviewed now - after regexp support has been moved to libpcre.
regexp_compile() reports in error message why the regexp does not compile but throws away position number where the error was detected.
regexp_compile() can be improved to report position, e.g.

\ at end of pattern at position 11

in case

/home/zabbix40/ZBX-15090/test.log.*\

was given as the first parameter to logrt[].
However this requires adding deallocation of error messages in callers (currently regexp_compile() returns pointer to error message in static memory).

Generated at Tue Apr 23 16:43:49 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.