1 | |
2 | |
3 | * Create a spike protection notification action |
4 | * Creates a new Notification Action for Spike Protection. |
5 |
|
6 | Notification Actions notify a set of members when an action has been triggered through a notification service such as Slack or Sentry. |
7 | For example, organization owners and managers can receive an email when a spike occurs. |
8 | */ |
9 | export async function main(auth: RT.Sentry, body: Body) { |
10 | const url = new URL( |
11 | `https://${auth.region}.sentry.io/api/0/organizations/${auth.organizationSlug}/notifications/actions/` |
12 | ) |
13 |
|
14 | const response = await fetch(url, { |
15 | method: 'POST', |
16 | headers: { |
17 | 'Content-Type': 'application/json', |
18 | Authorization: 'Bearer ' + auth.token |
19 | }, |
20 | body: JSON.stringify(body) |
21 | }) |
22 | if (!response.ok) { |
23 | const text = await response.text() |
24 | throw new Error(`${response.status} ${text}`) |
25 | } |
26 | return await response.json() |
27 | } |
28 |
|
29 | |
30 | |
31 | * This file was automatically generated by json-schema-to-typescript. |
32 | * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file, |
33 | * and run json-schema-to-typescript to regenerate this file. |
34 | */ |
35 |
|
36 | |
37 | * Django Rest Framework serializer for incoming NotificationAction API payloads |
38 | */ |
39 | export interface Body { |
40 | |
41 | * Type of the trigger that causes the notification. The only supported trigger right now is: `spike-protection`. |
42 | */ |
43 | trigger_type: string |
44 | |
45 | * Service that is used for sending the notification. |
46 | * - `email` |
47 | * - `slack` |
48 | * - `sentry_notification` |
49 | * - `pagerduty` |
50 | * - `opsgenie` |
51 | * |
52 | */ |
53 | service_type: string |
54 | |
55 | * ID of the integration used as the notification service. See |
56 | * [List Integrations](https://docs.sentry.io/api/integrations/list-an-organizations-available-integrations/) |
57 | * to retrieve a full list of integrations. |
58 | * |
59 | * Required if **service_type** is `slack`, `pagerduty` or `opsgenie`. |
60 | * |
61 | */ |
62 | integration_id?: number |
63 | |
64 | * ID of the notification target, like a Slack channel ID. |
65 | * |
66 | * Required if **service_type** is `slack` or `opsgenie`. |
67 | * |
68 | */ |
69 | target_identifier?: string |
70 | |
71 | * Name of the notification target, like a Slack channel name. |
72 | * |
73 | * Required if **service_type** is `slack` or `opsgenie`. |
74 | * |
75 | */ |
76 | target_display?: string |
77 | |
78 | * List of projects slugs that the Notification Action is created for. |
79 | */ |
80 | projects?: string[] |
81 | [k: string]: unknown |
82 | } |
83 |
|