alerts.tsx 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. import type {SchemaFormConfig} from 'sentry/views/settings/organizationIntegrations/sentryAppExternalForm';
  2. import type {IssueConfigField} from './integrations';
  3. export const enum IssueAlertActionType {
  4. SLACK = 'sentry.integrations.slack.notify_action.SlackNotifyServiceAction',
  5. NOTIFY_EMAIL = 'sentry.mail.actions.NotifyEmailAction',
  6. DISCORD = 'sentry.integrations.discord.notify_action.DiscordNotifyServiceAction',
  7. SENTRY_APP = 'sentry.rules.actions.notify_event_sentry_app.NotifyEventSentryAppAction',
  8. MS_TEAMS = 'sentry.integrations.msteams.notify_action.MsTeamsNotifyServiceAction',
  9. PAGER_DUTY = 'sentry.integrations.pagerduty.notify_action.PagerDutyNotifyServiceAction',
  10. OPSGENIE = 'sentry.integrations.opsgenie.notify_action.OpsgenieNotifyTeamAction',
  11. /**
  12. * Legacy integrations
  13. */
  14. NOTIFY_EVENT_ACTION = 'sentry.rules.actions.notify_event.NotifyEventAction',
  15. /**
  16. * Webhooks
  17. */
  18. NOTIFY_EVENT_SERVICE_ACTION = 'sentry.rules.actions.notify_event_service.NotifyEventServiceAction',
  19. /**
  20. * Ticket integrations
  21. */
  22. JIRA_CREATE_TICKET = 'sentry.integrations.jira.notify_action.JiraCreateTicketAction',
  23. JIRA_SERVER_CREATE_TICKET = 'sentry.integrations.jira_server.notify_action.JiraServerCreateTicketAction',
  24. GITHUB_CREATE_TICKET = 'sentry.integrations.github.notify_action.GitHubCreateTicketAction',
  25. GITHUB_ENTERPRISE_CREATE_TICKET = 'sentry.integrations.github_enterprise.notify_action.GitHubEnterpriseCreateTicketAction',
  26. AZURE_DEVOPS_CREATE_TICKET = 'sentry.integrations.vsts.notify_action.AzureDevopsCreateTicketAction',
  27. }
  28. export const enum IssueAlertConditionType {
  29. EVERY_EVENT = 'sentry.rules.conditions.every_event.EveryEventCondition',
  30. FIRST_SEEN_EVENT = 'sentry.rules.conditions.first_seen_event.FirstSeenEventCondition',
  31. REGRESSION_EVENT = 'sentry.rules.conditions.regression_event.RegressionEventCondition',
  32. REAPPEARED_EVENT = 'sentry.rules.conditions.reappeared_event.ReappearedEventCondition',
  33. EVENT_FREQUENCY = 'sentry.rules.conditions.event_frequency.EventFrequencyCondition',
  34. EVENT_UNIQUE_USER_FREQUENCY = 'sentry.rules.conditions.event_frequency.EventUniqueUserFrequencyCondition',
  35. EVENT_FREQUENCY_PERCENT = 'sentry.rules.conditions.event_frequency.EventFrequencyPercentCondition',
  36. HIGH_PRIORITY_ISSUE = 'sentry.rules.conditions.high_priority_issue.HighPriorityIssueCondition',
  37. }
  38. export const enum IssueAlertFilterType {
  39. AGE_COMPARISON = 'sentry.rules.filters.age_comparison.AgeComparisonFilter',
  40. ISSUE_OCCURRENCES = 'sentry.rules.filters.issue_occurrences.IssueOccurrencesFilter',
  41. ASSIGNED_TO = 'sentry.rules.filters.assigned_to.AssignedToFilter',
  42. LATEST_RELEASE = 'sentry.rules.filters.latest_release.LatestReleaseFilter',
  43. ISSUE_CATEGORY = 'sentry.rules.filters.issue_category.IssueCategoryFilter',
  44. EVENT_ATTRIBUTE = 'sentry.rules.filters.event_attribute.EventAttributeFilter',
  45. TAGGED_EVENT = 'sentry.rules.filters.tagged_event.TaggedEventFilter',
  46. LEVEL = 'sentry.rules.filters.level.LevelFilter',
  47. }
  48. interface IssueAlertFormFieldChoice {
  49. type: 'choice';
  50. choices?: Array<[key: string | number, name: string]>;
  51. initial?: string;
  52. placeholder?: string;
  53. }
  54. interface IssueAlertFormFieldString {
  55. type: 'string';
  56. initial?: string;
  57. placeholder?: string;
  58. }
  59. interface IssueAlertFormFieldNumber {
  60. type: 'number';
  61. initial?: string;
  62. placeholder?: number | string;
  63. }
  64. /**
  65. * The fields that are used to render the form for an action or condition.
  66. */
  67. type IssueAlertRuleFormField =
  68. | IssueAlertFormFieldChoice
  69. | IssueAlertFormFieldString
  70. | IssueAlertFormFieldNumber;
  71. /**
  72. * All issue alert configuration objects have these properties.
  73. */
  74. interface IssueAlertConfigBase {
  75. enabled: boolean;
  76. label: string;
  77. /**
  78. * "Send a Slack notification"
  79. */
  80. prompt?: string;
  81. }
  82. /**
  83. * Generic alert configuration. Do not add properties unless they are used by all filters.
  84. */
  85. interface IssueAlertGenericActionConfig extends IssueAlertConfigBase {
  86. id:
  87. | `${IssueAlertActionType.SLACK}`
  88. | `${IssueAlertActionType.NOTIFY_EMAIL}`
  89. | `${IssueAlertActionType.DISCORD}`
  90. | `${IssueAlertActionType.SENTRY_APP}`
  91. | `${IssueAlertActionType.MS_TEAMS}`
  92. | `${IssueAlertActionType.PAGER_DUTY}`
  93. | `${IssueAlertActionType.OPSGENIE}`
  94. | `${IssueAlertActionType.NOTIFY_EVENT_ACTION}`
  95. | `${IssueAlertActionType.NOTIFY_EVENT_SERVICE_ACTION}`;
  96. formFields?: Record<string, IssueAlertRuleFormField>;
  97. }
  98. /**
  99. * Currently filters and conditions are basically the same, just with different IDs.
  100. * Do not add properties unless they are used by all filters.
  101. */
  102. export interface IssueAlertGenericConditionConfig extends IssueAlertConfigBase {
  103. id: `${IssueAlertConditionType}` | `${IssueAlertFilterType}`;
  104. formFields?: Record<string, IssueAlertRuleFormField>;
  105. }
  106. /**
  107. * The object describing the options the slack action can use.
  108. */
  109. interface IssueAlertSlackConfig extends IssueAlertConfigBase {
  110. formFields: {
  111. channel: IssueAlertFormFieldString;
  112. channel_id: IssueAlertFormFieldString;
  113. tags: IssueAlertFormFieldString;
  114. workspace: IssueAlertFormFieldChoice;
  115. };
  116. id: `${IssueAlertActionType.SLACK}`;
  117. }
  118. interface IssueAlertTicketIntegrationConfig extends IssueAlertConfigBase {
  119. actionType: 'ticket';
  120. formFields: SchemaFormConfig;
  121. id:
  122. | `${IssueAlertActionType.JIRA_CREATE_TICKET}`
  123. | `${IssueAlertActionType.JIRA_SERVER_CREATE_TICKET}`
  124. | `${IssueAlertActionType.GITHUB_CREATE_TICKET}`
  125. | `${IssueAlertActionType.GITHUB_ENTERPRISE_CREATE_TICKET}`
  126. | `${IssueAlertActionType.AZURE_DEVOPS_CREATE_TICKET}`;
  127. link: string;
  128. ticketType: string;
  129. }
  130. interface IssueAlertSentryAppIntegrationConfig extends IssueAlertConfigBase {
  131. actionType: 'sentryapp';
  132. formFields: SchemaFormConfig;
  133. id: `${IssueAlertActionType.SENTRY_APP}`;
  134. sentryAppInstallationUuid: string;
  135. }
  136. /**
  137. * The actions that an organization has enabled and can be used to create an issue alert.
  138. */
  139. export type IssueAlertConfigurationAction =
  140. | IssueAlertGenericActionConfig
  141. | IssueAlertTicketIntegrationConfig
  142. | IssueAlertSentryAppIntegrationConfig
  143. | IssueAlertSlackConfig;
  144. /**
  145. * Describes the actions, filters, and conditions that can be used
  146. * to create an issue alert.
  147. */
  148. export interface IssueAlertConfiguration {
  149. actions: IssueAlertConfigurationAction[];
  150. conditions: IssueAlertGenericConditionConfig[];
  151. filters: IssueAlertGenericConditionConfig[];
  152. }
  153. /**
  154. * These templates that tell the UI how to render the action or condition
  155. * and what fields it needs
  156. */
  157. export interface IssueAlertRuleActionTemplate {
  158. enabled: boolean;
  159. id: string;
  160. label: string;
  161. actionType?: 'ticket' | 'sentryapp';
  162. formFields?:
  163. | {
  164. [key: string]: IssueAlertRuleFormField;
  165. }
  166. | SchemaFormConfig;
  167. link?: string;
  168. prompt?: string;
  169. sentryAppInstallationUuid?: string;
  170. ticketType?: string;
  171. }
  172. export type IssueAlertRuleConditionTemplate = IssueAlertRuleActionTemplate;
  173. /**
  174. * These are the action or condition data that the user is editing or has saved.
  175. */
  176. export interface IssueAlertRuleAction
  177. extends Omit<IssueAlertRuleActionTemplate, 'formFields' | 'enabled' | 'label'> {
  178. // These are the same values as the keys in `formFields` for a template
  179. [key: string]: any;
  180. dynamic_form_fields?: IssueConfigField[];
  181. }
  182. export type IssueAlertRuleCondition = Omit<
  183. IssueAlertRuleConditionTemplate,
  184. 'formFields' | 'enabled' | 'label'
  185. > & {
  186. dynamic_form_fields?: IssueConfigField[];
  187. } & {
  188. // These are the same values as the keys in `formFields` for a template
  189. [key: string]: number | string;
  190. };
  191. export interface UnsavedIssueAlertRule {
  192. /** When an issue matches [actionMatch] of the following */
  193. actionMatch: 'all' | 'any' | 'none';
  194. actions: IssueAlertRuleAction[];
  195. conditions: IssueAlertRuleCondition[];
  196. /** If that issue has [filterMatch] of these properties */
  197. filterMatch: 'all' | 'any' | 'none';
  198. filters: IssueAlertRuleCondition[];
  199. frequency: number;
  200. name: string;
  201. environment?: null | string;
  202. owner?: string | null;
  203. }
  204. // Issue-based alert rule
  205. export interface IssueAlertRule extends UnsavedIssueAlertRule {
  206. createdBy: {email: string; id: number; name: string} | null;
  207. dateCreated: string;
  208. id: string;
  209. projects: string[];
  210. snooze: boolean;
  211. status: 'active' | 'disabled';
  212. /**
  213. * Date alert is set to be disabled unless action is taken
  214. */
  215. disableDate?: string;
  216. disableReason?: 'noisy';
  217. errors?: {detail: string}[];
  218. lastTriggered?: string;
  219. /**
  220. * Set to true to opt out of the rule being automatically disabled
  221. * see also - status=disabled, disableDate, disableReason
  222. * TODO(scttcper): This is only used in the edit request and we should
  223. * move it to its own interface
  224. */
  225. optOutEdit?: boolean;
  226. snoozeCreatedBy?: string;
  227. snoozeForEveryone?: boolean;
  228. }
  229. // Project's alert rule stats
  230. export type ProjectAlertRuleStats = {
  231. count: number;
  232. date: string;
  233. };
  234. export enum MailActionTargetType {
  235. ISSUE_OWNERS = 'IssueOwners',
  236. TEAM = 'Team',
  237. MEMBER = 'Member',
  238. RELEASE_MEMBERS = 'ReleaseMembers',
  239. }
  240. export enum AssigneeTargetType {
  241. UNASSIGNED = 'Unassigned',
  242. TEAM = 'Team',
  243. MEMBER = 'Member',
  244. }
  245. export type NoteType = {
  246. mentions: string[];
  247. text: string;
  248. };
  249. /**
  250. * Used when determining what types of actions a rule has. The default action is "sentry.mail.actions.NotifyEmailAction"
  251. * while other actions can be integration (Slack, PagerDuty, etc) actions. We need to know this to determine what kind of muting
  252. * the alert should have.
  253. */
  254. export enum RuleActionsCategories {
  255. ALL_DEFAULT = 'all_default',
  256. SOME_DEFAULT = 'some_default',
  257. NO_DEFAULT = 'no_default',
  258. }