-
-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Add full CRUD CLI commands for managing alert rules. Alerts in Sentry come in two distinct types with different APIs and scopes.
Issue Alerts
Trigger notifications when error events match conditions.
Commands: sentry alert issues list|view|create|edit|delete
Scope: per-project — /projects/{org}/{project}/rules/
Key fields for create:
name(required)conditions[]— at least one (required)actions[]— at least one (required)actionMatch—allorany(required)frequency— minutes between checks (default 30)environment,filters[],filterMatch,owner(optional)
edit: all fields optional; merges over existing (only provided flags change).
delete: requires --yes flag (destructive, affects production alerting).
Validation: ≥1 condition and ≥1 action, enum check for actionMatch/filterMatch, owner must be valid team/user.
Metric Alerts
Trigger notifications when a metric query crosses a threshold.
Commands: sentry alert metrics list|view|create|edit|delete
Scope: org-wide — /organizations/{org}/alert-rules/
Key fields for create:
name(required)query— filter query string (required)aggregate— e.g.count(),p95(transaction.duration)(required)dataset—errors,transactions,sessions, etc. (required)timeWindow— minutes (required)triggers[]— at least one withalertThresholdandactions[](required)projects[],environment,owner(optional)
edit: merge-based, only provided flags change.
delete: requires --yes flag.
Validation: enum check for dataset and timeWindow, ≥1 trigger with ≥1 action, valid aggregate function.
Implementation Notes
- Follow existing patterns:
buildListCommandfor list,buildCommandfor view/create/edit/delete - Use
resolveOrg+resolveProjectfromlib/resolve-target.ts - Alert identified by numeric ID or name (fuzzy match, like dashboard)
- Validate enums + required fields before API call to surface errors early
edit: fetch existing rule → merge provided flags → PUT (same merge pattern as widget edit)delete: safety gate with--yesflag (like project delete, since alerts affect production)- Output: human table + JSON transform,
--webflag to open in browser src/commands/alert/→issues/andmetrics/subroutessrc/lib/api/alerts.tsfor all API calls