= 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.表达式选项卡允许设置正则表达式名称和添加子表达式。

概述 - 图1

参数 说明
名称(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.

概述 - 图2

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
iregsub()
Trigger functions
count() YesYespattern parameter if operator parameter is regexp or iregexp
logeventid()pattern parameter
iregexp()
regexp()
Low-level discovery
YesYesFilter field
Web monitoring
YesNo Variables with a regex: prefixRequired string field
Zabbix agent items
eventlog[] YesYesregexp, severity, source, eventid parameters
log[] regexp parameter
log.count[]
logrt[] Yes/Noregexp 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[]YesYesregexp parameter
Icon mapping
YesYesExpression field