/// <summary>
        ///     Process an event asynchronously.
        /// </summary>
        /// <param name="e">event to process</param>
        /// <returns>
        ///     Task to wait on.
        /// </returns>
        public async Task HandleAsync(IMessageContext context, ReportAddedToIncident e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            _log.Info("ReportId: " + e.Report.Id);

            var settings = await _notificationsRepository.GetAllAsync(e.Incident.ApplicationId);

            foreach (var setting in settings)
            {
                if (setting.NewIncident != NotificationState.Disabled && e.Incident.ReportCount == 1)
                {
                    await CreateNotification(context, e, setting.AccountId, setting.NewIncident);
                }
                else if (setting.NewReport != NotificationState.Disabled)
                {
                    await CreateNotification(context, e, setting.AccountId, setting.NewReport);
                }
                else if (setting.ReopenedIncident != NotificationState.Disabled && e.IsReOpened)
                {
                    await CreateNotification(context, e, setting.AccountId, setting.ReopenedIncident);
                }
            }
        }
예제 #2
0
        /// <summary>
        ///     Process an event asynchronously.
        /// </summary>
        /// <param name="e">event to process</param>
        /// <returns>
        ///     Task to wait on.
        /// </returns>
        public async Task HandleAsync(IMessageContext context, ReportAddedToIncident e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            _log.Info("ReportId: " + e.Report.Id);

            var settings = await _notificationsRepository.GetAllAsync(e.Incident.ApplicationId);

            foreach (var setting in settings)
            {
                if (setting.NewIncident != NotificationState.Disabled && e.IsNewIncident == true)
                {
                    if (string.IsNullOrEmpty(e.EnvironmentName) ||
                        e.EnvironmentName.Equals("production", StringComparison.OrdinalIgnoreCase) ||
                        e.EnvironmentName.Equals("prod", StringComparison.OrdinalIgnoreCase))
                    {
                        await CreateNotification(context, e, setting.AccountId, setting.NewIncident);
                    }
                    else
                    {
                        _log.Debug("Error was new, but not for the production environment: " + e.EnvironmentName);
                    }
                }
                else if (setting.ReopenedIncident != NotificationState.Disabled && e.IsReOpened)
                {
                    await CreateNotification(context, e, setting.AccountId, setting.ReopenedIncident);
                }
            }
        }
        /// <inheritdoc/>
        public async Task HandleAsync(IMessageContext context, FeedbackAttachedToIncident e)
        {
            var settings = await _notificationsRepository.GetAllAsync(-1);

            var incident = await _incidentRepository.GetAsync(e.IncidentId);

            foreach (var setting in settings)
            {
                if (setting.UserFeedback == NotificationState.Disabled)
                {
                    continue;
                }

                var notificationEmail = await context.QueryAsync(new GetAccountEmailById(setting.AccountId));

                var config = _configStore.Load <BaseConfiguration>();

                var shortName = incident.Description.Length > 40
                    ? incident.Description.Substring(0, 40) + "..."
                    : incident.Description;

                if (string.IsNullOrEmpty(e.UserEmailAddress))
                {
                    e.UserEmailAddress = "unknown";
                }

                var incidentUrl = string.Format("{0}/discover/{1}/incident/{2}",
                                                config.BaseUrl.ToString().TrimEnd('/'),
                                                incident.ApplicationId,
                                                incident.Id);

                //TODO: Add more information
                var msg = new EmailMessage(notificationEmail);
                msg.Subject  = "New feedback: " + shortName;
                msg.TextBody = string.Format(@"Incident: {0}
Feedback: {0}/feedback
From: {1}

{2}
", incidentUrl, e.UserEmailAddress, e.Message);


                var emailCmd = new SendEmail(msg);
                await context.SendAsync(emailCmd);
            }
        }
예제 #4
0
        /// <inheritdoc/>
        public async Task HandleAsync(IMessageContext context, FeedbackAttachedToIncident e)
        {
            var settings = await _notificationsRepository.GetAllAsync(-1);

            var incident = await _incidentRepository.GetAsync(e.IncidentId);

            foreach (var setting in settings)
            {
                if (setting.UserFeedback == NotificationState.Disabled)
                {
                    continue;
                }

                var notificationEmail = await context.QueryAsync(new GetAccountEmailById(setting.AccountId));

                var shortName = incident.Description.Length > 40
                    ? incident.Description.Substring(0, 40) + "..."
                    : incident.Description;

                if (string.IsNullOrEmpty(e.UserEmailAddress))
                {
                    e.UserEmailAddress = "Unknown";
                }

                var incidentUrl = $"{_baseUrl}/discover/{incident.ApplicationId}/incident/{incident.Id}";

                if (setting.UserFeedback == NotificationState.Email)
                {
                    await SendEmail(context, e, notificationEmail, shortName, incidentUrl);
                }
                else if (setting.UserFeedback == NotificationState.BrowserNotification)
                {
                    var msg          = $@"Incident: {shortName}
From: {e.UserEmailAddress}
Application: {e.ApplicationName}
{e.Message}";
                    var notification = new Notification(msg)
                    {
                        Title = "New feedback",
                        Data  = new
                        {
                            viewFeedbackUrl = $"{incidentUrl}/feedback",
                            incidentId      = e.IncidentId,
                            applicationId   = incident.ApplicationId
                        },
                        Timestamp = DateTime.UtcNow,
                        Actions   = new List <NotificationAction>
                        {
                            new NotificationAction
                            {
                                Title  = "View",
                                Action = "viewFeedback"
                            }
                        }
                    };
                    try
                    {
                        await _notificationService.SendBrowserNotification(setting.AccountId, notification);
                    }
                    catch (Exception ex)
                    {
                        Err.Report(ex, new { notification, setting });
                    }
                }
            }
        }
        /// <summary>
        ///     Process an event asynchronously.
        /// </summary>
        /// <param name="e">event to process</param>
        /// <returns>
        ///     Task to wait on.
        /// </returns>
        public async Task HandleAsync(IMessageContext context, ReportAddedToIncident e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            var notificationSettings = (await _repository.GetAllAsync(e.Report.ApplicationId)).ToList();

            if (notificationSettings.All(x => x.ApplicationSpike == NotificationState.Disabled))
            {
                return;
            }

            var countToday = await CalculateSpike(e);

            if (countToday == null)
            {
                return;
            }

            var spike = await _spikeRepository.GetSpikeAsync(e.Incident.ApplicationId);

            spike?.IncreaseReportCount();

            var existed = spike != null;

            foreach (var setting in notificationSettings)
            {
                if (setting.ApplicationSpike == NotificationState.Disabled)
                {
                    continue;
                }

                if (spike != null && spike.HasAccount(setting.AccountId))
                {
                    continue;
                }

                if (spike == null)
                {
                    spike = new ErrorReportSpike(e.Incident.ApplicationId, 1);
                }

                spike.AddNotifiedAccount(setting.AccountId);

                if (setting.ApplicationSpike == NotificationState.Email)
                {
                    var msg = BuildEmail(e, setting, countToday);
                    var cmd = new SendEmail(msg);
                    await context.SendAsync(cmd);
                }
                else
                {
                    var notification = BuildBrowserNotification(e, countToday, setting);
                    try
                    {
                        await _notificationService.SendBrowserNotification(setting.AccountId, notification);
                    }
                    catch (Exception ex)
                    {
                        Err.Report(ex, new { setting, notification });
                    }
                }
            }

            if (existed)
            {
                await _spikeRepository.UpdateSpikeAsync(spike);
            }
            else
            {
                await _spikeRepository.CreateSpikeAsync(spike);
            }
        }
        /// <summary>
        ///     Process an event asynchronously.
        /// </summary>
        /// <param name="e">event to process</param>
        /// <returns>
        ///     Task to wait on.
        /// </returns>
        public async Task HandleAsync(IMessageContext context, ReportAddedToIncident e)
        {
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            _log.Info("ReportId: " + e.Report.Id);

            var url = _baseConfiguration.BaseUrl;
            var notificationSettings = (await _repository.GetAllAsync(e.Report.ApplicationId)).ToList();

            if (notificationSettings.All(x => x.ApplicationSpike == NotificationState.Disabled))
            {
                return;
            }

            var todaysCount = await CalculateSpike(e);

            if (todaysCount == null)
            {
                return;
            }

            var spike = await _spikeRepository.GetSpikeAsync(e.Incident.ApplicationId);

            if (spike != null)
            {
                spike.IncreaseReportCount();
            }

            var existed  = spike != null;
            var messages = new List <EmailMessage>();

            foreach (var setting in notificationSettings)
            {
                if (setting.ApplicationSpike == NotificationState.Disabled)
                {
                    continue;
                }

                if (spike != null && spike.HasAccount(setting.AccountId))
                {
                    continue;
                }

                if (spike == null)
                {
                    spike = new ErrorReportSpike(e.Incident.ApplicationId, 1);
                }

                spike.AddNotifiedAccount(setting.AccountId);
                var msg = new EmailMessage(setting.AccountId.ToString())
                {
                    Subject  = $"Spike detected for {e.Incident.ApplicationName} ({todaysCount} reports)",
                    HtmlBody =
                        $"We've detected a spike in incoming reports for application <a href=\"{url}/discover/{e.Incident.ApplicationId}/\">{e.Incident.ApplicationName}</a>\r\n" +
                        "\r\n" +
                        $"We've received {todaysCount.SpikeCount} reports so far. Day average is {todaysCount.DayAverage}\r\n" +
                        "\r\n" + "No further spike emails will be sent today for this application."
                };

                messages.Add(msg);
            }

            if (existed)
            {
                await _spikeRepository.UpdateSpikeAsync(spike);
            }
            else
            {
                await _spikeRepository.CreateSpikeAsync(spike);
            }

            foreach (var message in messages)
            {
                var sendEmail = new SendEmail(message);
                await context.SendAsync(sendEmail);
            }
        }