sentry-create-alert

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Create Sentry Alert

创建 Sentry 告警

Create alerts via Sentry’s workflow engine API.
Note: This API is currently in beta and may be subject to change. It is part of New Monitors and Alerts and may not be viewable in the legacy Alerts UI.
通过 Sentry 的 workflow engine API 创建告警。
注意: 此 API 当前仍处于 beta 阶段,可能会发生变化。 它属于 New Monitors and Alerts,可能无法在旧版 Alerts UI 中查看。

Invoke This Skill When

调用此 Skill 的时机

  • 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 告警”或“设置通知”
  • 希望在 issue 符合特定条件时收到电子邮件或通知
  • 提到优先级告警、优先级降级告警或工作流自动化
  • 希望为 Sentry issue 配置 Slack、PagerDuty 或电子邮件通知

Prerequisites

前置条件

  • curl
    available in shell
  • Sentry org auth token with
    alerts:write
    scope (also accepts
    org:admin
    or
    org:write
    )
  • shell 中可使用
    curl
  • Sentry org auth token,需具备
    alerts:write
    scope(也接受
    org:admin
    或
    org:write
    )

Phase 1: Gather Configuration

阶段 1:收集配置

Ask the user for any missing details:
DetailRequiredExample
Org slugYes
sentry
,
my-org
Auth tokenYes
sntryu_...
(needs
alerts:write
scope)
RegionYes (default:
us
)
us
→
us.sentry.io
,
de
→
de.sentry.io
Alert nameYes
"High Priority De-escalation Alert"
Trigger eventsYesWhich issue events fire the workflow
ConditionsOptionalFilter conditions before actions execute
Action typeYes
email
,
slack
, or
pagerduty
Action targetYesUser email, team, channel, or service
询问用户是否缺少以下必要信息:
详细信息是否必填示例
Org slug是
sentry
、
my-org
Auth token是
sntryu_...
(需要
alerts:write
scope)
Region是(默认:
us
)
us
→
us.sentry.io
,
de
→
de.sentry.io
告警名称是
"High Priority De-escalation Alert"
触发事件是哪些 issue 事件触发工作流
条件可选在执行 actions 前应用的筛选条件
操作类型是
email
、
slack
或
pagerduty
操作目标是用户电子邮件、团队、频道或服务

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

Find user ID by email

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

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)

