sentry-create-alert
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreate Sentry Alert
创建Sentry告警
Create alerts via Sentry's workflow engine API.
通过Sentry的工作流引擎API创建告警。
Invoke This Skill When
触发此技能的场景
- User asks to "create a Sentry alert" or "set up notifications"
- User wants to be emailed or notified when issues match certain conditions
- User mentions priority alerts, de-escalation alerts, or workflow automations
- User wants to configure Slack, PagerDuty, or email notifications for Sentry issues
- 用户要求“创建Sentry告警”或“设置通知”
- 用户希望当问题匹配特定条件时收到邮件或通知
- 用户提及优先级告警、降级告警或工作流自动化
- 用户希望为Sentry问题配置Slack、PagerDuty或邮件通知
Prerequisites
前置条件
- available in shell
curl - Sentry org auth token with scope
alerts:write
- 环境中已安装
curl - 拥有权限的Sentry组织认证令牌
alerts:write
Phase 1: Gather Configuration
阶段1:收集配置信息
Ask the user for any missing details:
| Detail | Required | Example |
|---|---|---|
| Org slug | Yes | |
| Auth token | Yes | |
| Region | Yes (default: | |
| Alert name | Yes | |
| Trigger events | Yes | Which issue events fire the workflow |
| Conditions | Optional | Filter conditions before actions execute |
| Action type | Yes | |
| Action target | Yes | User email, team, channel, or service |
向用户询问缺失的详细信息:
| 详细信息 | 是否必填 | 示例 |
|---|---|---|
| 组织Slug | 是 | |
| 认证令牌 | 是 | |
| 区域 | 是(默认: | |
| 告警名称 | 是 | |
| 触发事件 | 是 | 触发工作流的问题事件类型 |
| 过滤条件 | 可选 | 执行操作前的过滤条件 |
| 操作类型 | 是 | |
| 操作目标 | 是 | 用户邮箱、团队、频道或服务 |
Phase 2: Look Up IDs
阶段2:查询ID
Use these API calls to resolve names to IDs as needed.
bash
API="https://{region}.sentry.io/api/0/organizations/{org}"
AUTH="Authorization: Bearer {token}"根据需要使用以下API调用将名称解析为ID。
bash
API="https://{region}.sentry.io/api/0/organizations/{org}"
AUTH="Authorization: Bearer {token}"Find user ID by email
通过邮箱查询用户ID
curl -s "$API/members/" -H "$AUTH" | python3 -c "
import json,sys
for m in json.load(sys.stdin):
if m.get('email')=='USER_EMAIL' or m.get('user',{}).get('email')=='USER_EMAIL':
print(m['user']['id']); break"
curl -s "$API/members/" -H "$AUTH" | python3 -c "
import json,sys
for m in json.load(sys.stdin):
if m.get('email')=='USER_EMAIL' or m.get('user',{}).get('email')=='USER_EMAIL':
print(m['user']['id']); break"
List teams
列出团队
curl -s "$API/teams/" -H "$AUTH" | python3 -c "
import json,sys
for t in json.load(sys.stdin):
print(t['id'], t['slug'])"
curl -s "$API/teams/" -H "$AUTH" | python3 -c "
import json,sys
for t in json.load(sys.stdin):
print(t['id'], t['slug'])"
List integrations (for Slack/PagerDuty)
列出集成(适用于Slack/PagerDuty)
curl -s "$API/integrations/" -H "$AUTH" | python3 -c "
import json,sys
for i in json.load(sys.stdin):
print(i['id'], i['provider']['key'], i['name'])"
undefinedcurl -s "$API/integrations/" -H "$AUTH" | python3 -c "
import json,sys
for i in json.load(sys.stdin):
print(i['id'], i['provider']['key'], i['name'])"
undefinedPhase 3: Build Payload
阶段3:构建请求体
Trigger Events
触发事件
Pick which issue events fire the workflow. Use (triggers must always use this).
logicType: "any-short"| Type | Fires when |
|---|---|
| New issue created |
| Resolved issue recurs |
| Archived issue reappears |
选择触发工作流的问题事件类型。必须使用(触发器始终需配置此参数)。
logicType: "any-short"| 类型 | 触发时机 |
|---|---|
| 新问题创建时 |
| 已解决的问题复发时 |
| 已归档的问题重新出现时 |
Filter Conditions
过滤条件
Conditions that must pass before actions execute. Use , , or .
logicType: "all""any-short""none"| Type | comparison | Description |
|---|---|---|
| | Priority >= Low/Medium/High/Critical |
| | Priority dropped below peak |
| | Event count exceeds threshold |
| | Affected users exceed threshold |
| | Event has specific tag |
| | Issue assigned to target |
Priority scale: Low=25, Medium=50, High=75, Critical=100.
Set to to invert (fire when condition is NOT met).
conditionResultfalse执行操作前必须满足的条件。可使用, 或 。
logicType: "all""any-short""none"| 类型 | 比较值 | 描述 |
|---|---|---|
| | 优先级 >= 低/中/高/严重 |
| | 优先级低于峰值时 |
| | 事件数量超过阈值时 |
| | 受影响用户数量超过阈值时 |
| | 事件包含特定标签时 |
| | 问题已分配给目标对象时 |
优先级对应关系:低=25,中=50,高=75,严重=100。
设置为可反转条件(当条件不满足时触发)。
conditionResultfalseActions
操作
| Type | Key Config |
|---|---|
| |
| |
| |
| 类型 | 核心配置 |
|---|---|
| |
| |
| |
Full Payload Structure
完整请求体结构
json
{
"name": "<Alert Name>",
"enabled": true,
"environment": null,
"config": { "frequency": 0 },
"triggers": {
"logicType": "any-short",
"conditions": [
{ "type": "first_seen_event", "comparison": true, "conditionResult": true }
]
},
"actionFilters": [{
"logicType": "all",
"conditions": [
{ "type": "issue_priority_greater_or_equal", "comparison": 75, "conditionResult": true }
],
"actions": [{
"type": "email",
"integrationId": null,
"data": {},
"config": {
"targetType": "user",
"targetIdentifier": "<user_id>",
"targetDisplay": null
}
}]
}]
}frequency01800json
{
"name": "<Alert Name>",
"enabled": true,
"environment": null,
"config": { "frequency": 0 },
"triggers": {
"logicType": "any-short",
"conditions": [
{ "type": "first_seen_event", "comparison": true, "conditionResult": true }
]
},
"actionFilters": [{
"logicType": "all",
"conditions": [
{ "type": "issue_priority_greater_or_equal", "comparison": 75, "conditionResult": true }
],
"actions": [{
"type": "email",
"integrationId": null,
"data": {},
"config": {
"targetType": "user",
"targetIdentifier": "<user_id>",
"targetDisplay": null
}
}]
}]
}frequency01800Phase 4: Create the Alert
阶段4:创建告警
bash
curl -s -w "\n%{http_code}" -X POST \
"https://{region}.sentry.io/api/0/organizations/{org}/workflows/" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{payload}'Expect HTTP . The response contains the workflow .
201idbash
curl -s -w "\n%{http_code}" -X POST \
"https://{region}.sentry.io/api/0/organizations/{org}/workflows/" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{payload}'预期返回HTTP 状态码。响应结果中包含工作流。
201idPhase 5: Verify
阶段5:验证
Confirm the alert was created and provide the UI link:
https://{org_slug}.sentry.io/monitors/alerts/{workflow_id}/If the org lacks the feature flag, the alert appears at:
workflow-engine-uihttps://{org_slug}.sentry.io/alerts/rules/确认告警已创建,并提供UI链接:
https://{org_slug}.sentry.io/monitors/alerts/{workflow_id}/若组织未启用功能标志,告警将显示在以下地址:
workflow-engine-uihttps://{org_slug}.sentry.io/alerts/rules/Managing Alerts
管理告警
bash
undefinedbash
undefinedList all workflows
列出所有工作流
curl -s "$API/workflows/" -H "$AUTH"
curl -s "$API/workflows/" -H "$AUTH"
Get one workflow
查询单个工作流
curl -s "$API/workflows/{id}/" -H "$AUTH"
curl -s "$API/workflows/{id}/" -H "$AUTH"
Delete a workflow
删除工作流
curl -s -X DELETE "$API/workflows/{id}/" -H "$AUTH"
curl -s -X DELETE "$API/workflows/{id}/" -H "$AUTH"
Expect 204
预期返回204状态码
undefinedundefinedTroubleshooting
故障排查
| Issue | Solution |
|---|---|
| 401 Unauthorized | Token needs |
| 403 Forbidden | Token must belong to the target org |
| 404 Not Found | Check org slug and region ( |
| 400 Bad Request | Validate payload JSON structure, check required fields |
| User ID not found | Verify email matches a member of the org |
| 问题 | 解决方案 |
|---|---|
| 401 Unauthorized | 令牌需要具备 |
| 403 Forbidden | 令牌必须属于目标组织 |
| 404 Not Found | 检查组织Slug和区域( |
| 400 Bad Request | 验证请求体JSON结构,检查必填字段 |
| 用户ID未找到 | 确认邮箱属于组织成员 |