Zabbix Documentation 3.4 (current)In development:4.4 (devel)Unsupported:

User Tools

Site Tools

This translation is older than the original page and might be outdated. See what has changed.



= Overview ===


Zabbix支持POSIX 正则表达式

There are two ways of using regular expressions in Zabbix: 在Zabbix中有两种方法使用正则表达式

  • manually entering a regular expression
  • 手动输入正则表达式
  • using a global regular expression created in Zabbix
  • 使用在Zabbix中创建的全局正则表达式

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. 你可以在受支持位置中手动输入正则表达式。请注意,表达式不能以@开头,因为该符号在Zabbix中用于引用全局正则表达式。

Global regular expressions


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: 创建全局正则表达式

  • Go to: Administration → General
  • 进入: 管理(Administration)→ 一般(General)
  • Select Regular expressions from the dropdown
  • 从下拉列表中选择正则表达式(Regular expressions)
  • Click on New regular expression
  • 点击新的正则表达式(New 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.

Regular expression support by location

LocationRegexp supportGlobal regexp supportComments
Macro functions
regsub() YesNo pattern parameter
Trigger functions
count() YesYespattern parameter if operator parameter is regexp or iregexp
logeventid()pattern parameter
Low-level discovery
YesYesFilter field
Web monitoring
YesNo Variables with a regex: prefix
Required string field
Zabbix agent items
eventlog[] YesYesregexp, severity, source, eventid parameters
log[] regexp parameter
logrt[] Yes/Noregexp parameter supports both, file_regexp parameter supports non-global expressions only
proc.cpu.util[] No cmdline parameter
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
SNMP traps
snmptrap[]YesYesregexp parameter
Icon mapping
YesYesExpression field