List integrations (for 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'])"
undefined
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'])"
undefined

Phase 3: Build Payload

阶段 3:构建 Payload

Trigger Events

触发事件

Pick which issue events fire the workflow. Use
logicType: "any-short"
(triggers must always use this).
TypeFires when
first_seen_event
New issue created
regression_event
Resolved issue recurs
reappeared_event
Archived issue reappears
issue_resolved_trigger
Issue is resolved
选择哪些 issue 事件触发工作流。 使用
logicType: "any-short"
(触发器必须始终使用此值)。
类型触发时机
first_seen_event
创建新 issue
regression_event
已解决的 issue 再次发生
reappeared_event
已归档的 issue 再次出现
issue_resolved_trigger
issue 已解决

Filter Conditions

筛选条件

Conditions that must pass before actions execute. Use
logicType: "all"
,
"any-short"
, or
"none"
.
The
comparison
field is polymorphic
— its shape depends on the condition
type
:
Type
comparison
format
Description
issue_priority_greater_or_equal
75
(bare integer)
Priority >= Low(25)/Medium(50)/High(75)
issue_priority_deescalating
true
(bare boolean)
Priority dropped below peak
event_frequency_count
{"value": 100, "interval": "1hr"}
Event count in time window
event_unique_user_frequency_count
{"value": 50, "interval": "1hr"}
Affected users in time window
tagged_event
{"key": "level", "match": "eq", "value": "error"}
Event tag matches
assigned_to
{"targetType": "Member", "targetIdentifier": 123}
Issue assigned to target
level
{"level": 40, "match": "gte"}
Event level (fatal=50, error=40, warning=30)
age_comparison
{"time": "hour", "value": 24, "comparisonType": "older"}
Issue age
issue_category
{"value": 1}
Category (1=Error, 6=Feedback, 10=Outage: uptime and cron)
issue_occurrences
{"value": 100}
Total occurrence count
Interval options:
"1min"
,
"5min"
,
"15min"
,
"1hr"
,
"1d"
,
"1w"
,
"30d"
Tag match types:
"co"
(contains),
"nc"
(not contains),
"eq"
,
"ne"
,
"sw"
(starts with),
"ew"
(ends with),
"is"
(set),
"ns"
(not set)
Set
conditionResult
to
false
to invert (fire when condition is NOT met).
执行 actions 前必须满足的条件。 使用
logicType: "all"
、
"any-short"
或
"none"
。
comparison
字段是多态的
——其结构取决于条件的
type
:
类型
comparison
格式
说明
issue_priority_greater_or_equal
75
(裸整数)
优先级 >= Low(25)/Medium(50)/High(75)
issue_priority_deescalating
true
(裸布尔值)
优先级降至峰值以下
event_frequency_count
{"value": 100, "interval": "1hr"}
时间窗口内的事件计数
event_unique_user_frequency_count
{"value": 50, "interval": "1hr"}
时间窗口内受影响的用户数
tagged_event
{"key": "level", "match": "eq", "value": "error"}
事件 tag 匹配
assigned_to
{"targetType": "Member", "targetIdentifier": 123}
issue 已分配给目标对象
level
{"level": 40, "match": "gte"}
事件级别(fatal=50、error=40、warning=30)
age_comparison
{"time": "hour", "value": 24, "comparisonType": "older"}
issue 存续时长
issue_category
{"value": 1}
类别(1=Error,6=Feedback,10=Outage: uptime and cron)
issue_occurrences
{"value": 100}
总发生次数
间隔选项:
"1min"
、
"5min"
、
"15min"
、
"1hr"
、
"1d"
、
"1w"
、
"30d"
Tag 匹配类型:
"co"
(包含)、
"nc"
(不包含)、
"eq"
、
"ne"
、
"sw"
(以...开头)、
"ew"
(以...结尾)、
"is"
(已设置)、
"ns"
(未设置)
将
conditionResult
设为
false
可反转条件(在条件不满足时触发)。

Actions

操作

TypeKey Config
email
config.targetType
:
"user"
/
"team"
/
"issue_owners"
,
config.targetIdentifier
:
<id>
slack
integrationId
:
<id>
,
config.targetDisplay
:
"#channel-name"
pagerduty
integrationId
:
<id>
,
config.targetDisplay
:
<service_name>
,
data.priority
:
"critical"
discord
integrationId
:
<id>
,
data.tags
: tag list
msteams
integrationId
:
<id>
,
config.targetDisplay
:
<channel>
opsgenie
integrationId
:
<id>
,
data.priority
:
"P1"
-
"P5"
jira
integrationId
:
<id>
,
data
: project/issue config
github
integrationId
:
<id>
,
data
: repo/issue config
类型关键配置
email
config.targetType
:
"user"
/
"team"
/
"issue_owners"
,
config.targetIdentifier
:
<id>
slack
integrationId
:
<id>
,
config.targetDisplay
:
"#channel-name"
pagerduty
integrationId
:
<id>
,
config.targetDisplay
:
<service_name>
,
data.priority
:
"critical"
discord
integrationId
:
<id>
,
data.tags
: tag 列表
msteams
integrationId
:
<id>
,
config.targetDisplay
:
<channel>
opsgenie
integrationId
:
<id>
,
data.priority
:
"P1"
-
"P5"
jira
integrationId
:
<id>
,
data
: 项目/issue 配置
github
integrationId
:
<id>
,
data
: 仓库/issue 配置

Full Payload Structure

完整 Payload 结构

json
{
  "name": "<Alert Name>",
  "enabled": true,
  "environment": null,
  "config": { "frequency": 30 },
  "triggers": {
    "logicType": "any-short",
    "conditions": [
      { "type": "first_seen_event", "comparison": true, "conditionResult": true }
    ],
    "actions": []
  },
  "actionFilters": [{
    "logicType": "all",
    "conditions": [
      { "type": "issue_priority_greater_or_equal", "comparison": 75, "conditionResult": true },
      { "type": "event_frequency_count", "comparison": {"value": 50, "interval": "1hr"}, "conditionResult": true }
    ],
    "actions": [{
      "type": "email",
      "integrationId": null,
      "data": {},
      "config": {
        "targetType": "user",
        "targetIdentifier": "<user_id>",
        "targetDisplay": null
      },
      "status": "active"
    }]
  }]
}
frequency
: minutes between repeated notifications. Allowed values:
0
,
5
,
10
,
30
,
60
,
180
,
720
,
1440
.
Structure note:
triggers.actions
is always
[]
— actions live inside
actionFilters[].actions
.
json
{
  "name": "<Alert Name>",
  "enabled": true,
  "environment": null,
  "config": { "frequency": 30 },
  "triggers": {
    "logicType": "any-short",
    "conditions": [
      { "type": "first_seen_event", "comparison": true, "conditionResult": true }
    ],
    "actions": []
  },
  "actionFilters": [{
    "logicType": "all",
    "conditions": [
      { "type": "issue_priority_greater_or_equal", "comparison": 75, "conditionResult": true },
      { "type": "event_frequency_count", "comparison": {"value": 50, "interval": "1hr"}, "conditionResult": true }
    ],
    "actions": [{
      "type": "email",
      "integrationId": null,
      "data": {},
      "config": {
        "targetType": "user",
        "targetIdentifier": "<user_id>",
        "targetDisplay": null
      },
      "status": "active"
    }]
  }]
}
frequency
:重复通知之间的间隔(分钟)。 允许值:
0
、
5
、
10
、
30
、
60
、
180
、
720
、
1440
。
结构说明:
triggers.actions
始终为
[]
——actions 位于
actionFilters[].actions
中。

Phase 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
201
. The response contains the workflow
id
.
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}'
预期返回 HTTP
201
。响应中包含 workflow
id
。

