alerts.tsx 9.3 KB

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