このセクションでは、保存前処理のステップを使用していくつかの実用的なタスクを実行する例を紹介します。
この例では、保存前処理ステップの正規表現に一致を使用して、VMWareイベントログの不要なイベントをフィルタリングします。
1. 動作中のVMWare Hypervisorホストで、イベントログアイテムvmware.eventlogが存在し、正しく動作していることを確認します。ホストの作成時にVMWareテンプレートがリンクされている場合、イベントログアイテムはハイパーバイザー上に既に存在する可能性があることに注意してください。
2. VMWare Hypervisorホストで"ログ"タイプの依存アイテムを作成し、イベントログアイテムをマスターとして設定します。
3. 依存アイテムの"保存前処理"タブで、保存前処理ステップの"正規表現に一致"を選択し、たとえば、次のパラメーターのいずれかを指定します。
# すべてのログイベントをフィルターします。
pattern: .* logged in .*
# "User"の後にユーザー名を含む行をフィルターします。
pattern: \bUser\s+\K\S+
正規表現に一致しない場合、依存アイテムはサポートされなくなり、対応するエラーメッセージが表示されます。 これを回避するには、"失敗時のカスタマイズ"チェックボックスをオンにし、値を破棄するかカスタム値を設定するなどのオプションを選択します。
または、保存前処理ステップの[正規表現]((/manual/config/items/preprocessing#regexp)を使用して、一致するグループを抽出し、出力を制御することもできます。例:
# "logged in"を含むログイベント全体を抽出して出力します。
pattern: .*logged in.*
output: \0
# "User"に続くユーザー名を抽出して出力します。
pattern: User (.*?)(?=\ )
output: \1
この例では、保存前処理ステップのカスタム乗数を使用して、取得したアイテムの値の型が数値かどうかを確認します。
アイテムの保存前処理タブで保存前処理ステップの"カスタム乗数"を選択し、次のパラメーターを設定します。
保存前処理が失敗した場合(入力が数値でない場合など)、アイテムはサポートされなくなり、対応するエラーメッセージが表示されます。 これを回避するには、"失敗時のカスタマイズ"チェックボックスをオンにし、値を破棄するかカスタム値を設定するなどのオプションを選択します。
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:
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:
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.