[ZBX-12500] Item preprocessing: Output condition is not applied if value does not match expression pattern Created: 2017 Aug 10  Updated: 2018 Oct 09  Resolved: 2017 Sep 07

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Server (S)
Affects Version/s: 3.4.0rc1
Fix Version/s: 3.4.2rc1, 4.0.0alpha1, 4.0 (plan)

Type: Problem report Priority: Trivial
Reporter: Anna Kucenko (Inactive) Assignee: Andris Zeila
Resolution: Fixed Votes: 0
Labels: preprocessing, regexps
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Team: Team C
Sprint: Sprint 15, Sprint 16
Story Points: 0.5

 Description   

Steps:
1. Create host with item for monitoring apache server (web.page.get[localhost,/server-status])
2. Create dependent item with preprocessing configuration = “([0-9]*) day” and output =”0\1”
3. Restart apache server
4. Wait until items get information

Result: Dependent item is ‘Not supported’ bacause of:
Value "" of type "string" is not suitable for value type "Numeric (unsigned)"
Expected: Last value of dependent item equal to 0.



 Comments   
Comment by Glebs Ivanovskis (Inactive) [ 2017 Aug 10 ]

In this case you can utilize full power of PCRE's lookahead:

([0-9]+(?= days)|(?![0-9]+ days))

This captures number which is followed by " days" or captures empty string if there is no number followed by " days". This way there will always be \1 to replace.

But that's just a workaround in case someone needs it...

Comment by Andris Zeila [ 2017 Aug 30 ]

It seems like 'feature' of our regular expression matching logic - if the input text does not match pattern, then the resulting output is empty string, it does not replace groups with empty strings in the output pattern.
Regarding workarounds - adding another regsub operation with patthern (.*) and output 0\1 should also work :/

There are several ways how we could proceed:

  1. document it and leave as it is
  2. make item not supported when expression does not match
  3. return input string when expression does not match
  4. return output string when expression does not match
  5. return output stirng with \N (capture group patterns) removed (empty)

The choosen solution is in bold.

Comment by Andris Zeila [ 2017 Aug 31 ]

Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-12500
(fix is based on 3.4 brach)

Comment by Andris Zeila [ 2017 Sep 06 ]

Released in:

  • pre-3.4.2rc1 r72247
  • pre-4.0.0alpha1 r72248
Comment by Andris Zeila [ 2017 Sep 06 ]

(1) [D] Documented in:

martins-v Reviewed, with a tiny grammar fix. CLOSED

Generated at Fri Mar 29 14:22:37 EET 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.