manual:regular_expressions

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
Next revision Both sides next revision
manual:regular_expressions [2018/10/22 05:38]
martins-v adding regexp support in auto registration
manual:regular_expressions [2021/01/20 10:39]
martins-v updating screenshot (DEV-1780)
Line 13: Line 13:
  
 You may manually enter a regular expression in supported places. Note that the expression may not start with @ because that symbol is used in Zabbix for referencing global regular expressions. You may manually enter a regular expression in supported places. Note that the expression may not start with @ because that symbol is used in Zabbix for referencing global regular expressions.
 +
 +<note warning>​It'​s possible to run out of stack when using regular expressions. See the [[http://​pcre.org/​original/​doc/​html/​pcrestack.html|pcrestack man page]] for more information.</​note>​
 +
 +Note that in multi-line matching, the ''​^''​ and ''​$''​ anchors match at the beginning/​end of each line respectively,​ instead of the beginning/​end of the entire string.
  
 === Global regular expressions === === Global regular expressions ===
Line 28: Line 32:
 The **Expressions** tab allows to set the regular expression name and add subexpressions. ​ The **Expressions** tab allows to set the regular expression name and add subexpressions. ​
  
-{{manual:​regular_expressions:​regexp_expr.png?600|}}+{{manual:​regular_expressions:​global_regexp.png|}}
  
 All mandatory input fields are marked with a red asterisk. ​ All mandatory input fields are marked with a red asterisk. ​
Line 40: Line 44:
 |//Case sensitive// ||A checkbox to specify whether a regular expression is sensitive to capitalization of letters. ​ | |//Case sensitive// ||A checkbox to specify whether a regular expression is sensitive to capitalization of letters. ​ |
  
-Since Zabbix 2.4.0, a forward slash (/) in the expression is treated literally, rather than a delimiter. This way it is possible to save expressions containing a slash, ​whereas previously it would produce an error.+forward slash (/) in the expression is treated literally, rather than a delimiter. This way it is possible to save expressions containing a slash, ​without errors.
  
 <note important>​A custom regular expression name in Zabbix may contain commas, spaces, etc. In those cases where that may lead to misinterpretation when referencing (for example, a comma in the parameter of an item key) the whole reference may be put in quotes like this: //​%%"​%%@My custom regexp for purpose1, purpose2%%"​%%//​.\\ Regular expression names must not be quoted in other locations (for example, in LLD rule properties).</​note>​ <note important>​A custom regular expression name in Zabbix may contain commas, spaces, etc. In those cases where that may lead to misinterpretation when referencing (for example, a comma in the parameter of an item key) the whole reference may be put in quotes like this: //​%%"​%%@My custom regexp for purpose1, purpose2%%"​%%//​.\\ Regular expression names must not be quoted in other locations (for example, in LLD rule properties).</​note>​
  
-=== Example ===+In the **Test** tab the regular expression and its subexpressions can be tested by providing a test string.
  
