[ZBX-22874] Trigger expression for "and not" not correspond expected behavior Created: 2023 May 31  Updated: 2024 Apr 10  Resolved: 2023 Jul 08

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Documentation (D)
Affects Version/s: 5.0.35, 6.0.18
Fix Version/s: 6.0.20rc1, 6.4.5rc1, 7.0.0alpha3, 7.0 (plan)

Type: Documentation task Priority: Trivial
Reporter: Egor T. Assignee: Martins Valkovskis
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File image-2023-06-05-07-20-54-849.png     PNG File image-2023-06-05-07-21-58-386.png     PNG File image_2023-05-31_12-07-06.png     PNG File not-sunday-not-saturday_not_working.png     PNG File not-sunday-not-saturday_working.png    
Team: Team D
Sprint: Sprint 101 (Jun 2023)
Story Points: 0.25

 Description   

Hello.

Our expectation that trigger expression with "and not" for these two cases will provide us the same result:

1) and not dayofweek()=6 and not dayofweek()=7

2) and not (dayofweek()=6 and dayofweek()=7)

First expression not work. Second work correctly.

There is no documentation for this case.

Only https://www.zabbix.com/documentation/current/en/manual/config/triggers/expression

with explanation:

"notand and or operators are case-sensitive and must be in lowercase. They also must be surrounded by spaces or parentheses."

Looks like parentheses is mandatory. Not "spaces or parentheses." -> "spaces and parentheses".

This mistake caused incident unfortunately. Please see attachment for example.



 Comments   
Comment by Aigars Kadikis [ 2023 Jun 02 ]

I'm confirming. If we want to negate something, then parentheses are mandatory.
For example, to make sure this is not Saturday and Sunday, this works:

and not (dayofweek()=6 and dayofweek()=7)

or:

and not (dayofweek()=6) and not (dayofweek()=7)

Screenshots from the expression calculator.

Not working correctly without parentheses :

 

Working correctly by using parentheses:

Comment by Egor T. [ 2023 Jun 05 ]

Hello dear aigars.kadikis

Let me please do not agree with you. We realized that  functions you mentioned not equal between each other:

and not (dayofweek()=6 and dayofweek()=7)

or:

and not (dayofweek()=6) and not (dayofweek()=7)

Please see test below. Test from today (dayofweek = 1).

This looks really strange. 

Thank you for your support!

 

Comment by Aigars Kadikis [ 2023 Jun 15 ]

It was my mistake to say this will solve the problem:

and not (dayofweek()=6 and dayofweek()=7) 

If we put any two different days in the parentheses, then the outcome will always be true (just like in screenshot). Because it's impossible that "today" can belong to two different week days at the same time. While technical trigger expression does not fail, there is no real-life situation to use it. We should ignore this use case and syntax.

Better to stick to this syntax:

and not (dayofweek()=6) and not (dayofweek()=7)

P.S. Not related to documentation task, but you should use "bigger than" or "less than".

Working days:

dayofweek() < 6

Weekend (Saturday, Sunday):

dayofweek() > 5
Comment by Martins Valkovskis [ 2023 Jun 26 ]

The documentation of time functions has been updated in 6.0, 6.4, 7.0 versions to include useful examples from the previous comment by aigars.kadikis.

For a more complex example including "and not", see trigger example 10.

Generated at Sun Apr 27 09:24:07 EEST 2025 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.