> ## Documentation Index
> Fetch the complete documentation index at: https://docs.flashcat.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Dynamic Assignment

> Implement dynamic alert assignment based on labels, integrating with your custom systems

## Use Cases

<Note>
  Alert responders are maintained in the source monitoring system and frequently adjusted; you want to sync them to Flashduty On-call in real-time.
</Note>

<AccordionGroup>
  <Accordion title="Scenario 1: Big Data Task System">
    Customer A has a self-developed big data task system where internal personnel can create various data batch processing tasks. Each task can specify a primary responder and secondary responder. When a batch processing task fails, the system will first notify the primary responder. If the alert is not resolved after 30 minutes, it escalates to the secondary responder.
  </Accordion>

  <Accordion title="Scenario 2: Zabbix Host Monitoring">
    Customer B uses Zabbix for host monitoring and has set a responsible person tag for each host. They want host alerts to notify the corresponding responder based on this tag.
  </Accordion>

  <Accordion title="Scenario 3: Self-developed Monitoring System">
    Customer C has a self-developed monitoring system with many alert policies. Each policy is configured to notify a specific WeCom group. The customer has decided to migrate incident response to Flashduty but wants to maintain the policy-to-WeCom-group relationships from the source monitoring system and dynamically route alerts to WeCom groups based on these relationships.
  </Accordion>
</AccordionGroup>

## Implementation

Add specific labels or query parameters to override assignment targets in Flashduty On-call, enabling dynamic assignment.

<Tabs>
  <Tab title="Replace Responders">
    | Configuration          | Description                                                                                                                                                                 |
    | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | **Parameter Name**     | Must match regex: `^layer_person_reset_(\d)_emails$`, level numbers start from 0. For example, `layer_person_reset_0_emails` replaces responders in escalation rule level 1 |
    | **Parameter Value**    | Responder email addresses, multiple addresses separated by `,`. For example, `zhangsan@flashcat.cloud,lisi@flashcat.cloud` replaces responders with Zhang San and Li Si     |
    | **Parameter Location** | Query parameter or label value. For example, set this label in Nightingale alerts, or auto-generate labels through label enhancement                                        |
  </Tab>

  <Tab title="Replace Teams">
    | Configuration          | Description                                                                                                                                                                    |
    | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
    | **Parameter Name**     | Must match regex: `^layer_person_reset_(\d)_team_names$`, level numbers start from 0. For example, `layer_person_reset_0_team_names` replaces teams in escalation rule level 1 |
    | **Parameter Value**    | Team names, multiple teams separated by `,`. For example, `Team A,Team B` replaces teams with Team A and Team B                                                                |
    | **Parameter Location** | Query parameter or label value. For example, set this label in Nightingale alerts, or auto-generate labels through label enhancement                                           |
  </Tab>

  <Tab title="Replace WeCom Group Bot">
    | Configuration          | Description                                                                                                                                                                        |
    | ---------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | **Parameter Name**     | Must match regex: `^layer_webhook_reset_(\d)_wecoms$`, level numbers start from 0. For example, `layer_webhook_reset_0_wecoms` replaces WeCom group bot in escalation rule level 1 |
    | **Parameter Value**    | Target group bot token, multiple tokens separated by `,`. For example, `bbb025a0-e2e8-4b79-939d-82c91a275b06` replaces the group bot with the bot corresponding to this token      |
    | **Parameter Location** | Query parameter or label value. For example, set this label in Nightingale alerts, or auto-generate labels through label enhancement                                               |
  </Tab>

  <Tab title="Replace Dingtalk Group Bot">
    | Configuration          | Description                                                                                                                                                                                 |
    | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | **Parameter Name**     | Must match regex: `^layer_webhook_reset_(\d)_dingtalks$`, level numbers start from 0. For example, `layer_webhook_reset_0_dingtalks` replaces Dingtalk group bot in escalation rule level 1 |
    | **Parameter Value**    | Target group bot token, multiple tokens separated by `,`. For example, `bbb025a0-e2e8-4b79-939d-82c91a275b06` replaces the group bot with the bot corresponding to this token               |
    | **Parameter Location** | Query parameter or label value. For example, set this label in Nightingale alerts, or auto-generate labels through label enhancement                                                        |
  </Tab>

  <Tab title="Replace Feishu/Lark Group Bot">
    | Configuration          | Description                                                                                                                                                                                |
    | ---------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
    | **Parameter Name**     | Must match regex: `^layer_webhook_reset_(\d)_feishus$`, level numbers start from 0. For example, `layer_webhook_reset_0_feishus` replaces Feishu/Lark group bot in escalation rule level 1 |
    | **Parameter Value**    | Target group bot token, multiple tokens separated by `,`. For example, `bbb025a0-e2e8-4b79-939d-82c91a275b06` replaces the group bot with the bot corresponding to this token              |
    | **Parameter Location** | Query parameter or label value. For example, set this label in Nightingale alerts, or auto-generate labels through label enhancement                                                       |
  </Tab>
