//native
/**
* Create an issue alert rule for a project
* Create a new issue alert rule for the given project.
*/
export async function main(auth: RT.Sentry, project_id_or_slug: string, body: Body) {
const url = new URL(
`https://${auth.region}.sentry.io/api/0/projects/${auth.organizationSlug}/${project_id_or_slug}/rules/`
)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.token
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
/* eslint-disable */
/**
* This file was automatically generated by json-schema-to-typescript.
* DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
* and run json-schema-to-typescript to regenerate this file.
*/
export interface Body {
/**
* The name for the rule.
*/
name: string
/**
* How often to perform the actions once for an issue, in minutes. The valid range is `5` to `43200`.
*/
frequency: number
/**
* A string determining which of the conditions need to be true before any filters are evaluated.
*
* * `all` - All conditions must evaluate to true.
* * `any` - At least one of the conditions must evaluate to true.
* * `none` - All conditions must evaluate to false.
*/
actionMatch: 'all' | 'any' | 'none'
/**
*
* A list of triggers that determine when the rule fires. See below for a list of possible conditions.
*
* **A new issue is created**
* ```json
* {
* "id": "sentry.rules.conditions.first_seen_event.FirstSeenEventCondition"
* }
* ```
*
* **The issue changes state from resolved to unresolved**
* ```json
* {
* "id": "sentry.rules.conditions.regression_event.RegressionEventCondition"
* }
* ```
*
* **The issue is seen more than `value` times in `interval`**
* - `value` - An integer
* - `interval` - Valid values are `1m`, `5m`, `15m`, `1h`, `1d`, `1w` and `30d` (`m` for minutes, `h` for hours, `d` for days, and `w` for weeks).
* ```json
* {
* "id": "sentry.rules.conditions.event_frequency.EventFrequencyCondition",
* "value": 500,
* "interval": "1h"
* }
* ```
*
* **The issue is seen by more than `value` users in `interval`**
* - `value` - An integer
* - `interval` - Valid values are `1m`, `5m`, `15m`, `1h`, `1d`, `1w` and `30d` (`m` for minutes, `h` for hours, `d` for days, and `w` for weeks).
* ```json
* {
* "id": "sentry.rules.conditions.event_frequency.EventUniqueUserFrequencyCondition",
* "value": 1000,
* "interval": "15m"
* }
* ```
*
* **The issue affects more than `value` percent of sessions in `interval`**
* - `value` - A float
* - `interval` - Valid values are `5m`, `10m`, `30m`, and `1h` (`m` for minutes, `h` for hours).
* ```json
* {
* "id": "sentry.rules.conditions.event_frequency.EventFrequencyPercentCondition",
* "value": 50.0,
* "interval": "10m"
* }
* ```
*
*/
conditions: {
[k: string]: unknown
}[]
/**
*
* A list of actions that take place when all required conditions and filters for the rule are met. See below for a list of possible actions.
*
* **Send a notification to Suggested Assignees**
* - `fallthroughType` - Who the notification should be sent to if there are no suggested assignees. Valid values are `ActiveMembers`, `AllMembers`, and `NoOne`.
* ```json
* {
* "id" - "sentry.mail.actions.NotifyEmailAction",
* "targetType" - "IssueOwners",
* "fallthroughType" - "ActiveMembers"
* }
* ```
*
* **Send a notification to a Member or a Team**
* - `targetType` - One of `Member` or `Team`.
* - `fallthroughType` - Who the notification should be sent to if it cannot be sent to the original target. Valid values are `ActiveMembers`, `AllMembers`, and `NoOne`.
* - `targetIdentifier` - The ID of the Member or Team the notification should be sent to.
* ```json
* {
* "id": "sentry.mail.actions.NotifyEmailAction",
* "targetType": "Team"
* "fallthroughType": "AllMembers"
* "targetIdentifier": 4524986223
* }
* ```
*
* **Send a Slack notification**
* - `workspace` - The integration ID associated with the Slack workspace.
* - `channel` - The name of the channel to send the notification to (e.g., #critical, Jane Schmidt).
* - `channel_id` (optional) - The ID of the channel to send the notification to.
* - `tags` (optional) - A string of tags to show in the notification, separated by commas (e.g., "environment, user, my_tag").
* - `notes` (optional) - Text to show alongside the notification. To @ a user, include their user id like `@<USER_ID>`. To include a clickable link, format the link and title like `<http://example.com|Click Here>`.
* ```json
* {
* "id": "sentry.integrations.slack.notify_action.SlackNotifyServiceAction",
* "workspace": 293854098,
* "channel": "#warning",
* "tags": "environment,level"
* "notes": "Please <http://example.com|click here> for triage information"
* }
* ```
*
* **Send a Microsoft Teams notification**
* - `team` - The integration ID associated with the Microsoft Teams team.
* - `channel` - The name of the channel to send the notification to.
* ```json
* {
* "id": "sentry.integrations.msteams.notify_action.MsTeamsNotifyServiceAction",
* "team": 23465424,
* "channel": "General"
* }
* ```
*
* **Send a Discord notification**
* - `server` - The integration ID associated with the Discord server.
* - `channel_id` - The ID of the channel to send the notification to.
* - `tags` (optional) - A string of tags to show in the notification, separated by commas (e.g., "environment, user, my_tag").
* ```json
* {
* "id": "sentry.integrations.discord.notify_action.DiscordNotifyServiceAction",
* "server": 63408298,
* "channel_id": 94732897,
* "tags": "browser,user"
* }
* ```
*
* **Create a Jira Ticket**
* - `integration` - The integration ID associated with Jira.
* - `project` - The ID of the Jira project.
* - `issuetype` - The ID of the type of issue that the ticket should be created as.
* - `dynamic_form_fields` (optional) - A list of any custom fields you want to include in the ticket as objects.
* ```json
* {
* "id": "sentry.integrations.jira.notify_action.JiraCreateTicketAction",
* "integration": 321424,
* "project": "349719"
* "issueType": "1"
* }
* ```
*
* **Create a Jira Server Ticket**
* - `integration` - The integration ID associated with Jira Server.
* - `project` - The ID of the Jira Server project.
* - `issuetype` - The ID of the type of issue that the ticket should be created as.
* - `dynamic_form_fields` (optional) - A list of any custom fields you want to include in the ticket as objects.
* ```json
* {
* "id": "sentry.integrations.jira_server.notify_action.JiraServerCreateTicketAction",
* "integration": 321424,
* "project": "349719"
* "issueType": "1"
* }
* ```
*
* **Create a GitHub Issue**
* - `integration` - The integration ID associated with GitHub.
* - `repo` - The name of the repository to create the issue in.
* - `title` - The title of the issue.
* - `body` (optional) - The contents of the issue.
* - `assignee` (optional) - The GitHub user to assign the issue to.
* - `labels` (optional) - A list of labels to assign to the issue.
* ```json
* {
* "id": "sentry.integrations.github.notify_action.GitHubCreateTicketAction",
* "integration": 93749,
* "repo": default,
* "title": "My Test Issue",
* "assignee": "Baxter the Hacker",
* "labels": ["bug", "p1"]
* ""
* }
* ```
*
* **Create a GitHub Enterprise Issue**
* - `integration` - The integration ID associated with GitHub Enterprise.
* - `repo` - The name of the repository to create the issue in.
* - `title` - The title of the issue.
* - `body` (optional) - The contents of the issue.
* - `assignee` (optional) - The GitHub user to assign the issue to.
* - `labels` (optional) - A list of labels to assign to the issue.
* ```json
* {
* "id": "sentry.integrations.github_enterprise.notify_action.GitHubEnterpriseCreateTicketAction",
* "integration": 93749,
* "repo": default,
* "title": "My Test Issue",
* "assignee": "Baxter the Hacker",
* "labels": ["bug", "p1"]
* ""
* }
* ```
*
* **Create an Azure DevOps work item**
* - `integration` - The integration ID.
* - `project` - The ID of the Azure DevOps project.
* - `work_item_type` - The type of work item to create.
* - `dynamic_form_fields` (optional) - A list of any custom fields you want to include in the work item as objects.
* ```json
* {
* "id": "sentry.integrations.vsts.notify_action.AzureDevopsCreateTicketAction",
* "integration": 294838,
* "project": "0389485",
* "work_item_type": "Microsoft.VSTS.WorkItemTypes.Task",
* }
* ```
*
* **Send a PagerDuty notification**
* - `account` - The integration ID associated with the PagerDuty account.
* - `service` - The ID of the service to send the notification to.
* - `severity` - The severity of the Pagerduty alert. This is optional, the default is `critical` for fatal issues, `error` for error issues, `warning` for warning issues, and `info` for info and debug issues.
* ```json
* {
* "id": "sentry.integrations.pagerduty.notify_action.PagerDutyNotifyServiceAction",
* "account": 92385907,
* "service": 9823924,
* "severity": "critical"
* }
* ```
*
* **Send an Opsgenie notification**
* - `account` - The integration ID associated with the Opsgenie account.
* - `team` - The ID of the Opsgenie team to send the notification to.
* - `priority` - The priority of the Opsgenie alert. This is optional, the default is `P3`.
* ```json
* {
* "id": "sentry.integrations.opsgenie.notify_action.OpsgenieNotifyTeamAction",
* "account": 8723897589,
* "team": "9438930258-fairy",
* "priority": "P1"
* }
* ```
*
* **Send a notification to a service**
* - `service` - The plugin slug.
* ```json
* {
* "id": "sentry.rules.actions.notify_event_service.NotifyEventServiceAction",
* "service": "mail"
* }
* ```
*
* **Send a notification to a Sentry app with a custom webhook payload**
* - `settings` - A list of objects denoting the settings each action will be created with. All required fields must be included.
* - `sentryAppInstallationUuid` - The ID for the Sentry app
* ```json
* {
* "id": "sentry.rules.actions.notify_event_sentry_app.NotifyEventSentryAppAction",
* "settings": [
* {"name": "title", "value": "Team Rocket"},
* {"name": "summary", "value": "We're blasting off again."},
* ],
* "sentryAppInstallationUuid": 643522
* "hasSchemaFormConfig": true
* }
* ```
*
* **Send a notification (for all legacy integrations)**
* ```json
* {
* "id": "sentry.rules.actions.notify_event.NotifyEventAction"
* }
* ```
*
*/
actions: {
[k: string]: unknown
}[]
/**
* The name of the environment to filter by.
*/
environment?: string
/**
* The ID of the team or user that owns the rule.
*/
owner?: string
/**
* A string determining which filters need to be true before any actions take place. Required when a value is provided for `filters`.
*
* * `all` - All filters must evaluate to true.
* * `any` - At least one of the filters must evaluate to true.
* * `none` - All filters must evaluate to false.
*/
filterMatch?: 'all' | 'any' | 'none'
/**
*
* A list of filters that determine if a rule fires after the necessary conditions have been met. See below for a list of possible filters.
*
* **The issue is `comparison_type` than `value` `time`**
* - `comparison_type` - One of `older` or `newer`
* - `value` - An integer
* - `time` - The unit of time. Valid values are `minute`, `hour`, `day`, and `week`.
* ```json
* {
* "id": "sentry.rules.filters.age_comparison.AgeComparisonFilter",
* "comparison_type": "older",
* "value": 3,
* "time": "week"
* }
* ```
*
* **The issue has happened at least `value` times**
* - `value` - An integer
* ```json
* {
* "id": "sentry.rules.filters.issue_occurrences.IssueOccurrencesFilter",
* "value": 120
* }
* ```
*
* **The issue is assigned to No One**
* ```json
* {
* "id": "sentry.rules.filters.assigned_to.AssignedToFilter",
* "targetType": "Unassigned"
* }
* ```
*
* **The issue is assigned to `targetType`**
* - `targetType` - One of `Team` or `Member`
* - `targetIdentifier` - The target's ID
* ```json
* {
* "id": "sentry.rules.filters.assigned_to.AssignedToFilter",
* "targetType": "Member",
* "targetIdentifier": 895329789
* }
* ```
*
* **The event is from the latest release**
* ```json
* {
* "id": "sentry.rules.filters.latest_release.LatestReleaseFilter"
* }
* ```
*
* **The issue's category is equal to `value`**
* - `value` - An integer correlated with a category. Valid values are `1` (Error), `2` (Performance), `3` (Profile), `4` (Cron), and `5` (Replay).
* ```json
* {
* "id": "sentry.rules.filters.issue_category.IssueCategoryFilter",
* "value": 2
* }
* ```
*
* **The event's `attribute` value `match` `value`**
* - `attribute` - Valid values are `message`, `platform`, `environment`, `type`, `error.handled`, `error.unhandled`, `error.main_thread`, `exception.type`, `exception.value`, `user.id`, `user.email`, `user.username`, `user.ip_address`, `http.method`, `http.url`, `http.status_code`, `sdk.name`, `stacktrace.code`, `stacktrace.module`, `stacktrace.filename`, `stacktrace.abs_path`, `stacktrace.package`, `unreal.crash_type`, `app.in_foreground`.
* - `match` - The comparison operator. Valid values are `eq` (equals), `ne` (does not equal), `sw` (starts with), `ew` (ends with), `co` (contains), `nc` (does not contain), `is` (is set), and `ns` (is not set).
* - `value` - A string. Not required when `match` is `is` or `ns`.
* ```json
* {
* "id": "sentry.rules.conditions.event_attribute.EventAttributeCondition",
* "attribute": "http.url",
* "match": "nc",
* "value": "localhost"
* }
* ```
*
* **The event's tags match `key` `match` `value`**
* - `key` - The tag
* - `match` - The comparison operator. Valid values are `eq` (equals), `ne` (does not equal), `sw` (starts with), `ew` (ends with), `co` (contains), `nc` (does not contain), `is` (is set), and `ns` (is not set).
* - `value` - A string. Not required when `match` is `is` or `ns`.
* ```json
* {
* "id": "sentry.rules.filters.tagged_event.TaggedEventFilter",
* "key": "level",
* "match": "eq"
* "value": "error"
* }
* ```
*
* **The event's level is `match` `level`**
* - `match` - Valid values are `eq`, `gte`, and `lte`.
* - `level` - Valid values are `50` (fatal), `40` (error), `30` (warning), `20` (info), `10` (debug), `0` (sample).
* ```json
* {
* "id": "sentry.rules.filters.level.LevelFilter",
* "match": "gte"
* "level": "50"
* }
* ```
*
*/
filters?: {
[k: string]: unknown
}[]
[k: string]: unknown
}
Submitted by hugo697 235 days ago