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

# Label Enhancement

> Label enhancement automatically generates new labels during alert ingestion to supplement source data. Examples: extract IP from description, map resource ID to readable name, combine multiple fields to generate jump links, query external systems via API for dynamic data

<Tip>**Plan requirement**: Basic label enhancement requires an On-call Standard or higher subscription. Advanced label enhancement (such as API mapping) requires a Pro or higher subscription. [Learn more](https://flashcat.cloud/flashduty/price/)</Tip>

## Core Uses

Labels are used throughout Flashduty On-call's alert processing workflow:

| Scenario                    | Use                                                |
| :-------------------------- | :------------------------------------------------- |
| **Incident Filtering**      | Quickly filter by labels in incident list          |
| **Route Distribution**      | Route alerts to different channels based on labels |
| **Assignment Notification** | Match different escalation rules by labels         |
| **Alert Grouping**          | Group similar alerts by label dimensions           |
| **Silence/Inhibition**      | Match alerts to silence or inhibit by labels       |

## Configure Label Enhancement

Go to Integration Details → **Label Enhancement** → **Add Rule**.

### Enhancement Types

| Type        | Description                                               | Example                                        |
| :---------- | :-------------------------------------------------------- | :--------------------------------------------- |
| **Extract** | Extract content from title/description/labels using regex | Extract IP address from description            |
| **Combine** | Concatenate new labels using template syntax              | Combine domain + event ID to generate log link |
| **Map**     | Convert values to readable names via mapping table        | Map resource ID to resource type               |
| **Delete**  | Remove specified labels                                   | Delete sensitive info labels                   |

<Frame>
  <img src="https://docs-cdn.flashcat.cloud/images/png/c833e4ac159c9abaea755bad701d95ac.png" alt="Label enhancement types" />
</Frame>

### Configuration Options

| Option        | Description                                                                                                                |
| :------------ | :------------------------------------------------------------------------------------------------------------------------- |
| **Condition** | Only applies to alerts matching conditions, see [Configure Filter Conditions](/en/on-call/configuration/filter-conditions) |
| **Overwrite** | When enabled, overwrites labels with same name; disabled by default                                                        |
| **Preview**   | Preview rule effects using real alerts                                                                                     |

<Tip>
  Multiple rules execute sequentially from top to bottom. When a rule doesn't match, it's skipped and no corresponding label is generated.
</Tip>

## Configuration Examples

<Tabs>
  <Tab title="Label Extraction">
    **Scenario**: Alert events come from email integration; need to extract key information from description as labels for other scenarios, like extracting IP and trigger value from description as independent labels.

    <Steps>
      <Step title="View Original Alert">
        <Frame>
          <img src="https://docs-cdn.flashcat.cloud/images/png/4a335b5d80a1b5a8ea9460668f2a25d7.png" alt="Original alert" />
        </Frame>
      </Step>

      <Step title="Configure Extraction Rule">
        <Frame>
          <img src="https://docs-cdn.flashcat.cloud/images/png/eaebc7f494e5b0e955fb381813bace74.png" alt="Extraction rule configuration" />
        </Frame>
      </Step>

      <Step title="Verify Extraction Result">
        <Frame>
          <img src="https://docs-cdn.flashcat.cloud/images/png/33b3f01f2cc7f8b323765b0ed3ee7578.png" alt="Extraction result" />
        </Frame>
      </Step>
    </Steps>
  </Tab>

  <Tab title="Label Combination">
    **Scenario**: Company's log platform can access log details directly via domain + event ID + timestamp, but alert info only has event ID and timestamp labels, so need to combine these into an access URL.

    <Steps>
      <Step title="View Original Alert">
        <Frame>
          <img src="https://docs-cdn.flashcat.cloud/images/png/7b8eccb938993d2867bf3f7860b0788f.png" alt="Original alert" />
        </Frame>
      </Step>

      <Step title="Configure Combination Rule">
        <Frame>
          <img src="https://docs-cdn.flashcat.cloud/images/png/ea29da12647637b5f46667d8205f65b2.png" alt="Combination rule configuration" />
        </Frame>
      </Step>

      <Step title="Verify Combination Result">
        <Frame>
          <img src="https://docs-cdn.flashcat.cloud/images/png/7f6cf27203660cbd11ae737ed58a52a4.png" alt="Combination result" />
        </Frame>
      </Step>
    </Steps>
  </Tab>

  <Tab title="Label Mapping">
    **Scenario**: When source alert label values are variable and not intuitively meaningful, use mapping to map source labels to newly defined labels and values.

    Label mapping supports two mapping methods, selected via an inline radio toggle when adding a mapping rule -- choose **Schema** or **API**:

    | Mapping Type               | Description                                     | Use Case                                                              |
    | :------------------------- | :---------------------------------------------- | :-------------------------------------------------------------------- |
    | **Schema (Mapping Table)** | Static mapping via predefined CSV mapping table | Mapping relationships are relatively fixed with limited data          |
    | **API (API Mapping)**      | Dynamic mapping by calling external API service | Need to query external systems (e.g., mapping api) for real-time data |

    <Tabs>
      <Tab title="Schema Mapping">
        **Example**: Source alerts only have resource type IDs, want to show corresponding resource type names.

        <Steps>
          <Step title="Prepare Mapping Table File">
            Prepare a CSV format mapping table file to map resource type IDs in alerts to actual resource type names.

            |  ID |   Type   |
            | :-: | :------: |
            |  A  |  server  |
            |  B  |  router  |
            |  C  |  gateway |
            |  D  | database |
            |  E  |    MQ    |
          </Step>

          <Step title="Create Mapping Table">
            1. Go to `Configuration` → `Mappings` → `Schema`  → `Create mapping schema`
            2. Fill in basic info like name, description, management team, etc.
            3. In `Mapping Table Data`, upload the prepared CSV file (if quantity is small, you can edit and add in mapping details page after creation)
            4. Select `Source Label` (e.g., `ID`), select `Target Label` (e.g., `Type`)
            5. Click `Create` to complete mapping table creation

            <Frame>
              <img src="https://docs-cdn.flashcat.cloud/images/png/95bc8cdf3d3dcb60a52d11cdad4c386b.png" alt="Create mapping table" />
            </Frame>
          </Step>

          <Step title="Configure Mapping Relationship">
            <Frame>
              <img src="https://docs-cdn.flashcat.cloud/images/png/d25e632242d1a37ce9f159cd3b3086d4.png" alt="Configure mapping relationship" />
            </Frame>
          </Step>

          <Step title="Verify Mapping Result">
            **Original Alert**: Reported alert info only has resource ID, no resource type name.

            <Frame>
              <img src="https://docs-cdn.flashcat.cloud/images/png/c5e636c149f7125c0bde7e479414e130.png" alt="Original alert" />
            </Frame>

            **Mapping Result**: Through configured mapping relationship, map resource ID to new resource type name label.

            <Frame>
              <img src="https://docs-cdn.flashcat.cloud/images/png/8f93f6ae82e76e79196b5bf488663fe8.png" alt="Mapping result" />
            </Frame>
          </Step>
        </Steps>
      </Tab>

      <Tab title="API Mapping">
        **Example**: Need to query responsible team, service tier, and other dynamic data from mapping api system based on host information in alerts.

        <Steps>
          <Step title="Create Mapping Service">
            1. Go to `Configuration` → `Mappings` → `API`  → `Create API`
            2. Fill in service configuration:

            | Configuration | Description                                        | Example                                           |
            | :------------ | :------------------------------------------------- | :------------------------------------------------ |
            | Service Name  | Readable name for the service                      | Mapping api Asset Query Service                   |
            | Description   | Service purpose description                        | Query asset info by host IP                       |
            | Request URL   | API request address                                | `https://mapping-api.example.com/v1/enrich-event` |
            | Headers       | HTTP request header configuration                  | `X-Auth-Token: your-token`                        |
            | Timeout       | Request timeout, 1-3 seconds, default 2 seconds    | 1                                                 |
            | Retry Count   | Retry count on failure, 0-1 times, default 0 times | 1                                                 |

            <Tip>
              If the API uses HTTPS with an untrusted certificate, you can enable the `Skip Certificate Verification` option.
            </Tip>
          </Step>

          <Step title="Configure Mapping Rule">
            Add a mapping rule in label enhancement, use the radio toggle to select mapping type as `API`:

            1. Select the created mapping service
            2. Configure `Result Label List`: specify label names expected from API response, e.g., `owner_team`, `service_tier`, `host_ip`
            3. Enable `Override` option as needed
          </Step>

          <Step title="Verify Mapping Result">
            When an alert is triggered, Flashduty automatically calls the configured API service, sends alert event data to the external system, and adds the returned labels to the alert.
          </Step>
        </Steps>
      </Tab>
    </Tabs>
  </Tab>
</Tabs>

## Mapping Data Management

### Mapping Table Data Management

In the mapping table details page, you can manage mapping table data:

| Feature       | Description                                                 |
| :------------ | :---------------------------------------------------------- |
| Data Search   | Search by source label value                                |
| Data Add      | Manually add mapping data                                   |
| Data Upload   | Upload new data mapping table, will overwrite existing data |
| Data Download | Download current mapping table data locally                 |
| Data Display  | Display current mapping table data, can edit or delete      |

<Frame>
  <img src="https://docs-cdn.flashcat.cloud/images/png/477563cfc4e3759e8584edd34fa5bf9a.png" alt="Mapping table data management" />
</Frame>

<Tip>
  For frequently changing mapping relationships (like Mapping api data sync), we recommend using API mapping, or use [Flashduty API](/en/api-reference/on-call/alert-enrichment/mapping-data-write-upsert) for automated mapping table updates.
</Tip>

### Mapping Service API Specification

When using API mapping, your external API service must follow these specifications:

#### Request Specification

Flashduty will call your API via `POST` method with the following request body:

```json theme={null}
{
  "result_label_keys": ["owner_team", "service_tier", "host_ip"],
  "event": {
    "account_id": 1,
    "channel_id": 20,
    "data_source_id": 15,
    "data_source_type": "prometheus",
    "description": "CPU usage for instance '10.0.1.1:9100' is over 95%",
    "title": "High CPU Usage on instance 10.0.1.1:9100",
    "alert_key": "d41d8cd98f00b204e9800998ecf8427e",
    "event_severity": "Critical",
    "event_status": "Critical",
    "event_time": 1678886400,
    "labels": {
      "region": "us-east-1",
      "service": "service-A",
      "env": "production",
      "instance": "10.0.1.1:9100"
    }
  }
}
```

| Field               | Type           | Description                                                            |
| :------------------ | :------------- | :--------------------------------------------------------------------- |
| `result_label_keys` | array\[string] | List of expected label names to return, configured by user in the rule |
| `event`             | object         | Complete information of the current alert event                        |

#### Response Specification

The API must return a JSON response in the following format:

**Success Response** (HTTP 200):

```json theme={null}
{
  "result_labels": {
    "owner_team": "team-database",
    "service_tier": "tier-1",
    "host_ip": "10.0.1.1"
  }
}
```

| Response Code     | Description                             |
| :---------------- | :-------------------------------------- |
| `200 OK`          | Success, returns `result_labels` object |
| `404 Not Found`   | No matching data found                  |
| `400 Bad Request` | Invalid request format                  |
| `5xx`             | Internal server error                   |

<Note>
  If a requested label cannot find a corresponding value, the API **should not** include that key in `result_labels`.
</Note>

#### Security Constraints

For security purposes, the following HTTP Headers are prohibited in mapping services:

| Category         | Prohibited Headers                                                              |
| :--------------- | :------------------------------------------------------------------------------ |
| Authentication   | `authorization`, `proxy-authorization`, `cookie`, `x-api-key`, `x-access-token` |
| IP Spoofing      | `x-forwarded-for`, `x-real-ip`, `true-client-ip`, `x-client-ip`                 |
| Host & Routing   | `host`, `x-forwarded-host`, `x-forwarded-proto`, `x-internal-id`, `x-user-id`   |
| Protocol Related | `transfer-encoding`, `upgrade`, `connection`                                    |

<Tip>
  We recommend using custom Headers with `X-Custom-` or `X-Enrich-` prefix for authentication.
</Tip>

#### Best Practices

1. **Performance First**: The API is on the critical path of alert processing, must ensure low latency (recommended \< 500ms)
2. **Implement Caching**: For identical query conditions, implement caching to improve performance
3. **Idempotent Design**: Multiple calls for the same event should return identical results
4. **Secure Authentication**: API must be protected by authentication mechanisms to prevent unauthorized access

## Further Reading

<CardGroup cols={2}>
  <Card title="Configure Escalation Rules" icon="paper-plane" href="/en/on-call/channel/escalation-rule">
    Use labels to match escalation conditions
  </Card>

  <Card title="Configure Noise Reduction" icon="volume-slash" href="/en/on-call/channel/noise-reduction">
    Use labels as grouping dimensions
  </Card>

  <Card title="Configure Filter Conditions" icon="filter" href="/en/on-call/configuration/filter-conditions">
    Learn label matching syntax
  </Card>

  <Card title="Configure Routing Rules" icon="route" href="/en/on-call/integration/alert-integration/routing-rules">
    Distribute alerts to different channels
  </Card>
</CardGroup>
