警告を送信するための既存のメディアタイプに満足できない場合、別の方法があります。独自の方法で通知を処理するスクリプトを
作成することができます。
アラートスクリプトは Zabbix server 上で実行されます。これらのスクリプトはサーバのconfiguration file の
AlertScriptsPath 変数で定義されたディレクトリに配置されています。
以下はアラートスクリプトの例です。:
バージョン3.4以降、Zabbix は実行されたコマンドとスクリプトの終了コードをチェックします。終了コードが ** 0 **以外の終了コードは、
command execution エラーとみなされます。この場合、Zabbixは実行に失敗したコマンドを 再度実行しようとします。
環境変数はスクリプトのために保存も作成もされないので、明示的に処理する必要があります。
カスタムアラートスクリプトをメディアタイプとして設定するには:
Media type タブには、メディアタイプに関する一般的な属性が含まれています:
すべての必須入力フィールドには、赤いアスタリスクが表示されます。
以下のパラメータは、スクリプトメディアタイプに固有のものです:
パラメータ | 説明 |
---|---|
Script name | Enter the name of the script. |
Script parameters | Add command-line parameters to the script. {ALERT.SENDTO}, {ALERT.SUBJECT} and {ALERT.MESSAGE} macros are supported in script parameters. Customizing script parameters is supported since Zabbix 3.0. |
common media type parameters でデフォルトのメッセージとアラート処理オプションを設定する方法の詳細について説明します。
アラートスクリプトがデフォルトのメッセージを使用しない場合でも、このメディアタイプで使用される操作タイプ用の
メッセージテンプレートが定義されていなければなりません。そうでなければ、通知は送られません。
メディアタイプの並列処理は Zabbix 3.4.0 から実装されているため、複数のスクリプトメディアタイプが設定されている場合、これらの
スクリプトはアラータプロセスによって並行して処理される可能性があることに注意することが重要です。アラータプロセスの総数は、
StartAlerters parameter によって制限されます。
To test a configured script media type:
Locate the relevant script in the list of media types.
Click on Test in the last column of the list; a testing form will open in a pop-up window. The testing form will contain the same number of parameters that are configured for the script media type.
Edit the script parameter values if needed. Editing only affects the test procedure; the actual values will not be changed.
Click on Test.
When testing a configured script media type, {ALERT.SENDTO}, {ALERT.SUBJECT}, {ALERT.MESSAGE} and user macros will resolve to their values, but macros that are related to events (e.g., {HOST.HOST}, {ITEM.LASTVALUE}, etc.) will not resolve, as during testing there is no related event to get the details from. Note that macros within {ALERT.SUBJECT} and {ALERT.MESSAGE} macros will also not resolve. For example, if the value of {ALERT.SUBJECT} is composed of "Problem: {EVENT.NAME}" then the {EVENT.NAME} macro will not be resolved.
メディアタイプを設定したら、Administration → Users セクションで、ユーザープロファイルを編集して、このタイプのメディアを
ユーザーに割り当てます。ユーザーメディアの設定方法は、すべてのメディアタイプに共通なので、Media typesに記述されています。
ユーザーメディアを定義する場合、Send to フィールドを空にすることはできないことに注意してください。このフィールドを アラートスクリプトで使用しない場合は、検証要件を回避するために、サポートされている文字の任意の組み合わせを入力してください。