sentry-create-alert について
workflow engine APIを通じてSentryアラートを作成するスキルです。トリガー、条件、通知アクションの設定からワークフローの検証までを案内します。APIはベータ版とされています。
主な機能
- 01アラートと組織の設定を収集
- 02課題イベントのトリガーを設定
- 03フィルター条件を指定
- 04通知アクションを設定
- 05API経由でワークフローを作成
- 06作成したアラートを検証
活用シーン
- 01優先度の高い課題をチームに通知
- 02再発または新規課題のアラート送信
- 03Sentry課題の通知を対応サービスへ振り分け
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ getsentry/ sentry-for-ai --skill sentry-create-alertインストール後、Claude Code で/sentry-create-alertを入力して読み込まれたか確認します。
詳細
Sentry アラートの作成
Sentry のワークフローエンジン API を使用してアラートを作成します。
注: この API は現在 ベータ版 であり、変更される可能性があります。 New Monitors and Alerts の一部であり、従来の Alerts UI では表示できない場合があります。
このスキルを呼び出す場面
- ユーザーが「Sentry アラートを作成して」または「通知を設定して」と依頼した場合
- 特定の条件に一致する問題が発生したときに、メールを受け取る、または通知を受けたい場合
- 優先度アラート、優先度引き下げアラート、またはワークフロー自動化に言及した場合
- Sentry の問題に関する Slack、PagerDuty、またはメール通知を設定したい場合
前提条件
- シェルで
curlを利用できること alerts:writeスコープを持つ Sentry 組織の認証トークン(org:adminまたはorg:writeも使用できます)
フェーズ 1:設定を確認する
不足している詳細があれば、ユーザーに確認します。
| 詳細 | 必須 | 例 |
|---|---|---|
| 組織のスラッグ | はい | sentry、my-org |
| 認証トークン | はい | sntryu_...(alerts:write スコープが必要です) |
| リージョン | はい(デフォルト:us) | us → us.sentry.io、de → de.sentry.io |
| アラート名 | はい | "High Priority De-escalation Alert" |
| トリガーイベント | はい | ワークフローを起動する問題イベント |
| 条件 | 任意 | アクション実行前のフィルター条件 |
| アクションの種類 | はい | email、slack、または pagerduty |
| アクションの対象 | はい | ユーザーのメールアドレス、チーム、チャンネル、またはサービス |
フェーズ 2:ID を調べる
必要に応じて、これらの API 呼び出しを使って名前を ID に変換します。
API="https://{region}.sentry.io/api/0/organizations/{org}"
AUTH="Authorization: Bearer {token}"
# 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"
# 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'])"
# 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'])"
フェーズ 3:ペイロードを構築する
トリガーイベント
ワークフローを起動する問題イベントを選びます。
logicType: "any-short" を使用します(トリガーでは常にこの値を指定する必要があります)。
| 種類 | 発生条件 |
|---|---|
first_seen_event | 新しい問題が作成されたとき |
regression_event | 解決済みの問題が再発したとき |
reappeared_event | アーカイブ済みの問題が再び表示されたとき |
issue_resolved_trigger | 問題が解決されたとき |
フィルター条件
アクションの実行前に満たす必要がある条件です。
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"} | イベントのタグが一致 |
assigned_to | {"targetType": "Member", "targetIdentifier": 123} | 問題が対象に割り当てられている |
level | {"level": 40, "match": "gte"} | イベントレベル(fatal=50、error=40、warning=30) |
age_comparison | {"time": "hour", "value": 24, "comparisonType": "older"} | 問題の経過時間 |
issue_category | {"value": 1} | カテゴリ(1=Error、6=Feedback、10=Outage:稼働時間と cron) |
issue_occurrences | {"value": 100} | 合計発生回数 |
期間の選択肢: "1min"、"5min"、"15min"、"1hr"、"1d"、"1w"、"30d"
タグの一致タイプ: "co"(含む)、"nc"(含まない)、"eq"、"ne"、"sw"
(で始まる)、"ew"(で終わる)、"is"(設定済み)、"ns"(未設定)
条件を満たさない場合に実行するには、conditionResult を false に設定します。
アクション
| 種類 | 主な設定 |
|---|---|
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: リポジトリ/課題の設定 |
ペイロードの全体構造
{
"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 内に設定します。
フェーズ 4:アラートを作成する
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 が含まれます。
フェーズ 5:確認する
アラートが作成されたことを確認し、UI のリンクを提示します。
https://{org_slug}.sentry.io/monitors/alerts/{workflow_id}/
組織で workflow-engine-ui 機能フラグが有効でない場合、アラートは次の場所に表示されます。
https://{org_slug}.sentry.io/alerts/rules/
アラートの管理
# List all workflows
curl -s "$API/workflows/" -H "$AUTH"
# Get one workflow
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}'
# Delete a workflow
curl -s -X DELETE "$API/workflows/{id}/" -H "$AUTH"
# Expect 204
トラブルシューティング
| 問題 | 解決策 |
|---|---|
| 401 Unauthorized | トークンに alerts:write スコープが必要です |
| 403 Forbidden | トークンは対象の組織に属している必要があります |
| 404 Not Found | 組織のスラッグとリージョン(us と de)を確認してください |
| 400 Bad Request | ペイロードの JSON 構造を検証し、必須フィールドを確認してください |
| ユーザー ID が見つからない | メールアドレスが組織のメンバーのものと一致するか確認してください |