When you create a notification policy, you can specify that alert notifications are sent to a custom webhook URL. The Alert Management module of Application Real-Time Monitoring Service (ARMS) allows you to send alert notifications to contacts of specific instant messaging apps. This topic describes how to use a webhook to send notifications to Lark contacts.

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.
  4. In the Settings panel, click BOTs and then click Add Bot.
    Add a bot to a Lark group
  5. On the Add Bot page, select Custom Bot.
    Create a custom bot in Lark
  6. Configure the Bot name and Description parameters, and then click Add.
    Configure a custom bot in Lark
  7. Click Copy to the right of Webhook URL and then click Save.
    Copy a webhook URL in Lark

Step 2: Create an alert contact

  1. Log on to the ARMS console. In the left-side navigation pane, choose Alert Management > Notification Objects.
  2. In the Edit Contact Group dialog box, click the Webhook tab and then click Add Webhook.
  3. In the Create Webhook panel, configure the following parameters. The following table describes the parameters.
    ParameterDescription
    Webhook NameRequired. Enter a name for the webhook.
    Post or GetRequired. Specify a request method and enter a URL. The URL cannot exceed 256 characters in length.

    In this example, Post is selected, and the webhook URL that is copied in Step 1: Obtain a webhook URL is pasted.

    Header or ParamOptional. Specify a request header. The request header cannot exceed 200 characters in length. Click Add 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 cannot exceed six.
    In this example, the following headers are used:
    • Arms-Content-Type : json
    • Content-Type : application/json
    Notification TemplateOptional. Specify the content that you want to send when the alert is triggered. This parameter appears only if you select Post. You can use the $content placeholder to specify the notification content. The content cannot exceed 500 characters in length. For more information, see Configure a notification template and a webhook template.

    Specify the notification content 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 time":"{{ .startTime }}",
    "Notification content":"{{ for .alerts }} {{ .annotations.message }} {{ end }}"
    }
    In this example, the following template is used:
    {
      "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 }} \nNotification content: {{ for .alerts }} {{ .annotations.message }}\n {{ end }}"
      }
    }
    Template to Clear AlertsOptional. Specify the content that you want to send when the alert is resolved. This parameter appears only if you select Post. You can use the $content placeholder to specify the notification content. The content cannot exceed 500 characters in length. For more information, see Configure a notification template and a webhook template.

    Specify the notification content 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 }}",
    "Time when the alert is resolved":"{{ .endTime }}",
    "Notification content":"{{ for .alerts }} {{ .annotations.message }} {{ end }}"
    }
    In this example, the following template is used:
    {
      "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 }}Time when the alert is resolved: {{ .startTime }} \nNotification policy: {{ .dispatchRuleName }} \nNotification content: {{ for .alerts }} {{ .annotations.message }}\n {{ end }}"
      }
    }
  4. Optional:Click Test to verify whether the configurations are valid.
  5. Click OK.

Step 3: Set a notification policy

When you create or modify a notification policy, you can set the Notification Object parameter to Universal Webhook, and then select a webhook. For more information, see Create and manage a notification policy.

Note The timeout period for an alert notification that is sent by using a webhook is 5 seconds. If the webhook receives no response within 5 seconds after a notification is sent, the notification fails to be sent.