Zabbix支持POSIX 正则表达式
There are two ways of using regular expressions in Zabbix: 在Zabbix中有两种方法使用正则表达式
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. 你可以在受支持位置中手动输入正则表达式。请注意,表达式不能以@开头,因为该符号在Zabbix中用于引用全局正则表达式。
There is an advanced editor for creating and testing complex regular expressions in Zabbix frontend. 有一个高级编辑器用于在Zabbix前端中创建和测试复杂的正则表达式。
Once a regular expression has been created this way, it can be used in several places in the frontend by referring to its name, prefixed with @, for example, @mycustomregexp. 一旦以这种方式创建了正则表达式,它可以在前端的多个地方通过引用其名称(前缀为@)来使用,例如@mycustomregexp
To create a global regular expression: 创建全局正则表达式
The Expressions tab allows to set the regular expression name and add subexpressions. 表达式选项卡允许设置正则表达式名称和添加子表达式。
参数 | 说 | |
---|---|---|
名称(Name) | 设置正 | 表达式名称。 允许任何Unicode字符。 |
表达式(Expressions) | 单击表达 | 区域中的添加(Add)以添加新的子表达式。 |
表达式类型(Expression type) 选择表达式类 | : 字符串已包含(Character string included) - 匹配子字符串 包含任何字符串(Any character string included) - 匹配逗号分隔列表中的任何子字符串 字符串未包含(Character string not included) - 匹配除了子字符串之外的任何字符串 结果为真(Result is TRUE) - 匹配正则表达式 结果为假(Result is FALSE) - 不匹配正则表达式 |
|
表达式(Expression) 输入子字 | 串/正则表达式。 |
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.
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).
A custom regular expression may consist of multiple subexpressions, and it can be tested in the Test tab by providing a test string.
Results show the status of each subexpression and total custom expression status.
Location | Regexp support | Global regexp support | Comments | |
---|---|---|---|---|
Macro functions | ||||
regsub() | Yes | No | pattern parameter | |
iregsub() | ||||
Trigger functions | ||||
count() | Yes | Yes | pattern parameter if operator parameter is regexp or iregexp | |
logeventid() | pattern parameter | |||
iregexp() | ||||
regexp() | ||||
Low-level discovery | ||||
Yes | Yes | Filter field | ||
Web monitoring | ||||
Yes | No | Variables with a regex: prefix Required string field |
||
Zabbix agent items | ||||
eventlog[] | Yes | Yes | regexp, severity, source, eventid parameters | |
log[] | regexp parameter | |||
log.count[] | ||||
logrt[] | Yes/No | regexp parameter supports both, file_regexp parameter supports non-global expressions only | ||
logrt.count[] | ||||
proc.cpu.util[] | No | cmdline parameter | ||
proc.mem[] | ||||
proc.num[] | ||||
sensor[] | device and sensor parameters on Linux 2.4 | |||
system.hw.macaddr[] | interface parameter | |||
system.sw.packages[] | package parameter | |||
vfs.dir.size[] | regex_incl and regex_excl parameters | |||
vfs.file.regexp[] | regexp parameter | |||
vfs.file.regmatch[] | ||||
web.page.regexp[] | ||||
SNMP traps | ||||
snmptrap[] | Yes | Yes | regexp parameter | |
Icon mapping | ||||
Yes | Yes | Expression field |