alerts.tsx 6.0 KB

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