All Products
Search
Document Center

Managed Service for OpenTelemetry:Use a webhook to send custom alert notifications

Last Updated:Feb 26, 2025

When you create a notification policy, you can specify that alert notifications are sent to a custom webhook URL. Managed Service for OpenTelemetry supports sending webhook alerts to third-party notification endpoints. This topic uses Lark as an example to demonstrate how to use a webhook to send notifications.

Step 1: Obtain a webhook URL

Set up a Lark chatbot on your computer.

  1. Open Lark and log on.

  2. Click theicon, then select New group to establish a new group for alert sending.

  3. Click the group settings icon, and then click the BOTs tab.

  4. On the BOTs tab, click Add Bot.

    Lark add bot

  5. In the Add Bot dialog box, select Custom Bot.

    Lark custom bot

  6. Then, set the Bot name and Description, then click Add.Lark - Setting up a bot

  7. Click Copy next to Webhook URL and then click Save.Lark-Webhook

Step 2: Create a webhook

  1. Log on to the Managed Service for OpenTelemetry console.

  2. In the left-side navigation pane, choose Alert Management > Notification Objects. Then, on the Webhook Integration tab, click Create Webhook

  3. In the Create Webhook panel, configure the following parameters.

    Parameter

    Description

    Webhook Name

    Required. Enter a name for the webhook.

    Post or Get

    Required. Specify a request method. The URL cannot exceed 256 characters in length.

    In this example, select Post and paste the webhook URL saved in Step 1: Obtain a webhook URL into the text box on the right.

    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 params cannot exceed six.

    In this example, set the following two headers:

    • 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. 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 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 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 Alerts

    Optional. 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 was 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 was resolved: {{ .startTime }} \nNotification policy: {{ .dispatchRuleName }} \nNotification content: {{ for .alerts }} {{ .annotations.message }}\n {{ end }}"
      }
    }
  4. Click Send Test to verify whether the configurations are valid.

  5. Click OK.

Step 3: Configure a notification policy

When you create or modify a notification policy, set the Notification Object parameter to Universal Webhook and select the desired webhook.

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.