mcpField
S
sentry-create-alert

sentry-create-alert

github.com/getsentryクラウド・DevOps25592 回インストール35 週間前に更新
リポジトリ

sentry-create-alert について

Sentry workflow engine API を使って問題アラートを作成するスキルです。通知や自動化を設定するチーム向けに、設定情報の収集、リクエストの構築、作成結果の確認を案内します。API は現在ベータ版です。

主な機能

  1. 01組織、リージョン、アラート設定を収集
  2. 02問題のトリガーと条件を構成
  3. 03メールや連携先への通知アクションを設定
  4. 04API でアラートを作成して確認
  5. 05ワークフローの参照と更新方法を案内

活用シーン

  1. 01新規問題の通知を設定
  2. 02優先度やイベント頻度を条件にアラート
  3. 03Slack、PagerDuty、メールへ通知
  4. 04Sentry のワークフローアラートを作成・確認

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/getsentry/sentry-agent-skills --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_equal75(整数値のみ)優先度 >= Low(25)/Medium(50)/High(75)
issue_priority_deescalatingtrue(ブール値のみ)優先度が最高値を下回った
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)
issue_occurrences{"value": 100}発生回数の合計

インターバルの選択肢: "1min"、"5min"、"15min"、"1hr"、"1d"、"1w"、"30d"

タグのマッチタイプ: "co"(含む)、"nc"(含まない)、"eq"、"ne"、"sw"(次で始まる)、"ew"(次で終わる)、"is"(設定済み)、"ns"(未設定)

conditionResult を false に設定すると、条件を反転できます(条件を満たさない場合に発火します)。

アクション
種類主な設定
emailconfig.targetType: "user" / "team" / "issue_owners"、config.targetIdentifier: <id>
slackintegrationId: <id>、config.targetDisplay: "#channel-name"
pagerdutyintegrationId: <id>、config.targetDisplay: <service_name>、data.priority: "critical"
discordintegrationId: <id>、data.tags: タグのリスト
msteamsintegrationId: <id>、config.targetDisplay: <channel>
opsgenieintegrationId: <id>、data.priority: "P1"-"P5"
jiraintegrationId: <id>、data: プロジェクト/課題の設定
githubintegrationId: <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 が見つからないメールアドレスが組織のメンバーのものと一致するか確認してください

コメント