alerts.tsx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. JIRA_CREATE_TICKET = 'sentry.integrations.jira.notify_action.JiraCreateTicketAction',
  8. JIRA_SERVER_CREATE_TICKET = 'sentry.integrations.jira_server.notify_action.JiraServerCreateTicketAction',
  9. AZURE_DEVOPS_CREATE_TICKET = 'sentry.integrations.vsts.notify_action.AzureDevopsCreateTicketAction',
  10. GITHUB_CREATE_TICKET = 'sentry.integrations.github.notify_action.GitHubCreateTicketAction',
  11. SENTRY_APP = 'sentry.rules.actions.notify_event_sentry_app.NotifyEventSentryAppAction',
  12. MS_TEAMS = 'sentry.integrations.msteams.notify_action.MsTeamsNotifyServiceAction',
  13. PAGER_DUTY = 'sentry.integrations.pagerduty.notify_action.PagerDutyNotifyServiceAction',
  14. OPSGENIE = 'sentry.integrations.opsgenie.notify_action.OpsgenieNotifyTeamAction',
  15. }
  16. export const enum IssueAlertConditionType {
  17. EVERY_EVENT = 'sentry.rules.conditions.every_event.EveryEventCondition',
  18. FIRST_SEEN_EVENT = 'sentry.rules.conditions.first_seen_event.FirstSeenEventCondition',
  19. REGRESSION_EVENT = 'sentry.rules.conditions.regression_event.RegressionEventCondition',
  20. REAPPEARED_EVENT = 'sentry.rules.conditions.reappeared_event.ReappearedEventCondition',
  21. EVENT_FREQUENCY = 'sentry.rules.conditions.event_frequency.EventFrequencyCondition',
  22. EVENT_UNIQUE_USER_FREQUENCY = 'sentry.rules.conditions.event_frequency.EventUniqueUserFrequencyCondition',
  23. EVENT_FREQUENCY_PERCENT = 'sentry.rules.conditions.event_frequency.EventFrequencyPercentCondition',
  24. }
  25. export const enum IssueAlertFilterType {
  26. AGE_COMPARISON = 'sentry.rules.filters.age_comparison.AgeComparisonFilter',
  27. ISSUE_OCCURRENCES = 'sentry.rules.filters.issue_occurrences.IssueOccurrencesFilter',
  28. ASSIGNED_TO = 'sentry.rules.filters.assigned_to.AssignedToFilter',
  29. LATEST_RELEASE = 'sentry.rules.filters.latest_release.LatestReleaseFilter',
  30. ISSUE_CATEGORY = 'sentry.rules.filters.issue_category.IssueCategoryFilter',
  31. EVENT_ATTRIBUTE = 'sentry.rules.filters.event_attribute.EventAttributeFilter',
  32. TAGGED_EVENT = 'sentry.rules.filters.tagged_event.TaggedEventFilter',
  33. LEVEL = 'sentry.rules.filters.level.LevelFilter',
  34. }
  35. type IssueAlertRuleFormField =
  36. | {
  37. type: 'choice';
  38. choices?: [string, string][];
  39. initial?: string;
  40. placeholder?: string;
  41. }
  42. | {
  43. type: 'string';
  44. initial?: string;
  45. placeholder?: string;
  46. }
  47. | {
  48. type: 'number';
  49. initial?: string;
  50. placeholder?: number | string;
  51. };
  52. /**
  53. * These templates that tell the UI how to render the action or condition
  54. * and what fields it needs
  55. */
  56. export interface IssueAlertRuleActionTemplate {
  57. enabled: boolean;
  58. id: string;
  59. label: string;
  60. actionType?: 'ticket' | 'sentryapp';
  61. formFields?:
  62. | {
  63. [key: string]: IssueAlertRuleFormField;
  64. }
  65. | SchemaFormConfig;
  66. link?: string;
  67. prompt?: string;
  68. sentryAppInstallationUuid?: string;
  69. ticketType?: string;
  70. }
  71. export type IssueAlertRuleConditionTemplate = IssueAlertRuleActionTemplate;
  72. /**
  73. * These are the action or condition data that the user is editing or has saved.
  74. */
  75. export interface IssueAlertRuleAction
  76. extends Omit<IssueAlertRuleActionTemplate, 'formFields' | 'enabled' | 'label'> {
  77. // These are the same values as the keys in `formFields` for a template
  78. [key: string]: any;
  79. dynamic_form_fields?: IssueConfigField[];
  80. }
  81. export type IssueAlertRuleCondition = Omit<
  82. IssueAlertRuleConditionTemplate,
  83. 'formFields' | 'enabled' | 'label'
  84. > & {
  85. dynamic_form_fields?: IssueConfigField[];
  86. } & {
  87. // These are the same values as the keys in `formFields` for a template
  88. [key: string]: number | string;
  89. };
  90. export interface UnsavedIssueAlertRule {
  91. /** When an issue matches [actionMatch] of the following */
  92. actionMatch: 'all' | 'any' | 'none';
  93. actions: IssueAlertRuleAction[];
  94. conditions: IssueAlertRuleCondition[];
  95. /** If that issue has [filterMatch] of these properties */
  96. filterMatch: 'all' | 'any' | 'none';
  97. filters: IssueAlertRuleCondition[];
  98. frequency: number;
  99. name: string;
  100. environment?: null | string;
  101. owner?: string | null;
  102. }
  103. // Issue-based alert rule
  104. export interface IssueAlertRule extends UnsavedIssueAlertRule {
  105. createdBy: {email: string; id: number; name: string} | null;
  106. dateCreated: string;
  107. id: string;
  108. projects: string[];
  109. snooze: boolean;
  110. status: 'active' | 'disabled';
  111. /**
  112. * Date alert is set to be disabled unless action is taken
  113. */
  114. disableDate?: string;
  115. disableReason?: 'noisy';
  116. errors?: {detail: string}[];
  117. lastTriggered?: string;
  118. /**
  119. * Set to true to opt out of the rule being automatically disabled
  120. * see also - status=disabled, disableDate, disableReason
  121. * TODO(scttcper): This is only used in the edit request and we should
  122. * move it to its own interface
  123. */
  124. optOutEdit?: boolean;
  125. snoozeCreatedBy?: string;
  126. snoozeForEveryone?: boolean;
  127. }
  128. // Project's alert rule stats
  129. export type ProjectAlertRuleStats = {
  130. count: number;
  131. date: string;
  132. };
  133. export enum MailActionTargetType {
  134. ISSUE_OWNERS = 'IssueOwners',
  135. TEAM = 'Team',
  136. MEMBER = 'Member',
  137. RELEASE_MEMBERS = 'ReleaseMembers',
  138. }
  139. export enum AssigneeTargetType {
  140. UNASSIGNED = 'Unassigned',
  141. TEAM = 'Team',
  142. MEMBER = 'Member',
  143. }
  144. export type NoteType = {
  145. mentions: string[];
  146. text: string;
  147. };
  148. /**
  149. * Used when determining what types of actions a rule has. The default action is "sentry.mail.actions.NotifyEmailAction"
  150. * while other actions can be integration (Slack, PagerDuty, etc) actions. We need to know this to determine what kind of muting
  151. * the alert should have.
  152. */
  153. export enum RuleActionsCategories {
  154. ALL_DEFAULT = 'all_default',
  155. SOME_DEFAULT = 'some_default',
  156. NO_DEFAULT = 'no_default',
  157. }