This is a translation of the original English documentation page. Help us make it better.

1 使用例

概要

このセクションでは、保存前処理のステップを使用していくつかの実用的なタスクを実行する例を紹介します。

VMwareイベントログレコードのフィルタリング

この例では、保存前処理ステップの正規表現に一致を使用して、VMWareイベントログの不要なイベントをフィルタリングします。

1. 動作中のVMWare Hypervisorホストで、イベントログアイテムvmware.eventlogが存在し、正しく動作していることを確認します。ホストの作成時にVMWareテンプレートがリンクされている場合、イベントログアイテムはハイパーバイザー上に既に存在する可能性があることに注意してください。

2. VMWare Hypervisorホストで"ログ"タイプの依存アイテムを作成し、イベントログアイテムをマスターとして設定します。

3. 依存アイテムの"保存前処理"タブで、保存前処理ステップの"正規表現に一致"を選択し、たとえば、次のパラメーターのいずれかを指定します。

# すべてのログイベントをフィルターします。
       pattern: .* logged in .*
       
       # "User"の後にユーザー名を含む行をフィルターします。
       pattern: \bUser\s+\K\S+

正規表現に一致しない場合、依存アイテムはサポートされなくなり、対応するエラーメッセージが表示されます。 これを回避するには、"失敗時のカスタマイズ"チェックボックスをオンにし、値を破棄するかカスタム値を設定するなどのオプションを選択します。

または、保存前処理ステップの正規表現を使用して、一致するグループを抽出し、出力を制御することもできます。例:

# "logged in"を含むログイベント全体を抽出して出力します。
       pattern: .*logged in.*
       output: \0
       
       # "User"に続くユーザー名を抽出して出力します。
       pattern: User (.*?)(?=\ )
       output: \1

取得した値の型チェック

この例では、保存前処理ステップのカスタム乗数を使用して、取得したアイテムの値の型が数値かどうかを確認します。

アイテムの保存前処理タブで保存前処理ステップの"カスタム乗数"を選択し、次のパラメーターを設定します。

# 取得した値を1倍します。
       number: 1

保存前処理が失敗した場合(入力が数値でない場合など)、アイテムはサポートされなくなり、対応するエラーメッセージが表示されます。 これを回避するには、"失敗時のカスタマイズ"チェックボックスをオンにし、値を破棄するかカスタム値を設定するなどのオプションを選択します。

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)
    • 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.

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.