Simple Log Service provides the dynamic recipient feature. This feature allows you to configure dynamic recipients for alert notifications by using webhooks.
Scenarios
You can create users or user groups in the alerting system of Simple Log Service. Then, you can specify one or more users or user groups in an action policy as the recipients of alert notifications. However, this method cannot meet the requirements in special scenarios. Examples:
Connect to third-party user management systems: Specific enterprises have self-managed user management systems. In this case, the updates of user information in the user management systems cannot be synchronized to the alerting system of Simple Log Service in real time. The organization structure of an enterprise varies based on the users and user groups that are created in the enterprise. Therefore, the user model and the user group model that are provided by Simple Log Service are not applicable to all enterprises.
Send alert notifications to dynamic recipients: If your system has multiple services and alert notifications for each service need to be sent to different recipients, you must configure multiple action groups by using the dynamic distribution mechanism of action policies. This increases maintenance costs.
How it works
In the preceding scenarios, you can use the dynamic recipient feature to specify the recipients of alert notifications. If you use the dynamic recipient feature, you must specify a webhook URL. Before Simple Log Service sends an alert notification, Simple Log Service calls the webhook. Then, the webhook service returns information about the recipients of alert notification. This way, you do not need to maintain recipients in the alerting system of Simple Log Service.
Dynamic recipients
Static recipients
Configure dynamic recipients
When you create an action policy, set the Recipient Type parameter to Dynamic Recipient. Then, configure the other parameters. The following table describes the parameters. For more information, see Create an action policy.
Parameter | Description |
Recipient Type | Select Dynamic Recipient. |
Recipient Callback URL | Enter the webhook URL. For more information about webhook specifications, see Webhook specifications. The webhook URL has the following limits:
Important The webhook for dynamic recipients is called in the same manner as a webhook for alert notifications. If you want to configure access control for a webhook, you can configure an IP address whitelist or an HTTP request header. For more information, see How do I verify access permissions? |
Request Header | Enter the request header that must be added when Simple Log Service sends a request to the specified webhook URL. By default, the Content-Type: application/json request header is added. If you set the Content-Type parameter to a different value, the request header does not take effect. |
Webhook specifications
Request information
Request method: POST
Request header:
A custom request header.
Default request header: Content-Type: application/json.
Sample request:
The value of the alerts field is an array of alerts that are merged into a set. Up to 10 alerts can be included in an alert set. After your webhook service receives the request, the webhook service determines recipients based on the request and returns information about the recipients to Simple Log Service.
{ "alerts": [{ "alert_id": "test-alert-1", "alert_instance_id": "jid-2ed042ba079041c-a578-441e-8d25-42e92aef506c", "alert_name": "Test Alert 1", "alert_time": 1646808904, "alert_type": "sls_alert", "aliuid": "123****3424", "annotations": { "desc": "Test alert triggered", "title": "Test Title" }, "fire_results": [{ "message": "error occurs" }], "fire_results_count": 1, "fire_time": 1646808904, "labels": { "app": "nginx" }, "next_eval_interval": 60, "project": "demo-alert", "region": "cn-hangzhou", "resolve_time": 0, "severity": 8, "status": "firing" }] }
Response information
Status code: 200
Response header: The Content-Type: application/json response header must be included.
Sample response:
{ "receivers": [{ "code": "86", "phone": "137****34", "email": "****@example.com" }] }
Field
Type
Required
Description
code
string
No
If the response does not contain this field, Simple Log Service uses the default code 86.
phone
string
No
This field is valid only if you set the Notification Method parameter to SMS Message, Voice Call, DingTalk, or Enterprise WeChat. If you set the Notification Method parameter to Email, you can ignore this field.
email
string
No
This field is valid only if you set the Notification Method parameter to Email. If you set the Notification Method parameter to a different value, you can ignore this field.