When you create a notification policy, you can specify that alert notifications are sent to a custom webhook URL. Alibaba Cloud Managed Service for Prometheus 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.
Step 1: Obtain a webhook URL
Open and log on to Lark.
Click the + icon and then click Add Group to create a Lark group that is used to receive alert notifications.
Click the Settings icon on the right side of the Lark group, and then click the BOTs tab.
On the BOTs tab, click Add Bot.
In the Add Bot dialog box, click Add in the Custom Bot section.
Set the Bot name and Description parameters and click Add.
Click Copy next to Webhook URL and then click Save.
Step 2: Create a webhook
Log on to the Managed Service for Prometheus console. In the left-side navigation pane, choose .
In the Edit Contact Group dialog box, click the Webhook tab and then click Create Webhook. In the Create Webhook dialog box, configure the parameters. The following table describes the parameters.
Parameter
Description
Webhook Name
Enter a name for the webhook.
Request method
Specify a request method and enter an HTTP or HTTPS URL. The request method can be POST or GET., and the URL cannot exceed 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 and Param
Specify request headers and parameters. A maximum of 200 characters are supported.
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 6.In this example, set the following headers:
Arms-Content-Type : json
Content-Type : application/json
If you set Request Method to Post, you must configure the following parameters
Notification template
Specify the content that you want to send when an alert is triggered. 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 Triggered At: {{ .startTime }} \nAlert Message: {{ for .alerts }} {{ .annotations.message }}\n {{ end }}" } }
Template to Clear Alerts
Specify the content that you want to send when the alert is resolved. 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 }}", "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{{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 }}Alert Cleared At: {{ .startTime }} \nNotification Policy: {{ .dispatchRuleName }} \nAlert Message: {{ for .alerts }} {{ .annotations.message }}\n {{ end }}" } }
Optional: Click Test to verify whether the configurations are valid.
Click OK.
Step 3: Configure 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.
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.