Zabbix Documentation 5.0

3.04.05.0 (current)| In development:5.2 (devel)| Unsupported:1.82.02.22.43.23.44.24.4Guidelines

User Tools

Site Tools


manual:config:triggers:expression

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
manual:config:triggers:expression [2019/07/08 05:46]
martins-v more precise wording
manual:config:triggers:expression [2020/04/24 06:49] (current)
martins-v string comparison allowed (ZBXNEXT-702)
Line 21: Line 21:
  
 A complete list of [[manual:​appendix:​triggers:​functions|supported functions]] is available. A complete list of [[manual:​appendix:​triggers:​functions|supported functions]] is available.
 +
 +Typically functions return numeric values. However, returning strings for string comparison is also possible with **=** and **<>​** operators; see [[#​operators|operators]] and trigger [[#​example_14|examples]] for more details.
  
 === Function parameters === === Function parameters ===
Line 39: Line 41:
  
 Numbers with a '​+'​ sign are not supported. Numbers with a '​+'​ sign are not supported.
 +
 === Operators === === Operators ===
  
 The following operators are supported for triggers **(in descending priority of execution)**:​ The following operators are supported for triggers **(in descending priority of execution)**:​
  
-^PRIORITY^OPERATOR^DEFINITION^**Notes for [[:​manual/​config/​triggers/​expression#​expressions_with_unsupported_items_and_unknown_values|unknown values]]**^ +^Priority^Operator^Definition^**Notes for [[:​manual/​config/​triggers/​expression#​expressions_with_unsupported_items_and_unknown_values|unknown values]]**^Force cast operand to float <​sup>​**1**</​sup>​
-|**1** ​ |**-** ​ |Unary minus  |**-**Unknown -> Unknown| +|**1** ​ |**-** ​ |Unary minus  |**-**Unknown -> Unknown|Yes  ​
-|**2** ​ |**not** ​ |Logical NOT  |**not** Unknown -> Unknown| +|**2** ​ |**not** ​ |Logical NOT  |**not** Unknown -> Unknown|Yes  ​
-|**3** ​ |**<​nowiki>​*</​nowiki>​** ​ |Multiplication ​ |0 **<​nowiki>​*</​nowiki>​** Unknown -> Unknown\\ (yes, Unknown, not 0 - to not lose\\ Unknown in arithmetic operations)\\ 1.2 **<​nowiki>​*</​nowiki>​** Unknown -> Unknown| +|**3** ​ |**<​nowiki>​*</​nowiki>​** ​ |Multiplication ​ |0 **<​nowiki>​*</​nowiki>​** Unknown -> Unknown\\ (yes, Unknown, not 0 - to not lose\\ Unknown in arithmetic operations)\\ 1.2 **<​nowiki>​*</​nowiki>​** Unknown -> Unknown|Yes  ​
-|       ​|**/​** ​ |Division ​ |Unknown **/** 0 -> error\\ Unknown **/** 1.2 -> Unknown\\ 0.0 **/** Unknown -> Unknown| +|       ​|**/​** ​ |Division ​ |Unknown **/** 0 -> error\\ Unknown **/** 1.2 -> Unknown\\ 0.0 **/** Unknown -> Unknown|Yes  ​
-|**4** ​ |**+** ​ |Arithmetical plus  |1.2 **+** Unknown -> Unknown| +|**4** ​ |**+** ​ |Arithmetical plus  |1.2 **+** Unknown -> Unknown|Yes  ​
-|       ​|**-** ​ |Arithmetical minus  |1.2 **-** Unknown -> Unknown| +|       ​|**-** ​ |Arithmetical minus  |1.2 **-** Unknown -> Unknown|Yes  ​
-|**5** ​ |**<​** ​ |Less than. The operator is defined as:\\ \\ <​nowiki>​A<​B ⇔ (A<​B-0.000001)</​nowiki>​|1.2 **<** Unknown -> Unknown| +|**5** ​ |**<​** ​ |Less than. The operator is defined as:\\ \\ <​nowiki>​A<​B ⇔ (A<​B-0.000001)</​nowiki>​|1.2 **<** Unknown -> Unknown|Yes  ​
-|       ​|**<​nowiki><​=</​nowiki>​** |Less than or equal to. The operator is defined as:\\ \\ <​nowiki>​A<​=B ⇔ (A≤B+0.000001)</​nowiki>​|Unknown **<​nowiki><​=</​nowiki>​** Unknown -> Unknown| +|       ​|**<​nowiki><​=</​nowiki>​** |Less than or equal to. The operator is defined as:\\ \\ <​nowiki>​A<​=B ⇔ (A≤B+0.000001)</​nowiki>​|Unknown **<​nowiki><​=</​nowiki>​** Unknown -> Unknown|Yes  ​
-|       ​|**>​** ​ |More than. The operator is defined as:\\ \\ A>B ⇔ (A>​B+0.000001)| +|       ​|**>​** ​ |More than. The operator is defined as:\\ \\ A>B ⇔ (A>​B+0.000001)|  |Yes  ​
-|       ​|**>​=** |More than or equal to. The operator is defined as:\\ \\ <​nowiki>​A>​=B ⇔ (A≥B-0.000001)</​nowiki>​| +|       ​|**>​=** |More than or equal to. The operator is defined as:\\ \\ <​nowiki>​A>​=B ⇔ (A≥B-0.000001)</​nowiki>​|  |Yes  ​
-|**6** ​ |**=** ​ |Is equal. The operator is defined as:\\ \\  A=B ⇔ (A<​nowiki>​≥</​nowiki>​B-0.000001) and (A<​nowiki>​≤</​nowiki>​B+0.000001)| +|**6** ​ |**=** ​ |Is equal. The operator is defined as:\\ \\  A=B ⇔ (A<​nowiki>​≥</​nowiki>​B-0.000001) and (A<​nowiki>​≤</​nowiki>​B+0.000001)|  |No <​sup>​**1**</​sup>  ​
-|       ​|**<>​** |Not equal. The operator is defined as:\\ \\ <​nowiki>​A<>​B ⇔ (A<​B-0.000001) or (A>​B+0.000001)</​nowiki>​| +|       ​|**<>​** |Not equal. The operator is defined as:\\ \\ <​nowiki>​A<>​B ⇔ (A<​B-0.000001) or (A>​B+0.000001)</​nowiki>​|  |No <​sup>​**1**</​sup>  ​
-|**7** ​ |**and** ​ |Logical AND  |0 **and** Unknown -> 0\\  1 **and** Unknown -> Unknown\\ Unknown **and** Unknown -> Unknown| +|**7** ​ |**and** ​ |Logical AND  |0 **and** Unknown -> 0\\  1 **and** Unknown -> Unknown\\ Unknown **and** Unknown -> Unknown|Yes  ​
-|**8** ​ |**or** ​ |Logical OR  |1 **or** Unknown -> 1\\ 0 **or** Unknown -> Unknown\\ Unknown **or** Unknown -> Unknown|+|**8** ​ |**or** ​ |Logical OR  |1 **or** Unknown -> 1\\ 0 **or** Unknown -> Unknown\\ Unknown **or** Unknown -> Unknown|Yes  | 
 + 
 +<​sup>​**1**</​sup>​ String operand is still cast to numeric if: 
 +  * another operand is numeric 
 +  * operator other than **=** or **<>​** is used on an operand 
 +(If the cast fails - numeric operand is cast to a string operand and both operands get compared as strings.)
  
 **not**, **and** and **or** operators are case-sensitive and must be in lowercase. They also must be surrounded by spaces or parentheses. **not**, **and** and **or** operators are case-sensitive and must be in lowercase. They also must be surrounded by spaces or parentheses.
Line 170: Line 178:
  
 The trigger will fire if at least two of the triggers in the expression are over 5. The trigger will fire if at least two of the triggers in the expression are over 5.
 +
 +== Example 14 ==
 +
 +Comparing string values of two items - operands here are functions that return strings.
 +
 +Problem: create an alert if Ubuntu version is different on different hosts
 +
 +  {Riga Zabbix server:​vfs.file.contents[/​etc/​os-release].last()}<>​{London Zabbix server:​vfs.file.contents[/​etc/​os-release].last()}
 +
 +== Example 15 ==
 +
 +Comparing two string values - operands are: 
 +  * a function that returns a string
 +  * a combination of macros and strings
 +
 +Problem: detect changes in the DNS query
 +
 +The item key is:
 +
 +  net.dns.record[8.8.8.8,​{$WEBSITE_NAME},​{$DNS_RESOURCE_RECORD_TYPE},​2,​1]
 +
 +with macros defined as
 +
 +  {$WEBSITE_NAME} = zabbix.com
 +  {$DNS_RESOURCE_RECORD_TYPE} = MX
 +
 +and normally returns:
 +
 +  zabbix.com ​          ​MX ​      0 mail.zabbix.com
 +  ​
 +So our trigger expression to detect if the DNS query result deviated from the expected result is:
 +
 +  {Zabbix server:​net.dns.record[8.8.8.8,​{$WEBSITE_NAME},​{$DNS_RESOURCE_RECORD_TYPE},​2,​1].last()}<>"​{$WEBSITE_NAME} ​          ​{$DNS_RESOURCE_RECORD_TYPE} ​      0 mail.{$WEBSITE_NAME}"​
 +
 +Notice the quotes around the second operand.
 +
 +== Example 16 ==
 +
 +Comparing two string values - operands are: 
 +  * a function that returns a string ​
 +  * a string constant with special characters \ and %%"%%
 +
 +Problem: detect if the ''/​tmp/​hello''​ file content is equal to:
 +
 +  \" //hello ?\"
 +
 +Option 1) write the string directly
 +
 +  {Zabbix server:​vfs.file.contents[/​tmp/​hello].last()}="​\\\"​ //hello ?​\\\""​
 +
 +Notice how \ and %%"%% characters are escaped when the string gets compared directly.
 +
 +Option 2) use a macro
 +
 +  {$HELLO_MACRO} = \" //hello ?\"
 +
 +in the expression:
 +
 +  {Zabbix server:​vfs.file.contents[/​tmp/​hello].last()}={$HELLO_MACRO}
  
 === Hysteresis === === Hysteresis ===