通知ポリシーを作成する際に、カスタム Webhook URL にアラート通知を送信できます。Application Real-Time Monitoring Service (ARMS) のアラート管理機能を使用すると、Webhook を介してサードパーティサービスにアラートを送信できます。このトピックでは、Lark を例に、これらの通知を受信するための Webhook の設定方法を説明します。
ステップ 1:Lark の Webhook URL の取得
Lark デスクトップクライアントから Lark の Webhook ボットを設定します。
Lark を開き、ログインします。
[+] アイコンをクリックし、次に [新しいグループ] をクリックして、アラートを受信するためのグループを作成します。
グループ設定アイコンをクリックし、次に [ボット] タブをクリックします。
[ボット] タブで、[ボットを追加] をクリックします。
[ボットを追加] パネルで、[カスタムボット] を選択します。
設定ページで、[ボット名] と [説明] を設定し、追加 をクリックします。
表示された セクションで、コピー をクリックして Webhook URL を保存し、次に 完了 をクリックします。
[セキュリティ設定] セクションで、[カスタムキーワード] チェックボックスを選択し、テキストボックスにキーワード「alert」を入力します。
ステップ 2:Webhook の作成
-
ARMS コンソールにログインします。左側のナビゲーションウィンドウで、 を選択します。
Webhook の統合 タブをクリックし、次に webhook の新規作成 をクリックします。
webhook の新規作成 ダイアログボックスで、次のパラメーターを設定します。
パラメーター
説明
Webhook 名
必須。Webhook のカスタム名。
Post/Get
必須。HTTP メソッド。URL は 256 文字を超えることはできません。
この例では、[Post] を選択し、「ステップ 1:Lark の 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 }}" } }アラート解消時のテンプレート
任意。アラートが解消されたときに送信される通知のテンプレートです。このパラメーターは 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 }}", "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: {{ .startTime }} \nNotification Policy: {{ .dispatchRuleName }} \nCleared Alert Content: {{ for .alerts }} {{ .annotations.message }}\n {{ end }}" } }任意: テストの送信 をクリックして設定を検証します。
確定する をクリックします。
ステップ 3:通知ポリシーの設定
通知ポリシーを作成または編集します。通知対象 を [ユニバーサル Webhook] に設定し、作成した Webhook を選択します。詳細については、「通知ポリシー」をご参照ください。
Webhook リクエストは、5 秒以内に応答が受信されない場合、タイムアウトして通知が失敗します。