private Email MapToEmail(TeamMemberViewModel userModel, AlertSummary alertSummary, string hashedAccountId, string accountName)
 {
     return(new Email
     {
         RecipientsAddress = userModel.Email,
         TemplateId = "EmployerAlertSummaryNotification",
         ReplyToAddress = "*****@*****.**",
         Subject = "Items for your attention: apprenticeship service",
         SystemId = "x",
         Tokens =
             new Dictionary <string, string>
         {
             { "name", userModel.Name },
             { "total_count_text", alertSummary.TotalCount == 1
                         ? "is 1 apprentice"
                         : $"are {alertSummary.TotalCount} apprentices" },
             { "account_name", accountName },
             { "need_needs", alertSummary.TotalCount > 1 ? "need" :"needs" },
             { "changes_for_review", ChangesForReviewText(alertSummary.ChangesForReview) },
             { "requested_changes", RestartRequestText(alertSummary.RestartRequestCount) },
             { "link_to_mange_apprenticeships", $"accounts/{hashedAccountId}/apprentices/manage/all?RecordStatus=ChangesForReview&RecordStatus=ChangeRequested" },
             { "link_to_unsubscribe", $"/settings/notifications/unsubscribe/{hashedAccountId}" }
         }
     });
 }
Exemplo n.º 2
0
        public AlertSummary[] GetAlertSummary()
        {
            AlertSummary[] alerts = new AlertSummary[AlertDataGridView.Rows.Count - 1];
            for (int index = 1; index < AlertDataGridView.Rows.Count; index++)
            {
                DataGridViewRow alertRow = AlertDataGridView.Rows[index];

                alerts[index]             = new AlertSummary();
                alerts[index].AlertType   = alertRow.Cells[0].GetValue();
                alerts[index].Description = alertRow.Cells[1].GetValue();
                alerts[index].ExpiryDate  = Convert.ToDateTime(alertRow.Cells[2].GetValue());
            }

            return(alerts);
        }
Exemplo n.º 3
0
        protected void AlertGridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            GridViewRow row = e.Row;

            if (AlertGridView.EditIndex != e.Row.RowIndex)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    AlertSummary alert = e.Row.DataItem as AlertSummary;
                    Label        level = e.Row.FindControl("Level") as Label;

                    if (level != null && alert != null)
                    {
                        if (alert.LevelIsErrorOrCritical)
                        {
                            level.ForeColor = Color.Red;
                        }
                        level.Text = alert.Level;

                        LinkButton appLogLink = e.Row.FindControl("AppLogLink") as LinkButton;


                        int    timeRange = int.Parse(ConfigurationManager.AppSettings["AlertTimeRange"]);
                        string hostname  = GetHostName(alert.Source);

                        DateTime startTime = alert.InsertTime.AddSeconds(-timeRange / 2);
                        DateTime endTime   = alert.InsertTime.AddSeconds(timeRange / 2);
                        appLogLink.PostBackUrl = ImageServerConstants.PageURLs.ApplicationLog + "?From=" +
                                                 HttpUtility.UrlEncode(startTime.ToString("yyyy-MM-dd") + " " +
                                                                       startTime.ToString("HH:mm:ss")) + "&To=" +
                                                 HttpUtility.UrlEncode(endTime.ToString("yyyy-MM-dd") + " " +
                                                                       endTime.ToString("HH:mm:ss")) +
                                                 "&HostName=" + hostname;
                    }

                    if (alert.ContextData != null)
                    {
                        AlertHoverPopupDetails ctrl =
                            Page.LoadControl("AlertHoverPopupDetails.ascx") as AlertHoverPopupDetails;

                        ctrl.Alert = alert;

                        e.Row.FindControl("DetailsHoverPlaceHolder").Controls.Add(ctrl);
                        ctrl.DataBind();
                    }
                }
            }
        }
