[ZBXNEXT-1782] triggers should support greater than or equal to (>=) and less than or equal to (<=) Created: 2013 Jun 07  Updated: 2018 Apr 18  Resolved: 2014 Jul 02

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: Frontend (F), Server (S)
Affects Version/s: 2.0.6
Fix Version/s: 2.3.0

Type: Change Request Priority: Minor
Reporter: Tim Mooney Assignee: Pavels Jelisejevs (Inactive)
Resolution: Fixed Votes: 3
Labels: expressions, trigger, usability
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Server: RHEL 6.4 x86_64 with local mysql database


Attachments: PNG File expression_parser.png    
Issue Links:
Causes
causes ZBX-13742 It is possible to create a trigger wi... Closed
Duplicate

 Description   

Note that I searched the issue tracker for more than an hour and couldn't find any similar reports (which really surprises me!). My apologies if this is a duplicate report and I just didn't find what it duplicates.

With the current trigger implementation, you can't use >= or <= in trigger expressions.

This causes problems when you want to have two separate triggers related to the value of some item. For example, let's say I want a warning if the ping loss is less than 50%, but I want an error if it's >= 50%. You can't actually do that with current triggers, so you end up
doing stuff like this:

trigger #1 expression: {devicename:icmppingloss[,,200,32,1200].last(0)}<50.1
trigger #2 expression: {devicename:icmppingloss[,,200,32,1200].last(0)}>50.0

(so there's overlap, and both triggers may fire if the item value is exactly 50.0)

Or, much worse, you do something like:

trigger #1 expression: {devicename:icmppingloss[,,200,32,1200].last(0)}<50.0
trigger #2 expression: {devicename:icmppingloss[,,200,32,1200].last(0)}>50.0

In which case neither trigger fires if there's exactly 50% packet loss.

This is even worse when you consider that sites might want to use user macros in their templates, so that the desired threshold might be {$PING_PACKET_LOSS} => 50.0 at the template level. The first case (the overlap) now becomes impossible, unless you define two macros, which is a pretty horrible workaround.

What's really needed is for both the trigger engine and the frontend expression builder to support both >= and <=, so that multiple trigger expressions can correctly handle ranges with no overlap and especially no gap.



 Comments   
Comment by Timo Veith [ 2013 Jul 30 ]

I second this. There were several situations, in which I also would have used "greater/less then or equal to".

Thanks.
tvtue

Comment by Tim Mooney [ 2013 Nov 27 ]

The lack of <= and >= is becoming more and more of an annoyance for me, so I've been looking at the source code to try determine what would be involved in fixing this.

Can I get some feedback from a developer? I'm willing to do the work, but I'll need some guidance.

It looks like src/libs/zbxserver/expression.c is where I need to start, specifically evaluate_simple().

It appears that there are at least a couple things that need to change:

1) The large "if" that uses strchr() to check for each of the single-character operators either needs to be reworked to use strstr() and advance the character pointer a variable number of characters (2 if the operator is <= or >=, 1 for all the other operators). Either that, or we need a new "if" before this one, that checks for <= and >=.

2) The switch statement needs to be converted to a sequence of if/else if statements that use strcmp to check for the appropriate operators.
In addition, there needs to be checks for <= and >= that just check cmp_double first and succeed if it does, and then check either < or >, as the existing tests do.

Am I on the right track? If I submit a patch, will you review and provide guidance for improvements?

Comment by Marc [ 2014 Jan 02 ]

Me and probably many others would appreciate to see a patch.
But don't expect any guidance or feedback from upstream development team - miracles happen though.

Comment by Alexei Vladishev [ 2014 Jan 20 ]

It is scheduled to be implemented in Zabbix 2.4, initial specification is available at https://www.zabbix.org/wiki/Docs/specs/ZBXNEXT-1782

Comment by Andris Zeila [ 2014 Mar 25 ]

(1) [I] Database patch does not remove extra spaces around operators

asaveljevs RESOLVED in r43962.

wiper CLOSED

Comment by Aleksandrs Saveljevs [ 2014 Apr 01 ]

ZBX-8014 is also going to be solved under this issue.

Comment by Aleksandrs Saveljevs [ 2014 Apr 01 ]

The C side implements a new algorithm for evaluating expressions. Performance is dependent on expression complexity, but on an expression like "-5+10*-6-700/(49*(1/(2+5)))=-165" the new algorithm is about 8-9 times faster.

Comment by richlv [ 2014 Apr 22 ]

