[comment]: # translation:outdated

[comment]: # ({56bf7160-56bf7160})
# 4 Webhook

[comment]: # ({/56bf7160-56bf7160})

[comment]: # ({6584b266-6584b266})
#### 概要

webhook メディアタイプは、ヘルプデスクシステム、チャット、メッセンジャーなどの外部ソフトウェアと簡単に統合するために、<br>
カスタム JavaScript コードを使用して HTTP コールを行うのに便利です。Zabbix が提供する統合機能をインポートするか、<br>
カスタム統合機能を一から作成することができます。

[comment]: # ({/6584b266-6584b266})

[comment]: # ({9b538128-27a06b1f})
#### インテグレーション

以下のインテグレーションを利用することで、定義済みの Webhook メディアタイプを使用して Zabbix 通知をプッシュすることができます:

-   [brevis.one](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/brevis.one/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Discord](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/discord/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Express.ms
    messenger](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/express.ms/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Github
    issues](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/github/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [GLPi](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/glpi/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [iLert](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/ilert/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [iTop](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/itop/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Jira](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/jira/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Jira Service
    Desk](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/jira_servicedesk/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [ManageEngine
    ServiceDesk](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/manageengine_servicedesk/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Mattermost](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/mattermost/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Microsoft
    Teams](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/msteams/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Opsgenie](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/opsgenie/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [OTRS](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/otrs/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Pagerduty](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/pagerduty/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Pushover](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/pushover/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Redmine](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/redmine/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Rocket.Chat](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/rocketchat/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [ServiceNow](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/servicenow/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [SIGNL4](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/signl4/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Slack](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/slack/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [SolarWinds](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/solarwinds/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [SysAid](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/sysaid/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Telegram](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/telegram/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [TOPdesk](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/topdesk/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [VictorOps](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/victorops/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Zammad](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/zammad/README.md?at=refs%2Fheads%2Frelease%2F6.0)
-   [Zendesk](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/media/zendesk/README.md?at=refs%2Fheads%2Frelease%2F6.0)

::: notetip
ここに挙げたサービスに加え、Zabbix は **Spiceworks** と連携することができます。(Webhookは不要です)
Zabbixの通知をSpiceworksのチケットに変換するには、[email media type](/manual/config/notifications/media/email)を作成し、Spiceworksヘルプデスクのメールアドレス<br>
(例: help@zabbix.on.spiceworks.com) を指定したZabbixのプロファイル設定に入力する必要があります。
:::

[comment]: # ({/9b538128-27a06b1f})

[comment]: # ({2ae42569-d84f1038})
#### 構成

Webhook 連携の利用を開始するには:

1.  ダウンロードしたZabbixのtemplates/media`ディレクトリにある必要な.xmlファイルを見つけるか、Zabbix [git
    repository](https://git.zabbix.com/projects/ZBX/repos/zabbix/browse)からダウンロードしてください。 
2.  ファイルを Zabbix のインストールに[Import](/manual/xml_export_import/media#importing) します。メディアタイプのリストに
    Webhookが表示されます。
3.  *Readme.md*ファイルの指示に従ってWebhookを設定します(上記のWebhookの名前をクリックすると、
    *Readme.md*にすぐにアクセスできます)

カスタムWebhookをゼロから作成する場合:

-   *Administration → Media types* に進みます。
-   *Create media type* をクリックします。

**Media type** タブには、そのメディアタイプに固有のさまざまな属性が含まれています:

![](../../../../../assets/en/manual/config/notifications/media/media_webhook_express.png)

すべての必須入力フィールドには、赤いアスタリスクが表示されます。

以下のパラメータは、webhook メディアタイプに固有のものです:

|パラメータ|説明|
|---------|-----------|
|*Parameters*|Specify the webhook variables as the attribute and value pairs.<br>For preconfigured webhooks, a list of parameters varies, depending on the service. Check the webhook's *Readme.md* file for parameter description.<br>For new webhooks, several common variables are included by default (URL:<empty>, HTTPProxy:<empty>, To:{ALERT.SENDTO}, Subject:{ALERT.SUBJECT}, <Message:%7BALERT.MESSAGE>}), feel free to keep or remove them.<br>All [macros](/manual/appendix/macros/supported_by_location) that are supported in problem notifications are supported in the parameters.<br>If you specify an HTTP proxy, the field supports the same functionality as in the item configuration [HTTP proxy](/manual/config/items/itemtypes/http#configuration) field. The proxy string may be prefixed with `[scheme]://` to specify which kind of proxy is used (e.g. https, socks4, socks5; see [documentation](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html)).|
|*Script*|Enter JavaScript code in the block that appears when clicking in the parameter field (or on the view/edit button next to it). This code will perform the webhook operation.<br>The script is a function code that accepts parameter - value pairs. The values should be converted into JSON objects using JSON.parse() method, for example: `var params = JSON.parse(value);`.<br><br>The code has access to all parameters, it may perform HTTP GET, POST, PUT and DELETE requests and has control over HTTP headers and request body.<br>The script must contain a return operator, otherwise it will not be valid. It may return OK status along with an optional list of tags and tag values (see *Process tags* option) or an error string.<br><br>Note, that the script is executed only after an alert is created. If the script is configured to return and process tags, these tags will not get resolved in {EVENT.TAGS} and {EVENT.RECOVERY.TAGS} macros in the initial problem message and recovery messages because the script has not had the time to run yet.<br><br>See also: [Webhook development guidelines](https://www.zabbix.com/documentation/guidelines/en/webhooks), [Webhook script examples](/manual/config/notifications/media/webhook/webhook_examples), [Additional JavaScript objects](/manual/config/items/preprocessing/javascript/javascript_objects).<br>|
|*Timeout*|JavaScript execution timeout (1-60s, default 30s).<br>Time suffixes are supported, e.g. 30s, 1m.|
|*Process tags*|Mark the checkbox to process returned JSON property values as tags. These tags are added to the already existing (if any) problem event tags in Zabbix.<br>If a webhook uses tags (the Process tags checkbox is marked), the webhook should always return a JSON object containing at least an empty object for tags:`var result = {tags: {}};`.<br>Examples of tags that can be returned: *Jira ID: PROD-1234*, *Responsible: John Smith*, *Processed:<no value>*, etc.|
|*Include event menu entry*|Mark the checkbox to include an entry in the [event menu](/manual/web_interface/frontend_sections/monitoring/problems#event_menu) linking to the created external ticket.<br>If marked, the webhook should not be used to send notifications to different users (consider creating a [dedicated user](/manual/config/notifications/media/webhook#user_media) instead) or in several alert actions [related to a single problem event](/manual/config/notifications/media/webhook#configuring_alert_actions).|
|*Menu entry name*|Specify the menu entry name.<br>{EVENT.TAGS.<tag name>} macro is supported.<br>This field is only mandatory if *Include event menu entry* is selected.|
|*Menu entry URL*|Specify the underlying URL of the menu entry.<br>{EVENT.TAGS.<tag name>} macro is supported.<br>This field is only mandatory if *Include event menu entry* is selected.|

デフォルトのメッセージとアラート処理オプションを設定する方法の詳細については [common media type parameters](/manual/config/notifications/media#common_parameters) を参照してください。

::: notewarning
Webhook がデフォルトメッセージを使用しない場合でも、この Webhook が使用する操作タイプ用のメッセージテンプレートは<br>
定義されている必要があります。
:::

[comment]: # ({/2ae42569-d84f1038})

[comment]: # ({1e1fb343-e5e73ea8})

#### メディアタイプのテスト

設定済みのWebhookメディアタイプをテストするには：

1. メディアタイプの[リスト](/manual/config/notifications/media#overview)から該当するWebhookを見つけます。
2. リストの最後の列にある*テスト*をクリックします（テストウィンドウが開きます）。
3. 必要に応じてWebhookパラメータの値を編集します。マクロは例の値に置き換えてください。そうしないとマクロが解決されず、テストが失敗します。
4. *テスト*をクリックします。

テストウィンドウで値を置き換えたり削除したりしても、テスト手順のみに影響し、実際のWebhook属性値は変更されません。

![](../../../../../../assets/en/manual/config/webhook_test1.png){width="600"}

テストウィンドウを離れずにメディアタイプのテストログエントリを表示するには、*ログを開く*をクリックします（新しいポップアップウィンドウが開きます）

![](../../../../../assets/en/manual/config/mediatype_test2.png){width="600"}

[comment]: # ({/1e1fb343-e5e73ea8})

[comment]: # ({307f8831-b2974109})
##### Webhookテストが成功した場合

-   *"Media type test successful. "* のメッセージが表示されます。
-   灰色の *Response* フィールドにサーバーの応答が表示されます。
-   レスポンスの種類（JSONまたはString）は、*Response* フィールドの下に表示されます。

[comment]: # ({/307f8831-b2974109})

[comment]: # ({fc3db87a-abfbc807})
** Webhook テストが失敗した場合: **

-   *"Media type test failed. "* というメッセージが表示され、その後に失敗の詳細が表示されます。

[comment]: # ({/fc3db87a-abfbc807})

[comment]: # ({7bd932da-6eeec89a})
#### ユーザーメディア

メディアタイプを設定したら、*Administration → Users* セクションで、Webhook メディアを既存のユーザーに割り当てるか、<br>
Webhook を表すユーザーを新規に作成します。既存のユーザーにユーザーメディアを設定する手順は、すべてのメディアタイプに<br>
共通なので、[Media types](/manual/config/notifications/media#user_media) ページで説明されています。

Webhook がタグを使用して ticket \\メッセージ ID を格納する場合、同じ Webhook を異なるユーザーにメディアとして割り当てることは<br>
避けてください。エラーの原因となる可能性があります。（*Include event menu entry* optionを利用するウェブフックの大部分に<br>
適用されます）この場合、ベストプラクティスは、Webhook を代表する専用のユーザを作成することです:

1.  Webhook メディアタイプの設定後、*Administration → Users*　セクションに移動し、Webhook専用のZabbixユーザ
    (例：Slack Webhook用のユーザ名 *Slack* )を作成します。このユーザは Zabbix にログインしないため、メディア以外の設定は
    すべてデフォルトのままでよいです。
2.  ユーザプロファイルの *Media* タブで、必要な連絡先情報を入力し、[add a webhook](/manual/config/notifications/media#user_media)を行います。
    Webhookが*Send to*フィールドを使用しない場合、検証要件を回避するためにサポートされている文字の任意の組み合わせを入力します。
3.  このユーザーに、アラートを送信するすべてのホストに対する少なくとも読み取り [permissions](/manual/config/users_and_usergroups/permissions#permissions_to_host_groups)を許可します。

アラートアクションの設定時に、操作の詳細の *Send to users*フィールドにこのユーザを追加することで、Zabbix にこのアクションからの<br>
通知にWebhookを使用するよう指示します。

アラートアクションを設定する際、操作の詳細の *Send to users* フィールドにこのユーザーを追加します。これにより、<bnr>
このアクションからの通知に Webhook を使用するようZabbix に指示します。

[comment]: # ({/7bd932da-6eeec89a})

[comment]: # ({ac89791d-ac89791d})
#### アラートアクションの設定

アクションは、どの通知を Webhook 経由で送信するかを決定します。
[configuring actions](/manual/config/notifications/action)の手順は以下の通りです。
Webhook を含む他のすべてのメディアタイプの場合と同じですが、以下の例外があります:

-   Webhook が ticket\\message ID を保存し、update\\resolve 操作でフォローアップするためにタグを使用する場合、
    この Webhook は単一の問題イベントに対する複数の警告アクションで使用されるべきではないです。
    {EVENT.TAGS.<name>} が既に存在し、Webhook で更新される場合、その結果の値は定義されません。このような場合、
    更新された値を保存するために、Webhook で新しいタグ名を使用する必要があります。これは、Zabbix が提供する Jira、
    Jira Service Desk、Mattermost、Opsgenie、OTRS、Redmine、ServiceNow、Slack、Zammad、Zendesk Webhookと、
    *Include event menu entry* オプションを利用する Webhook の大部分に適用されます。複数の操作で Webhook を
    使用することは可能です。これらの操作またはエスカレーションステップが同じアクションに属している場合、Webhook を
    複数の操作で使用することができます。また、フィルタ条件が異なるため、同じ問題イベントにアクションが適用されない場合、
    異なるアクションでこの Webhook を使用することもできます。
-   [internal events](/manual/config/events/sources#internal_events) アクションでWebhookを使用する場合：
    アクションの動作設定で、*Custom message*チェックボックスをチェックし、カスタムメッセージを定義します。
    さもないと、通知が送信されません。

[comment]: # ({/ac89791d-ac89791d})
