mcpField
S
sentry-create-alert

sentry-create-alert

github.com/getsentryクラウド・DevOps2724.1k 回インストール今日更新
リポジトリ

sentry-create-alert について

workflow engine APIを通じてSentryアラートを作成するスキルです。トリガー、条件、通知アクションの設定からワークフローの検証までを案内します。APIはベータ版とされています。

主な機能

  1. 01アラートと組織の設定を収集
  2. 02課題イベントのトリガーを設定
  3. 03フィルター条件を指定
  4. 04通知アクションを設定
  5. 05API経由でワークフローを作成
  6. 06作成したアラートを検証

活用シーン

  1. 01優先度の高い課題をチームに通知
  2. 02再発または新規課題のアラート送信
  3. 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_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、10=Outage:稼働時間と cron)
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 が見つからないメールアドレスが組織のメンバーのものと一致するか確認してください

コメント