</Tabs>

<Tip>
  When an incident is triggered, Flashduty matches according to existing escalation rules. After matching an escalation rule, it assigns or escalates according to the levels in that rule. If the above parameters are set, the system will automatically replace the assignment targets or group chat channels.

  In the matched escalation rule, everything remains unchanged except for the assignment targets and group chat targets - essentially acting as a template escalation rule.
</Tip>

## Push Example

### Step 1: Set Up Template Escalation Rule

Configure an escalation rule for the channel. As shown below, this channel has only one assignment level, with the responder set to "Toutie Tech", and also pushes to a WeCom group chat with a token ending in 5b96.

<Frame caption="Template Escalation Rule Configuration Example">
  ![Template Escalation Rule Configuration](https://download.flashcat.cloud/flashduty/doc/en/fd/dyn-1.png)
</Frame>

### Step 2: Set Alert Labels

Using custom alert event integration as an example, push a sample alert to the target channel:

* Set `layer_person_reset_0_emails` label to replace level 1 responders with guoyuhang and yushuangyu
* Set `layer_webhook_reset_0_wecoms` label to replace level 1 WeCom group chat token with a token ending in d9c0

```bash theme={null}
curl --location --request POST 'https://api.flashcat.cloud/event/push/alert/standard?integration_key=your-integration-key' \
--header 'Content-Type: application/json' \
--data-raw '{
    "event_status": "Warning",
    "alert_key": "lasdfl2xzasd0262",
    "description": "cpu idle lower than 20%",
    "title_rule": "$cluster::$resource::$check",
    "labels": {
        "service": "engine",
        "cluster":"nj",
        "resource":"es.nj.01",
        "check":"cpu.idle<20%",
        "metric":"node_cpu_seconds_total",
        "layer_person_reset_0_emails": "guoyuhang@flashcat.cloud,yushuangyu@flashcat.cloud",
        "layer_webhook_reset_0_wecoms":"90dbb66b-af39-4235-956c-636a9c1ed9c0"
    }
}'
```

### Step 3: View Incident Assignment Timeline

As shown below, the target incident is triggered normally and assigned. The incident responders and target group chat have been replaced as expected.

<Frame caption="Dynamic Assignment Result">
  ![Dynamic Assignment Result Display](https://download.flashcat.cloud/flashduty/doc/en/fd/dyn-2.png)
</Frame>

## FAQ

<AccordionGroup>
  <Accordion title="What if my monitoring system doesn't have these labels?">
    <Steps>
      <Step title="Option 1: Manually Add Labels">
        If your system supports manually adding labels, such as Prometheus or Nightingale, we recommend adding specific labels directly in the alert policy.
      </Step>

      <Step title="Option 2: Use Label Enhancement">
        If your system already has related labels but in a different format or naming convention. For example, your hosts have team labels and you need to find the corresponding responder based on the team - in this case, you can use the label enhancement feature to generate responder-related labels based on team labels.

        For details, see [Configure Label Enhancement](/en/on-call/integration/alert-integration/label-enhancement).
      </Step>
    </Steps>
  </Accordion>
</AccordionGroup>

## Related Topics

<CardGroup cols={2}>
  <Card title="Label Enhancement" icon="tags" href="/en/on-call/integration/alert-integration/label-enhancement">
    Automatically generate new labels based on existing labels
  </Card>

  <Card title="Escalation Rules" icon="route" href="/en/on-call/channel/escalation-rule">
    Learn how to configure escalation rules
  </Card>
</CardGroup>
