通知ポリシーを作成する際に、カスタム Webhook URL にアラート通知を送信できます。アラート管理機能を使用すると、Webhook 統合を介してサードパーティのサービスにアラートを送信できます。このトピックでは、Lark を例として、アラート用の Webhook を作成および設定する方法を説明します。
ステップ 1:Webhook URL の取得
-
Lark を開き、ログインします。
-
[+] アイコンをクリックし、[Create Group] をクリックしてアラート受信用のグループを作成します。
-
グループ設定アイコンをクリックし、[Bots] タブをクリックします。
-
[Bots] タブで、[Add Bot] をクリックします。
-
[Add Bot] パネルで、[Custom Bot] を選択します。
-
設定ページで [Display name] と [Description] を設定し、[Add] をクリックします。
-
[Webhook URL] セクションで [Copy Link] をクリックし、[Finish] をクリックします。
[Security Settings] セクションで、[Custom Keywords] チェックボックスにチェックを入れ、キーワード
alertを追加します。
ステップ 2:Webhook 統合の作成
にログインします。 Prometheusコンソールのマネージドサービス。 左側のナビゲーションウィンドウで、 を選択します。
-
[Webhook 統合] タブをクリックし、右上隅の [Webhook の作成] をクリックして、[Webhook の作成] パネルで次のパラメーターを設定します。
パラメーター
説明
[Webhook 名]
Webhook のカスタム名を入力します。
リクエストメソッド
リクエストメソッド (POST または GET) を選択し、http:// または https:// で始まる URL を入力します。URL は 100 文字以内です。
この例では、POST を選択し、「ステップ 1:Webhook URL の取得」で取得した Webhook URL を右側のテキストボックスに貼り付けます。
ヘッダー、パラメーター
リクエストヘッダーとパラメーターを設定します。各ヘッダーとパラメーターは 200 文字以内です。
[+ 追加] をクリックして、ヘッダーまたはパラメーター情報を追加します。デフォルトのリクエストヘッダーは
Content-Type: text/plain; charset=UTF-8です。ヘッダーとパラメーターの合計は 6 個までです。この例では、次の 2 つのヘッダーを設定します。
-
Arms-Content-Type: json
-
Content-Type: application/json
リクエストメソッドとして POST を選択した場合は、次のパラメーターも設定する必要があります。
[通知テンプレート]
アラートがトリガーされた際の通知テンプレートです。$content プレースホルダーを使用して通知コンテンツを出力できます。テンプレートは 500 文字以内です。詳細については、「通知テンプレートと Webhook テンプレートの設定」をご参照ください。
以下は通知テンプレートのサンプルです。
{ "Alert name":"{{ .commonLabels.alertname }}{{if .commonLabels.clustername }}", "Cluster name":"{{ .commonLabels.clustername }} {{ end }}{{if eq "app" .commonLabels._aliyun_arms_involvedObject_kind }}", "Application name":"{{ .commonLabels._aliyun_arms_involvedObject_name }} {{ end }}", "Notification policy":"{{ .dispatchRuleName }}", "Alert time":"{{ .startTime }}", "Alert content":"{{ for .alerts }} {{ .annotations.message }} {{ end }}" }Lark の例では、テキスト形式を次のように設定できます。
{ "msg_type": "text", "content": { "text": "Alert name: {{ .commonLabels.alertname }}\n{{if .commonLabels.clustername }}Cluster name: {{ .commonLabels.clustername }}\n{{ end }}{{if eq "app" .commonLabels._aliyun_arms_involvedObject_kind }}Application name: {{ .commonLabels._aliyun_arms_involvedObject_name }}\n{{ end }}Notification policy: {{ .dispatchRuleName }} \nAlert time: {{ .startTime }} \nAlert content: {{ for .alerts }} {{ .annotations.message }}\n {{ end }}" } }[復旧テンプレート]
アラートが解決されたときに送信される通知のテンプレートです。$content プレースホルダーを使用して通知コンテンツを出力できます。テンプレートは 500 文字以内です。詳細については、「通知テンプレートと Webhook テンプレートの設定」をご参照ください。
以下はサンプルです。
{ "Alert name":"{{ .commonLabels.alertname }}{{if .commonLabels.clustername }}", "Cluster name":"{{ .commonLabels.clustername }} {{ end }}{{if eq "app" .commonLabels._aliyun_arms_involvedObject_kind }}", "Application name":"{{ .commonLabels._aliyun_arms_involvedObject_name }} {{ end }}", "Notification policy":"{{ .dispatchRuleName }}", "Recovery time":"{{ .endTime }}", "Alert content":"{{ for .alerts }} {{ .annotations.message }} {{ end }}" }Lark の例では、テキスト形式を次のように設定できます。
{ "msg_type": "text", "content": { "text": "Alert name: {{ .commonLabels.alertname }}\n{{if .commonLabels.clustername }}Cluster name: {{ .commonLabels.clustername }}\n{{ end }}{{if eq "app" .commonLabels._aliyun_arms_involvedObject_kind }}Application name: {{ .commonLabels._aliyun_arms_involvedObject_name }}\n{{ end }}Recovery time: {{ .endTime }} \nNotification policy: {{ .dispatchRuleName }} \nResolved alert content: {{ for .alerts }} {{ .annotations.message }}\n {{ end }}" } } -
-
(オプション) [テスト] をクリックして設定を検証します。
-
[OK] をクリックします。
ステップ 3:通知ポリシーの設定
通知ポリシーを作成または編集します。[通知オブジェクト] で [汎用 Webhook] を選択し、作成した Webhook 統合を選択します。詳細については、「通知ポリシー」をご参照ください。
Webhook リクエストのタイムアウトは 5 秒です。この時間内にエンドポイントが応答しない場合、通知の配信は失敗します。