Skip to main content

Regular expression

The regular expression (regex) mapping serves as a dynamic replacement tool, similar to a lookup table, but leverages the flexibility of regular expressions to define complex matching and replacement rules. The attributes that need to be set in a regex mapping are:

Configuration Attributes for Regex Mapping

AttributeRequired (Y/N)Description
fromYSpecifies the field name from which data is mapped.
toYSpecifies the field name to which data is mapped.
precedenceNDetermines the order in which mappings are applied.
Function typeYMust be set to "String functions" to use regex capabilities.
functionYSet to "regular expression" to enable regex-based mapping.
RegexYDefines the regular expression used for matching patterns within the field. Mode modifiers: Optional modifiers that adjust the behavior of the regex, such as (?s) to make the dot match newline characters.
Replacement stringNDefines the replacement string or format based on capture groups; defaults to the first capture group if unspecified.

Advanced Options

  • Value Map: A regex mapping can include a nested value map, utilizing the capture groups ($n$) defined in the Regex attribute for detailed replacements in the "Replacement string".
  • Capture Groups in to and from Fields: If capture groups are used in the from and to fields, the "Replacement string" can be adjusted to reference these using $n# to avoid confusion with capture groups from the regex pattern itself.

Example Application

Consider the scenario where the Zabbix API outputs a field with value vfs.fs.size[/,free] that you need to parse for monitoring disk space. Using regex mapping, this value can be split into two different fields:

  • /metric/type: Extracted to represent the metric type, such as "disk_free".
  • /ci/element: Used to capture specific filesystem elements, such as "/".