alerts.tsx 5.8 KB

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