Phase 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
workflow-engine-ui
feature flag, the alert appears at:
https://{org_slug}.sentry.io/alerts/rules/
确认告警已创建,并提供 UI 链接:
https://{org_slug}.sentry.io/monitors/alerts/{workflow_id}/
如果 org 没有
workflow-engine-ui
feature flag,告警将显示在:
https://{org_slug}.sentry.io/alerts/rules/

Managing Alerts

管理告警

bash
undefined
bash
undefined

List all workflows

List all workflows

curl -s "$API/workflows/" -H "$AUTH"
curl -s "$API/workflows/" -H "$AUTH"

Get one workflow

Get one workflow

curl -s "$API/workflows/{id}/" -H "$AUTH"
curl -s "$API/workflows/{id}/" -H "$AUTH"

Update a workflow

Update a workflow

curl -s -X PUT "$API/workflows/{id}/" -H "$AUTH" -H "Content-Type: application/json" -d '{payload}'
curl -s -X PUT "$API/workflows/{id}/" -H "$AUTH" -H "Content-Type: application/json" -d '{payload}'

Delete a workflow

Delete a workflow

curl -s -X DELETE "$API/workflows/{id}/" -H "$AUTH"
curl -s -X DELETE "$API/workflows/{id}/" -H "$AUTH"

Expect 204

Expect 204

undefined
undefined

Troubleshooting

故障排查

IssueSolution
401 UnauthorizedToken needs
alerts:write
scope
403 ForbiddenToken must belong to the target org
404 Not FoundCheck org slug and region (
us
vs
de
)
400 Bad RequestValidate payload JSON structure, check required fields
User ID not foundVerify email matches a member of the org
问题解决方案
401 UnauthorizedToken 需要具备
alerts:write
scope
403 ForbiddenToken 必须属于目标 org
404 Not Found检查 org slug 和 region(
us
与
de
)
400 Bad Request校验 payload JSON 结构并检查必填字段
未找到用户 ID验证电子邮件是否与 org 成员匹配