Exemplo n.º 4
0
        private static AlertSummary CreateAlertSummary(ElmahIoResponse elmahResponse, string policyName, string logId)
        {
            var alertSummary = new AlertSummary
            {
                TotalCount   = elmahResponse.Total,
                PolicyName   = policyName,
                LogId        = logId,
                MostFrequent = elmahResponse.Messages.GroupBy(p => p.Type)
                               .OrderByDescending(p => p.Count()).Take(5)
                               .ToDictionary(p => p.Key, p => p.Count()),
                SeverityCount = elmahResponse.Messages.GroupBy(p => p.Severity)
                                .OrderByDescending(p => p.Count())
                                .ToDictionary(p => p.Key, p => p.Count())
            };

            return(alertSummary);
        }
Exemplo n.º 5
0
 private static void SetTimeDiffString(ElmahIoResponse elmahResponse, AlertSummary alertSummary)
 {
     if (elmahResponse.Messages.Any())
     {
         var timeDiff = (DateTime.UtcNow - elmahResponse.Messages.Min(p => p.DateTime));
         if (timeDiff.TotalSeconds < 60)
         {
             alertSummary.FirstErrorTimeDiffString = (int)timeDiff.TotalSeconds + " seconds";
         }
         else
         {
             alertSummary.FirstErrorTimeDiffString =
                 (int)(DateTime.UtcNow - elmahResponse.Messages.Min(p => p.DateTime)).TotalMinutes +
                 " minutes";
         }
     }
 }
Exemplo n.º 6
0
        public List <AlertSummary> GetAllActiveAlertsForCameraKey(string cameraKey)
        {
            int cameraId = _dbQueryService.GetCameraIdFromKey(cameraKey);
            List <DatabaseAlert> dbAlerts  = _dbQueryService.GetAlertsByCameraId(cameraId);
            List <AlertSummary>  alertList = new List <AlertSummary>();

            foreach (var dbAlert in dbAlerts)
            {
                if (dbAlert.DisabledUntil.GetValueOrDefault(DateTime.MinValue) < DateTime.Now &&
                    (dbAlert.StartTime.IsNullOrEmpty() || dbAlert.StartTime.ToDateTime() < DateTime.Now) &&
                    (dbAlert.EndTime.IsNullOrEmpty() || dbAlert.EndTime.ToDateTime() > DateTime.Now))
                {
                    AlertSummary alertSummary = new AlertSummary(dbAlert);
                    alertSummary.NeedsImage = DoesAlertNeedsFrameImage(dbAlert);
                    alertList.Add(alertSummary);
                }
            }

            return(alertList);
        }
Exemplo n.º 7
0
 protected bool HasContextData(AlertSummary item)
 {
     return(item.ContextData != null);
 }
Exemplo n.º 8
0
 public override void Alert(AlertSummary alertSummary)
 {
     SendEmail("Daily Elmah summary",
               $"There were {alertSummary.TotalCount} new errors in the last 24 hours.{Environment.NewLine}https://elmah.io/errorlog/search/?logId={alertSummary.LogId}#searchTab");
 }
Exemplo n.º 9
0
 public override void Alert(AlertSummary alertSummary)
 {
     _client.PostMessage(GetAlertOpenMessage(alertSummary));
 }
 public void SetAlert(AlertSummary alert)
 {
     Alert = alert;
 }
Exemplo n.º 11
0
 public abstract void Alert(AlertSummary alertSummary);
Exemplo n.º 12
0
 protected virtual string GetAlertOpenMessage(AlertSummary alertSummary)
 {
     return($"Error rate for alert policy `{alertSummary.PolicyName}` is higher than normal with 20 logs in the last {alertSummary.FirstErrorTimeDiffString}. https://elmah.io/errorlog/search/?logId={alertSummary.LogId}#searchTab{Environment.NewLine}{Environment.NewLine}Frequent errors:```{Environment.NewLine}{string.Join(Environment.NewLine, alertSummary.MostFrequent.Select(p => p.Value + " x " + p.Key))}```");
 }
Exemplo n.º 13
0
 public override void Alert(AlertSummary alertSummary)
 {
     Console.WriteLine(GetAlertOpenMessage(alertSummary));
 }
Exemplo n.º 14
0
 public override void Alert(AlertSummary alertSummary)
 {
     SendEmail($"Error rate alert for policy '{alertSummary.PolicyName}'", GetAlertOpenMessage(alertSummary));
 }
Exemplo n.º 15
0
 public override void Alert(AlertSummary alertSummary)
 {
     Summary = alertSummary;
     AlertCount++;
 }