OpenTelemetry 向けマネージドサービスのアラート管理機能を使用すると、Webhook アラートをサードパーティの通知オブジェクトに送信できます。このトピックでは、Lark を例に、Webhook アラートの作成方法を説明します。
手順1:Webhook URL の取得
PC で Lark の Webhook ボットを設定します。
-
Lark を開き、ログインします。
-
[+] アイコンをクリックし、次に [グループを作成] をクリックしてアラートグループを作成します。
-
グループ設定アイコンをクリックし、[ボット] タブをクリックします。
-
[ボット] タブで、[ボットを追加] をクリックします。
-
[ボットを追加] パネルで、[カスタムボット] を選択します。
-
設定ページで、表示名と説明を設定し、[追加] をクリックします。
-
表示される確認パネルで [コピー] をクリックし、次に [完了] をクリックします。Webhook URL をコピーし、安全な場所に保管してください。この URL は公開しないでください。[セキュリティ設定] エリアで、[カスタムキーワード] チェックボックスを選択し、キーワードとして alert を追加して、[完了] をクリックします。
手順2:Webhook 通知オブジェクトの作成
OpenTelemetry 向けマネージドサービスコンソールにログインします。
-
左側のナビゲーションウィンドウで、 を選択します。[Webhook 連携] タブをクリックし、[Webhook の作成] をクリックします。
-
[Webhook の作成] ダイアログボックスで、次のパラメーターを設定します。
パラメーター
説明
Webhook 名
必須。Webhook のカスタム名。
Post または Get
必須。リクエストメソッド。URL は 256 文字以内にする必要があります。
この例では、[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 }}" } }アラート解決テンプレート
アラートが解決されたときに送信される通知のテンプレートです。このパラメーターは任意であり、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 }}", "Resolution 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 }}Resolution Time: {{ .endTime }} \nNotification Policy: {{ .dispatchRuleName }} \nResolved Alert Content: {{ for .alerts }} {{ .annotations.message }}\n {{ end }}" } } -
-
[テスト送信] をクリックして設定を検証します。
-
[OK] をクリックします。
手順3:通知ポリシーの設定
通知ポリシーを作成または編集し、通知オブジェクトを[ユニバーサル Webhook] に設定してから、対応する Webhook 連携を選択します。
ターゲットエンドポイントが 5 秒以内に応答しない場合、Webhook アラートはタイムアウトし、通知は失敗します。