what follows is purely personal opinion

i've been thinking about this for some time. my current conclusion is that it does not seem to provide any significant improvement.

the supposed benefit - making expressions easier to get into for new users - is a very short lived and imho does not trump the drawbacks.
it creates a problem for existing users, makes expressions longer and harder to read.

existing users, when upgrading, would have to adapt. many users have several zabbix installations/versions in parallel - transition period would be fairly confusing for them. people who have to support larger amount of zabbix users with different versions would have their life made harder - that would include those working on it in any capacity, but same goes for community self-help.

expressions being longer makes it harder to grasp what they do quickly. using words (even if short), as opposed to symbols, takes a bit longer to parse mentally - picking out symbols from a character stream is easier.

additionally, it seems to try to solve a problem that is not largely there - the only confusion seems to be usage of # as 'not' for new users - but besides being non-standard it does not cause any problems once they know about this use. once users examine the used operators, they are perfectly clear to them.

adding support for >= and <= without changing existing behaviour would bring much more benefit.

again, all of the above is just my opinion for the record, not meant to change the current direction.

Comment by Alexander Vladishev [ 2014 Apr 23 ]

(2) Please review my changes in r44722:44730

asaveljevs Looks very good, thank you. Improved a bit further in r44756. CLOSED.

Comment by Pavels Jelisejevs (Inactive) [ 2014 May 19 ]

(9) Implemented trigger expression convertion when importing in r45614 and 45634.

sasha CLOSED

Comment by Alexander Vladishev [ 2014 May 21 ]

(10) "Undefined index" in "Trigger expression condition" popup

Expression example:

{host:trap.str(abc)}>25w

Error messages:

Undefined index: str[>] [ in popup_trexpr.php:697]
Function "" cannot be used with selected item "host: trap"

jelisejev RESOLVED in r45714.

sasha CLOSED

Comment by Alexander Vladishev [ 2014 May 21 ]

(11) addToken() method shouldn't add empty 'data' array for simple tokens.

jelisejev I think it's more appropriate to return NULLs instead of not returning the "data" attribute at all. RESOLVED in r45715.

sasha CLOSED

Comment by Alexei Vladishev [ 2014 May 21 ]

(12) Unable to create database, problems while loading data.sql:

shell> cat schema.sql images.sql data.sql|mysql -uroot zbxnext1782

ERROR 1452 (23000) at line 2936: Cannot add or update a child row: a foreign key constraint fails
(`zbxnext1782`.`triggers`, CONSTRAINT `c_triggers_1` FOREIGN KEY (`templateid`) REFERENCES
`triggers` (`triggerid`) ON DELETE CASCADE)

sasha RESOLVED in r45739

alexei CLOSED

Comment by Alexander Vladishev [ 2014 May 21 ]

(13) [XML import] C24TriggerExpressionConverter doesn't work correctly.

I added some test cases.

sasha r45750 was successfully tested!

sasha CLOSED

Comment by Alexander Vladishev [ 2014 May 22 ]

(14) [F] GUI shouldn't support LLD filter expressions without spaces around logical operators

jelisejev RESLOVED in r45758

sasha Please review my changes in r45759.

jelisejev CLOSED.

Comment by Alexander Vladishev [ 2014 May 22 ]

Available in pre-2.3.0 (trunk) r45764.

Comment by Ivo Kurzemnieks [ 2014 Jul 01 ]

(15) In some cases trigger expression parser may retun string with open parentheses. For example I have a trigger expression:

((({common1:eventlog[logtype].regexp(A)})<>0) or (({common1:eventlog[logtype].regexp(B)})<>0))

Parser returnes string:

( ( ( ((float) "0") ) <> ((float) "0") ) or ( ( ((float) "0") ) <> ((float) "0") ) (

Evaulation fails. See attached image.

jelisejev RESOLVED in svn://svn.zabbix.com/branches/dev/ZBXNEXT-1782.

kristsk CLOSED.

Comment by Pavels Jelisejevs (Inactive) [ 2014 Jul 07 ]

Fixed in 2.3.2 r47082.

CLOSED.

Comment by richlv [ 2015 Feb 27 ]

for the record, this resulted in a regression : trigger dependencies on triggers with old operators fail to import. ZBX-9346

Comment by richlv [ 2015 Mar 18 ]

we also forgot to update web monitoring docs - see ZBX-9412

Comment by richlv [ 2016 Apr 08 ]

changelog for this issue said "fixed... not working incorrectly" - reported as ZBX-10635

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