alerts.tsx 5.7 KB

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