All Products
Search
Document Center

Enterprise Distributed Application Service:Create a custom webhook-based alert contact

Last Updated:Aug 16, 2023

When you create a notification policy, you can configure the alert notifications to be sent to a custom webhook URL. The Alert Management module of Application Real-Time Monitoring Service (ARMS) allows you to send webhook alert notifications to Lark, WeChat, and DingTalk groups. This topic describes how to create a custom webhook-based alert contact. Lark is used in this example.

Step 1: Obtain a webhook URL

  1. Open and log on to Lark.

  2. Click the + icon and then click New group to create a Lark group that is used to receive alert notifications.

  3. Click the Settings icon and then click the Bots tab.

  4. On the Bots tab, click Add Bot.

    飞书添加机器人
  5. In the Add Bot dialog box, click Add in the Custom Bot section.

    飞书-自定义机器人
  6. Set the Bot name and Description parameters and click Add.

    飞书-设置机器人
  7. Click Copy next to Webhook URL and then click Finish.

    飞书-Webhook

Step 2: Create a contact

  1. Log on to the EDAS console.

  2. In the left-side navigation pane, click Application Management > Applications. In the top navigation bar, select a region. In the upper part of the page, select a namespace. Select Container Service or Serverless Kubernetes Cluster from the Cluster Type drop-down list. Then, find the application that you want to deploy and click the application name.

  3. In the left-side navigation pane, choose Alert Management > Contact.

  4. On the Contact tab, click Create Webhook in the upper-right corner.

  5. In the Create Webhook dialog box, configure parameters as needed.

    The following table describes the parameters.

    Parameter

    Description

    Webhook Name

    Required. Specify a name of the webhook-based contact.

    Post or Get

    Required. Specify a request method and enter a URL. The URL can be up to 100 characters in length.

    In this example, select Post and paste the webhook URL that is saved in Step 1: Obtain a webhook URL to the field.

    Header or Param

    Optional. Specify a request header. The request header can be up to 200 characters in length. Click Create to add a header or a parameter. The default request header is Content-Type: text/plain; charset=UTF-8. The total number of headers and parameters can be up to 6.

    In this example, the following headers are used:

    • Arms-Content-Type : json

    • Content-Type : application/json

    Notification Template

    Optional. Specify the content that you want to send when the alert is triggered. This parameter appears only if you select Post as the request method. You can use the $content placeholder to specify the notification content. The content can be up to 500 characters in length. Specify a notification template in the following format:

    {
    "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 Triggered At":"{{ .startTime }}",
    "Alert Message":"{{ for .alerts }} {{ .annotations.message }} {{ end }}"
    }

    In this example, the following template is used:

    {
      "msg_type": "text",
      "content": {
        "text": "Alert Name: {{ .commonLabels.alertname }} \n Alert Triggered At: {{ .startTime }} \n Alert Message: {{ for .alerts }} {{ .annotations.message }}  {{if .generatorURL }} Link to Details: {{.generatorURL}} {{ end }} \n {{ end }}"
      }
    }

    Template to Clear Alerts

    Optional. Specify the content that you want to send when the alert is resolved. This parameter appears only if you select Post as the request method. You can use the $content placeholder to specify the notification content. The content can be up to 500 characters in length. Specify a notification template in the following format:

    {
    "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 Cleared At":"{{ .endTime }}",
    "Alert Content":"{{ for .alerts }} {{ .annotations.message }} {{ end }}"
    }

    In this example, the following template is used:

    {
      "msg_type": "text",
      "content": {
        "text": "Alert Name: {{ .commonLabels.alertname }} \n Alert Cleared At: {{ .endTime }} \n Alert Message: {{ for .alerts }} {{ .annotations.message }}  {{if .generatorURL }} Link to Details: {{.generatorURL}} {{ end }} \n {{ end }}"
      }
    }
  6. (Optional) Click Test to verify whether the configurations are valid.

  7. Click Create.

Step 3: Configure a notification policy

To use the custom webhook URL to receive alert notifications, you must set the Notification Methods parameter to WebHook on the Notification Policies page.

Create or modify a notification policy. On the Notification Objects tab, set the Contacts parameter to the webhook-based contact that you created, and set the Notification Methods parameter to Webhook. For more information, see Create and manage a notification policy.

Note

If no response is received within five seconds after a webhook-based alert notification is sent, the alert notification fails to be sent.