-Use of the following ​regular ​expression in LLD to discover databases ​not taking into consideration ​a database with a specific name:  ​+{{manual:​regular_expressions:​global_regexp_b.png|}} 
 + 
 +Results show the status of each subexpression and total custom expression status.  
 + 
 +Total custom expression status is defined as //Combined result//. If several sub expressions are defined Zabbix uses AND logical operator to calculate //Combined result//. It means that if at least one Result is False //Combined result// has also False status.  
 + 
 +=== Default global regular expressions === 
 + 
 +Zabbix comes with several global regular expression in its default dataset. 
 + 
 +^Name^Expression^Matches^ 
 +|//File systems for discovery// ​ |''​^(btrfs|ext2|ext3|ext4|jfs|reiser|xfs|ffs|ufs|jfs|jfs2|vxfs|hfs|refs|apfs|ntfs|fat32|zfs)$'' ​ |%%"​%%btrfs%%"​%% or %%"​%%ext2%%"​%% or %%"​%%ext3%%"​%% or %%"​%%ext4%%"​%% or %%"​%%jfs%%"​%% or %%"​%%reiser%%"​%% or %%"​%%xfs%%"​%% or %%"​%%ffs%%"​%% or %%"​%%ufs%%"​%% or %%"​%%jfs%%"​%% or %%"​%%jfs2%%"​%% or %%"​%%vxfs%%"​%% or %%"​%%hfs%%"​%% or %%"​%%refs%%"​%% or %%"​%%apfs%%"​%% or %%"​%%ntfs%%"​%% or %%"​%%fat32%%"​%% or %%"​%%zfs%%"​%% ​ | 
 +|//Network interfaces for discovery// ​ |''​^Software Loopback Interface'' ​ |Strings starting with %%"​%%Software Loopback Interface%%"​%%. ​ | 
 +|  |''​^lo$'' ​ |%%"​%%lo%%"​%% ​ | 
 +|  |''​^(In)?​[Ll]oop[Bb]ack[0-9._]*$'' ​ |Strings that optionally start with %%"​%%In%%"​%%,​ then have %%"​%%L%%"​%% or %%"​%%l%%"​%%,​ then %%"​%%oop%%"​%%,​ then %%"​%%B%%"​%% or %%"​%%b%%"​%%,​ then %%"​%%ack%%"​%%,​ which can be optionally followed by any number of digits, dots or underscores. ​ | 
 +|  |''​^NULL[0-9.]*$'' ​ |Strings starting with %%"​%%NULL%%"​%% optionally followed by any number of digits or dots.  | 
 +|  |''​^[Ll]o[0-9.]*$'' ​ |Strings starting with %%"​%%Lo%%"​%% or %%"​%%lo%%"​%% and optionally followed by any number of digits or dots.  | 
 +|  |''​^[Ss]ystem$'' ​ |%%"​%%System%%"​%% or %%"​%%system%%"​%% ​ | 
 +|  |''​^Nu[0-9.]*$'' ​ |Strings starting with %%"​%%Nu%%"​%% optionally followed by any number of digits or dots.  | 
 +|//Storage devices for SNMP discovery// ​ |''​^(Physical memory|Virtual memory|Memory buffers|Cached memory|Swap space)$'' ​ |%%"​%%Physical memory%%"​%% or %%"​%%Virtual memory%%"​%% or %%"​%%Memory buffers%%"​%% or %%"​%%Cached memory%%"​%% or %%"​%%Swap space%%"​%% ​ | 
 +|//Windows service names for discovery// ​ |''​^(MMCSS|gupdate|SysmonLog|clr_optimization_v2.0.50727_32|clr_optimization_v4.0.30319_32)$'' ​ |%%"​%%MMCSS%%"​%% or %%"​%%gupdate%%"​%% or %%"​%%SysmonLog%%"​%% or strings like %%"​%%clr_optimization_v2.0.50727_32%%"​%% and %%"​%%clr_optimization_v4.0.30319_32%%"​%% where instead of dots you can put any character except newline. ​ | 
 +|//Windows service startup states for discovery// ​ |''​^(automatic|automatic delayed)$'' ​ |%%"​%%automatic%%"​%% or %%"​%%automatic delayed%%"​%% ​ | 
 + 
 +=== Examples === 
 + 
 +== Example 1 == 
 + 
 +Use of the following expression in low-level discovery ​to discover databases ​except ​a database with a specific name:  ​
  
   ^TESTDATABASE$   ^TESTDATABASE$
Line 54: Line 85:
 Chosen //​Expression type//: %%"​Result is FALSE"​%%. Doesn'​t match name, containing string "//​TESTDATABASE//"​. Chosen //​Expression type//: %%"​Result is FALSE"​%%. Doesn'​t match name, containing string "//​TESTDATABASE//"​.
  
-=== Example with an inline regex modifier ​===+== Example with an inline regex modifier ==
  
 Use of the following regular expression including an inline modifier (?i) to match the characters "​error":​ Use of the following regular expression including an inline modifier (?i) to match the characters "​error":​
Line 64: Line 95:
 Chosen //​Expression type//: %%"​Result is TRUE"​%%. Characters "​error"​ are matched. ​ Chosen //​Expression type//: %%"​Result is TRUE"​%%. Characters "​error"​ are matched. ​
  
-=== Another example with an inline regex modifier ​===+== Another example with an inline regex modifier ==
  
 Use of the following regular expression including multiple inline modifiers to match the characters after a specific line: Use of the following regular expression including multiple inline modifiers to match the characters after a specific line:
