这是原厂英文文档的翻译页面. 欢迎帮助我们 完善文档.

3 预处理示例

概述

本节介绍使用预处理步骤完成一些实际任务的示例。

过滤VMware事件日志记录

使用正则表达式预处理过滤 VMWare 事件日志的不必要事件。

1. 在工作的 VMWare Hypervisor 主机上,检查事件日志项 vmware.eventlog[<url>,<mode>] 是否存在并且工作正常。 请注意,如果在主机创建期间已链接 Template VM VMWare 模板,则事件日志项可能已经存在于管理程序上。

2. 在 VMWare Hypervisor 主机上创建一个“日志”类型的 依赖项 并将事件日志项设置为其主项。

在依赖项的“预处理”选项卡中,选择“匹配正则表达式”验证选项和填充模式,例如:

".* logged in .*" - 过滤事件日志中的所有日志事件
       "\bUser\s+\K\S+" -  只筛选事件日志中带有用户名的行

如果正则表达式不匹配,则依赖项变得不受支持,并显示相应的错误消息。为了避免这种情况,请选中“失败时自定义”复选框并选择丢弃不匹配的值。

另一种允许使用匹配组和输出控制的方法是在“预处理”选项卡中选择“正则表达式”选项并设置参数,例如:

pattern: ".*logged in.*", output: "\0" - 过滤事件日志中的每行日志事件
       pattern "User (.*?)(?=\ )", output: "\1" - 仅截取事件日志中筛选用户名信息

Checking retrieved value type

This example uses the Custom multiplier preprocessing step to check if the retrieved item value type is numeric.

In the Preprocessing tab of an item, select the "Custom multiplier" preprocessing step and set the following parameter:

# Multiplies the retrieved value by 1:
       number: 1

If preprocessing fails (e.g., input is not numeric), then the item becomes unsupported with a corresponding error message. To avoid this, mark the "Custom on fail" checkbox and select an option such as discarding the value or setting a custom one.

Checking for not supported value

This example uses the Check for not supported value preprocessing step to check if the item value could not be retrieved.

When a Zabbix server/proxy poller process attempts to collect an item value, it may:

  • Return a valid result.
  • Return a result that initially seems valid but may become unsupported later (e.g., due to a value type mismatch after preprocessing).
  • Return an error of collecting the value, causing the item to become unsupported. Common causes include:
    • Unknown item key (for Zabbix agent, Simple check, or Zabbix internal items)
    • Unknown OID (SNMP agent), unknown sensor (IPMI agent), or no JMX metric (JMX agent)
    • Cannot read trap file (SNMP trap)
    • Script not found (External check)
    • No such URL (HTTP agent, Browser)
    • Login failed (SSH agent, TELNET agent)
    • Invalid formula syntax (Calculated), JavaScript syntax error (Script), or invalid SQL (Database monitor)

To detect and handle errors of collecting item values, you can use the Check for not supported value preprocessing step. Note that this step is always executed first and only detects errors that occur before preprocessing begins.

In the Preprocessing tab of an item, select the Check for not supported value preprocessing step and specify one of the following parameters:

  • For any errors:
Parameter: any error
  • For errors containing "cannot connect":
Parameter: error matches
       pattern: (?i)cannot connect

Then, use the Custom on fail option to discard the value (in this case, the error), set a custom value, or return a custom error message. Please note that discarded values are not stored in the database; as a result, triggers are not evaluated and trend data is not generated.