sentry-create-alert

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
All Skills > Feature Setup > Create Alert
所有技能 > 功能设置 > 创建Sentry告警

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的工作流引擎API创建告警。
注意: 此API目前处于测试版,可能会随时变更。它属于新版监控与告警功能,在旧版告警UI中可能无法查看。

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

前置条件

  • curl
    available in shell
  • Sentry org auth token with
    alerts:write
    scope (also accepts
    org:admin
    or
    org:write
    )
  • Shell环境中已安装
    curl
  • 拥有
    alerts:write
    权限范围的Sentry组织认证令牌(也支持
    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
向用户询问缺失的详细信息:
详细信息是否必填示例
组织Slug
sentry
,
my-org
认证令牌
sntryu_...
(需要
alerts:write
权限)
区域是(默认:
us
us
us.sentry.io
,
de
de.sentry.io
告警名称
"High Priority De-escalation Alert"
触发事件触发工作流的问题事件类型
过滤条件可选执行动作前的过滤条件
动作类型
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

通过邮箱查找用户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'])"
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:构建请求体

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
选择触发工作流的问题事件类型。必须使用
logicType: "any-short"
(触发器始终需使用此值)。
类型触发时机
first_seen_event
新问题创建时
regression_event
已解决的问题复发时
reappeared_event
已归档的问题重新出现时
issue_resolved_trigger
问题被解决时

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)
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).
动作执行前必须满足的条件。可使用
logicType: "all"
,
"any-short"
, 或
"none"
comparison
字段为多态结构
—— 其格式取决于条件
type
类型
comparison
格式
描述
issue_priority_greater_or_equal
75
(纯整数)
优先级 >= 低(25)/中(50)/高(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"}
事件标签匹配时
assigned_to
{"targetType": "Member", "targetIdentifier": 123}
问题被分配给指定目标时
level
{"level": 40, "match": "gte"}
事件级别(致命=50,错误=40,警告=30)
age_comparison
{"time": "hour", "value": 24, "comparisonType": "older"}
问题时长
issue_category
{"value": 1}
分类(1=错误,6=反馈)
issue_occurrences
{"value": 100}
总出现次数
时间间隔选项:
"1min"
,
"5min"
,
"15min"
,
"1hr"
,
"1d"
,
"1w"
,
"30d"
标签匹配类型:
"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
: 标签列表
msteams
integrationId
:
<id>
,
config.targetDisplay
:
<channel>
opsgenie
integrationId
:
<id>
,
data.priority
:
"P1"
-
"P5"
jira
integrationId
:
<id>
,
data
: 项目/问题配置
github
integrationId
:
<id>
,
data
: 仓库/问题配置

Full Payload Structure

完整请求体结构

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
始终为
[]
—— 动作需定义在
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
状态码。响应结果包含工作流
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}/
如果组织未启用
workflow-engine-ui
功能标志,告警将显示在以下地址:
https://{org_slug}.sentry.io/alerts/rules/

Managing Alerts

告警管理

bash
undefined
bash
undefined

List 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"

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

删除工作流

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

Expect 204

预期返回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 Unauthorized令牌需要
alerts:write
权限范围
403 Forbidden令牌必须属于目标组织
404 Not Found检查组织Slug和区域(
us
vs
de
400 Bad Request验证请求体JSON结构,检查必填字段
用户ID未找到确认邮箱与组织成员的邮箱匹配