//native
/**
* Update a metric alert rule
* Updates a metric alert rule.
*/
export async function main(auth: RT.Sentry, alert_rule_id: string, body: Body) {
const url = new URL(
`https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/alert-rules/${alert_rule_id}/`
)
const response = await fetch(url, {
method: 'PUT',
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
/**
* A string representing the aggregate function used in this alert rule. Valid aggregate functions are `count`, `count_unique`, `percentage`, `avg`, `apdex`, `failure_rate`, `p50`, `p75`, `p95`, `p99`, `p100`, and `percentile`. See **Metric Alert Rule Types** under [Create a Metric Alert Rule](/api/alerts/create-a-metric-alert-rule-for-an-organization/#metric-alert-rule-types) for valid configurations.
*/
aggregate: string
/**
* The time period to aggregate over.
*
* * `1` - 1 minute
* * `5` - 5 minutes
* * `10` - 10 minutes
* * `15` - 15 minutes
* * `30` - 30 minutes
* * `60` - 1 hour
* * `120` - 2 hours
* * `240` - 4 hours
* * `1440` - 24 hours
*/
timeWindow: 1 | 5 | 10 | 15 | 30 | 60 | 120 | 240 | 1440
/**
* The names of the projects to filter by.
*/
projects: string[]
/**
* An event search query to subscribe to and monitor for alerts. For example, to filter transactions so that only those with status code 400 are included, you could use `"query": "http.status_code:400"`. Use an empty string for no filter.
*/
query: string
/**
* The comparison operator for the critical and warning thresholds. The comparison operator for the resolved threshold is automatically set to the opposite operator. When a percentage change threshold is used, `0` is equivalent to "Higher than" and `1` is equivalent to "Lower than".
*
* * `0` - Above
* * `1` - Below
*/
thresholdType: 0 | 1
/**
*
* A list of triggers, where each trigger is an object with the following fields:
* - `label`: One of `critical` or `warning`. A `critical` trigger is always required.
* - `alertThreshold`: The value that the subscription needs to reach to trigger the
* alert rule.
* - `actions`: A list of actions that take place when the threshold is met.
* ```json
* triggers: [
* {
* "label": "critical",
* "alertThreshold": 100,
* "actions": [
* {
* "type": "email",
* "targetType": "user",
* "targetIdentifier": "23489853",
* "inputChannelId": None
* "integrationId": None,
* "sentryAppId": None
* }
* ]
* },
* {
* "label": "warning",
* "alertThreshold": 75,
* "actions": []
* }
* ]
* ```
* Metric alert rule trigger actions follow the following structure:
* - `type`: The type of trigger action. Valid values are `email`, `slack`, `msteams`, `pagerduty`, `sentry_app`, `sentry_notification`, and `opsgenie`.
* - `targetType`: The type of target the notification will be sent to. Valid values are `specific`, `user`, `team`, and `sentry_app`.
* - `targetIdentifier`: The ID of the target. This must be an integer for PagerDuty and Sentry apps, and a string for all others. Examples of appropriate values include a Slack channel name (`#my-channel`), a user ID, a team ID, a Sentry app ID, etc.
* - `inputChannelId`: The ID of the Slack channel. This is only used for the Slack action, and can be used as an alternative to providing the `targetIdentifier`.
* - `integrationId`: The integration ID. This is required for every action type except `email` and `sentry_app.`
* - `sentryAppId`: The ID of the Sentry app. This is required when `type` is `sentry_app`.
* - `priority`: The severity of the Pagerduty alert or the priority of the Opsgenie alert (optional). Defaults for Pagerduty are `critical` for critical and `warning` for warning. Defaults for Opsgenie are `P1` for critical and `P2` for warning.
*
*/
triggers: unknown[]
/**
* The name of the environment to filter by. Defaults to all environments.
*/
environment?: string
/**
* The name of the dataset that this query will be executed on. Valid values are `events`, `transactions`, `metrics`, `sessions`, and `generic-metrics`. Defaults to `events`. See **Metric Alert Rule Types** under [Create a Metric Alert Rule](/api/alerts/create-a-metric-alert-rule-for-an-organization/#metric-alert-rule-types) for valid configurations.
*/
dataset?: string
/**
* The type of query. If no value is provided, `queryType` is set to the default for the specified `dataset.` See **Metric Alert Rule Types** under [Create a Metric Alert Rule](/api/alerts/create-a-metric-alert-rule-for-an-organization/#metric-alert-rule-types) for valid configurations.
*
* * `0` - event.type:error
* * `1` - event.type:transaction
* * `2` - None
*/
queryType?: 0 | 1 | 2
/**
* List of event types that this alert will be related to. Valid values are `default` (events captured using [Capture Message](/product/sentry-basics/integrate-backend/capturing-errors/#capture-message)), `error` and `transaction`.
*/
eventTypes?: string[]
/**
* An optional int representing the time delta to use as the comparison period, in minutes. Required when using a percentage change threshold ("x%" higher or lower compared to `comparisonDelta` minutes ago). A percentage change threshold cannot be used for [Crash Free Session Rate](/api/alerts/create-a-metric-alert-rule-for-an-organization/#crash-free-session-rate) or [Crash Free User Rate](/api/alerts/create-a-metric-alert-rule-for-an-organization/#crash-free-user-rate).
*/
comparisonDelta?: number
/**
* Optional value that the metric needs to reach to resolve the alert. If no value is provided, this is set automatically based on the lowest severity trigger's `alertThreshold`. For example, if the alert is set to trigger at the warning level when the number of errors is above 50, then the alert would be set to resolve when there are less than 50 errors. If `thresholdType` is `0`, `resolveThreshold` must be greater than the critical threshold. Otherwise, it must be less than the critical threshold.
*/
resolveThreshold?: number
/**
* The ID of the team or user that owns the rule.
*/
owner?: string
[k: string]: unknown
}
Submitted by hugo697 235 days ago