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

# 紧急度与优先级档位

> 读取和设置组织的优先级档位和紧急度档位：各档的名称，以及每档紧急度怎么通知。

```http theme={null}
GET /api/v1/alerts/importance
PUT /api/v1/alerts/importance
```

`GET` 需要 `alerts.importance.read`，`PUT` 需要 `alerts.importance.manage`。两者都返回组织的档位：

```json theme={null}
{
  "levels": {
    "priorities": [
      {"priority": "P1", "name": "严重影响业务", "description": "用户无法付款"},
      {"priority": "P2", "name": "", "description": ""},
      {"priority": "P3", "name": "", "description": ""}
    ],
    "urgencies": [
      {"key": "urgent", "name": "特急", "escalates": true, "quiet_hours": "switch", "steps": "high", "severities": ["critical"]},
      {"key": "high", "name": "", "escalates": true, "quiet_hours": "switch", "steps": "high", "severities": ["error"]},
      {"key": "low", "name": "", "escalates": false, "quiet_hours": "block", "steps": "low", "severities": ["warning", "info"]}
    ]
  },
  "updated_by": "3KF1...",
  "updated_at": 1793059200000000
}
```

从没保存过档位的组织得到内置的档位：`P1` 到 `P5`，以及[紧急度](https://docs.molesignal.com/zh-Hans/alerting/on-call.md#紧急度)里说的 `high`、`low`，`updated_by` 为空。`PUT` 接受 `levels` 对象，整份替换档位，并记审计事件 `alert_importance.updated`。

| 字段 | 说明 |
| - | - |
| `priorities` | 1 到 9 档，`P1`、`P2`……依次排下去，不能跳。`name` 最多 32 个字符，`description` 最多 200 个；名称为空时显示键。 |
| `urgencies` | 2 到 5 档，最急的在前。`key` 以小写字母开头，只用小写字母、数字和下划线，最多 32 个字符；`high` 和 `low` 必须保留。`name` 最多 32 个字符；为空时用内置的说法。 |
| `escalates` | `true` 按升级策略逐级通知；`false` 只通知第一级。 |
| `quiet_hours` | `switch` 看个人的 **免打扰时仍接收高紧急度告警**；`block` 免打扰时一律不打扰。 |
| `steps` | 用个人两组步骤里的哪一组：`high` 或 `low`。 |
| `severities` | 策略按严重度定紧急度时落到这一档的严重度；`critical`、`error`、`warning`、`info` 每个恰好落在一档里。 |

档位决定规则、升级策略、事件和接口里能写什么：超出档数的优先级、不是某一档的紧急度在那些地方返回 `400`。外部告警或告警流水线给的优先级超出档数时落到最低一档，组织没有的紧急度去掉不用。通知里用 `{{priority_name}}` 和 `{{urgency_name}}` 取档位的名称。

```bash cURL theme={null}
curl -X PUT http://localhost:5080/api/v1/alerts/importance \
  -H "authorization: Bearer $MS_TOKEN" \
  -H "content-type: application/json" \
  -d @levels.json
```

**错误**

| 状态码 | 原因 |
| - | - |
| `400` | 档位不符合上表的要求。 |
| `403` | Token 缺少相应权限。 |
| `422` | 字段类型不对，或键的写法不对。 |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.