Line 74: Line 105:
  
 <note important>​ **g** modifier can't be specified in line. The list of available modifiers can be found in [[https://​www.pcre.org/​original/​doc/​html/​pcresyntax.html#​SEC16|pcresyntax man page]]. For more information about PCRE syntax please refer to [[https://​www.pcre.org/​original/​doc/​html/​pcrepattern.html|PCRE HTML documentation]]. ​ </​note>​ <note important>​ **g** modifier can't be specified in line. The list of available modifiers can be found in [[https://​www.pcre.org/​original/​doc/​html/​pcresyntax.html#​SEC16|pcresyntax man page]]. For more information about PCRE syntax please refer to [[https://​www.pcre.org/​original/​doc/​html/​pcrepattern.html|PCRE HTML documentation]]. ​ </​note>​
- 
-=== More complex example === 
- 
-A custom regular expression may consist of multiple subexpressions,​ and it can be tested in the **Test** tab by providing a test string. 
- 
-{{manual:​regular_expressions:​regexp_test.png?​600|}} 
- 
-Results show the status of each subexpression and total custom expression status. ​ 
- 
-Total custom expression status is defined as //Combined result//. If several sub expressions are defined Zabbix uses AND logical operator to calculate //Combined result//. It means that if at least one Result is False //Combined result// has also False status. ​ 
- 
-=== Explanation of global regular expressions === 
- 
-^Global regexp^Expression^Description^ 
-|//File systems for discovery// ​ |''​^(btrfs|ext2|ext3|ext4|jfs|reiser|xfs|ffs|ufs|jfs|jfs2|vxfs|hfs|refs|ntfs|fat32|zfs)$'' ​ |Matches "​btrfs"​ or "​ext2"​ or "​ext3"​ or "​ext4"​ or "​jfs"​ or "​reiser"​ or " xfs" or "​ffs"​ or "​ufs"​ or "​jfs"​ or "​jfs2"​ or "​vxfs"​ or "​hfs"​ or "​refs"​ or "​ntfs"​ or "​fat32"​ or "​zfs" ​ | 
-|//Network interfaces for discovery// ​ |''​^Software Loopback Interface'' ​ |Matches strings starting with "​Software Loopback Interface" ​ | 
-|  |''​^lo$'' ​ |Matches "​lo" ​ | 
-|  |''​^(In)?​[Ll]oop[Bb]ack[0-9._]*$'' ​ |Matches strings that optionally start with "​In",​ then have "​L"​ or "​l",​ then "​oop",​ then "​B"​ or "​b",​ then "​ack",​ which can be optionally followed by any number of digits, dots or underscores ​ | 
-|  |''​^NULL[0-9.]*$'' ​ |Matches strings staring with "​NULL"​ optionally followed by any number of digits or dots  | 
-|  |''​^[Ll]o[0-9.]*$'' ​ |Matches strings starting with "​Lo"​ or "​lo"​ and optionally followed by any number of digits or dots  | 
-|  |''​^[Ss]ystem$'' ​ |Matches "​System"​ or "​system" ​ | 
-|  |''​^Nu[0-9.]*$'' ​ |Matches strings staring with "​Nu"​ optionally followed by any number of digits or dots  | 
-|//Storage devices for SNMP discovery// ​ |''​^(Physical memory|Virtual memory|Memory buffers|Cached memory|Swap space)$'' ​ |Matches "​Physical memory"​ or "​Virtual memory"​ or "​Memory buffers"​ or "​Cached memory"​ or "Swap space" ​ | 
-|//Windows service names for discovery// ​ |''​^(MMCSS|gupdate|SysmonLog|clr_optimization_v2.0.50727_32|clr_optimization_v4.0.30319_32)$'' ​ |Matches "​MMCSS"​ or "​gupdate"​ or "​SysmonLog"​ or strings like "​clr_optimization_v2.0.50727_32"​ and "​clr_optimization_v4.0.30319_32"​ where instead of dots you can put any character except newline. ​ | 
-|//Windows service startup states for discovery// ​ |''​^(automatic|automatic delayed)$'' ​ |Matches "​automatic"​ or "​automatic delayed"​. ​ | 
- 
  
 === Regular expression support by location === === Regular expression support by location ===
Line 117: Line 122:
 |:::​|system.hw.macaddr[] |:::​|:::​|''​interface''​ parameter| |:::​|system.hw.macaddr[] |:::​|:::​|''​interface''​ parameter|
 |:::​|system.sw.packages[]|:::​|:::​|''​package''​ parameter| |:::​|system.sw.packages[]|:::​|:::​|''​package''​ parameter|
-|:::​|vfs.dir.count[] ​    ​|:::​|:::​|''​regex_incl'' ​and ''​regex_excl''​ parameters| +|:::​|vfs.dir.count[] ​    ​|:::​|:::​|''​regex_incl''​''​regex_excl'',​ ''​regex_excl_dir''​ parameters| 
-|:::​|vfs.dir.size[] ​     |:::​|:::​|''​regex_incl'' ​and ''​regex_excl''​ parameters|+|:::​|vfs.dir.size[] ​     |:::​|:::​|''​regex_incl''​''​regex_excl'',​ ''​regex_excl_dir''​ parameters|
 |:::​|vfs.file.regexp[] ​  ​|:::​|:::​|''​regexp''​ parameter| |:::​|vfs.file.regexp[] ​  ​|:::​|:::​|''​regexp''​ parameter|
 |:::​|vfs.file.regmatch[] |:::​|:::​|:::​| |:::​|vfs.file.regmatch[] |:::​|:::​|:::​|
Line 131: Line 136:
 |:::​|iregexp() ​  ​|:::​|:::​|:::​| |:::​|iregexp() ​  ​|:::​|:::​|:::​|
 |:::​|regexp() ​   |:::​|:::​|:::​| |:::​|regexp() ​   |:::​|:::​|:::​|
-|**[[:​manual/​discovery/​low_level_discovery#​discovery_rule_filter|Low-level discovery]]** ||Yes|Yes|//​Filter// field| +|**[[:​manual/​discovery/​low_level_discovery#​discovery_rule_filter|Low-level discovery]]** |^  ^^^ 
-|**[[:​manual/​config/​notifications/​action/​conditions|Action conditions]]** ||Yes|No|In //​matches//,​ //does not match// options for //Host name// and //Host metadata// ​auto-registration ​conditions|+^   ​|Filters ​   ​|Yes|Yes|//Regular expression// field 
 +|:::​|Overrides ​ |Yes|No |In //​matches//,​ //does not match// options for //​Operation//​ conditions
 +|**[[:​manual/​config/​notifications/​action/​conditions|Action conditions]]** ||Yes|No|In //​matches//,​ //does not match// options for //Host name// and //Host metadata// ​autoregistration ​conditions|
 |**[[:​manual/​web_monitoring#​configuring_a_web_scenario|Web monitoring]]** ​  ​||Yes|No |//​Variables//​ with a **regex:** prefix\\ //Required string// field| |**[[:​manual/​web_monitoring#​configuring_a_web_scenario|Web monitoring]]** ​  ​||Yes|No |//​Variables//​ with a **regex:** prefix\\ //Required string// field|
 +|**[[manual:​config:​macros:​user_macros#​user_macro_context|User macro context]]** ​  ​||Yes|No |In macro context with a **regex:** prefix ​ |
 |**[[:​manual/​config/​macros/​macro_functions|Macro functions]]**|^ ​ ^^^ |**[[:​manual/​config/​macros/​macro_functions|Macro functions]]**|^ ​ ^^^
 ^   ​|regsub() |Yes|No |''​pattern''​ parameter| ^   ​|regsub() |Yes|No |''​pattern''​ parameter|
 |:::​|iregsub()|:::​|:::​|:::​| |:::​|iregsub()|:::​|:::​|:::​|
 |**[[:​manual/​web_interface/​frontend_sections/​administration/​general#​icon_mapping|Icon mapping]]** ||Yes|Yes|//​Expression//​ field| |**[[:​manual/​web_interface/​frontend_sections/​administration/​general#​icon_mapping|Icon mapping]]** ||Yes|Yes|//​Expression//​ field|
- 
- 
-