def send_incident_alert_notification(action, incident, new_status: IncidentStatus, metric_value=None): """ When a metric alert is triggered, send incident data to the SentryApp's webhook. :param action: The triggered `AlertRuleTriggerAction`. :param incident: The `Incident` for which to build a payload. :param metric_value: The value of the metric that triggered this alert to fire. If not provided we'll attempt to calculate this ourselves. :return: """ sentry_app = action.sentry_app organization = incident.organization metrics.incr("notifications.sent", instance=sentry_app.slug, skip_internal=False) try: install = SentryAppInstallation.objects.get( organization=organization.id, sentry_app=sentry_app, status=SentryAppInstallationStatus.INSTALLED, ) except SentryAppInstallation.DoesNotExist: logger.info( "metric_alert_webhook.missing_installation", extra={ "action": action.id, "incident": incident.id, "organization": organization.slug, "sentry_app_id": sentry_app.id, }, ) return app_platform_event = AppPlatformEvent( resource="metric_alert", action=INCIDENT_STATUS[new_status].lower(), install=install, data=build_incident_attachment(incident, new_status, metric_value), ) # Can raise errors if client returns >= 400 send_and_save_webhook_request( sentry_app, app_platform_event, ) # On success, record analytic event for Metric Alert Rule UI Component alert_rule_action_ui_component = find_alert_rule_action_ui_component( app_platform_event) if alert_rule_action_ui_component: analytics.record( "alert_rule_ui_component_webhook.sent", organization_id=organization.id, sentry_app_id=sentry_app.id, event=f"{app_platform_event.resource}.{app_platform_event.action}", )
def send_incident_alert_notification(action, incident, metric_value=None, method=None): """ When a metric alert is triggered, send incident data to the SentryApp's webhook. :param action: The triggered `AlertRuleTriggerAction`. :param incident: The `Incident` for which to build a payload. :param metric_value: The value of the metric that triggered this alert to fire. If not provided we'll attempt to calculate this ourselves. :return: """ sentry_app = action.sentry_app organization = incident.organization metrics.incr("notifications.sent", instance=sentry_app.slug, skip_internal=False) try: install = SentryAppInstallation.objects.get( organization=organization.id, sentry_app=sentry_app, status=SentryAppInstallationStatus.INSTALLED, ) except SentryAppInstallation.DoesNotExist: logger.info( "metric_alert_webhook.missing_installation", extra={ "action": action.id, "incident": incident.id, "organization": organization.slug, "sentry_app_id": sentry_app.id, }, ) return send_and_save_webhook_request( sentry_app, AppPlatformEvent( resource="metric_alert", action=INCIDENT_STATUS[incident_status_info( incident, metric_value, action, method)].lower(), install=install, data=build_incident_attachment(action, incident, metric_value, method), ), )
def _send_webhook(self): safe_urlread( send_and_save_webhook_request(self.sentry_app, self.request))
def _send_webhook(self): return send_and_save_webhook_request(self.sentry_app, self.request)