Configure a dynamic recipient

更新时间:
复制 MD 格式

You can use a webhook service to dynamically resolve alert notification recipients instead of maintaining recipient lists in Simple Log Service.

Use cases

You can create users or user groups in Simple Log Service and select them in an action policy to receive alert notifications. However, this approach may not suit all scenarios, such as:

  • Integrating with a third-party user management system: Some organizations use their own user management systems, and keeping user information synchronized in real time with Simple Log Service can be challenging. The user and user group models in Simple Log Service may not fully align with an organization's existing structure.

  • Notifying dynamic contacts: If your system has many services and each service requires alerts to be sent to different recipients, configuring separate branches in an action policy increases maintenance overhead.

How it works

With the dynamic recipient feature, you provide a webhook service that Simple Log Service calls when an alert is triggered. The webhook returns the recipients' contact information, so you do not need to maintain recipient lists in Simple Log Service.

  • Dynamic recipient

    image
  • Static recipient

    image

Configuration

In an action policy, set Recipient Type to Dynamic Recipient, and then configure the following parameters.

Parameter

Description

Recipient type

Select Dynamic Recipient.

Recipient callback URL

The URL of your webhook service. For more information, see API specification. The following limits apply:

  • The URL must be publicly accessible.

  • The API response latency cannot exceed 10 seconds.

  • The response body cannot exceed 2 KB.

  • The response status code must be 200.

  • If a call fails, Simple Log Service retries up to 3 times.

Important

The dynamic recipient webhook follows the same calling convention as a standard alert notification webhook. To control access, you can configure an IP address whitelist or custom HTTP headers. For more information, see Configure access control.

Request header

The request header included when Simple Log Service sends a request to the recipient callback URL.

By default, Simple Log Service adds the Content-Type: application/json request header. Setting Content-Type to a different value has no effect.

API specification

Request

  • Request method: POST

  • Request header:

    • Your custom request headers.

    • Default request header: Content-Type: application/json.

  • Sample request payload

    The alerts field is an array that contains up to 10 correlated alerts. For more information about the parameters, see Variables in alert templates (new). Your webhook service uses this data to determine the recipients and returns their contact information to Simple Log Service.

    {
      "alerts": [
        {
          "alert_id": "test-alert-1",                  // Unique ID of the alert
          "alert_instance_id": "jid-**********-a578-441e-8d25-42e92aef506c",  // instance ID
          "alert_name": "Test Alert 1",                // Alert rule name
          "alert_time": 1646808904,                    // Current evaluation time
          "alert_type": "sls_alert",                   // Alert type
          "aliuid": "123****3424",                     // Alibaba Cloud account ID
          // Annotations
          "annotations": {
            "desc": "Test alert triggered",            // Description
            "title": "Test Title"                      // Title
          },
          // The data entries that triggered the alert
          "fire_results": [                            
            {"message": "error occurs"}                
          ],
          "fire_results_count": 1,                     // Total number of data entries that triggered the alert
          "fire_time": 1646808904,                     // First trigger time
          // Labels
          "labels": {
            "app": "nginx",                            // Application tag
            "env": "prod",                             // Environment tag
            "team": "sre"                              // Responsible team
          },
          "next_eval_interval": 60,                    // Next evaluation interval (seconds)
          "project": "demo-alert",                     // The project to which the alert rule belongs
          "region": "cn-hangzhou",                     // region
          "resolve_time": 0,                           // Time when the alert was resolved. The value is 0 if the alert status is 'firing', or the actual resolution time if the alert status is 'resolved'.
          "severity": 8,                               // alert severity (10: Critical, 8: High, 6: Medium, 4: Low, 2: Report-Only)
          "status": "firing"                           // alert status ('firing': triggered, 'resolved': recovery notification)
        }
      ]
    }

Response

  • Status code: 200

  • Response header: Must include Content-Type: application/json.

  • Response body example:

    {
        "receivers": [{
            "code": "86",
            "phone": "137****34",
            "email": "****@example.com"
        }]
    }

    Parameter

    Type

    Required

    Description

    code

    string

    No

    The country calling code. Defaults to 86 if omitted.

    phone

    string

    No

    Used for SMS, voice, DingTalk, and Enterprise WeChat notifications. Not required for email notifications.

    email

    string

    No

    Used only for email notifications. Not required for other channels.