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}" } } }); }
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); }
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(); } } } }
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); }
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"; } } }
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); }
protected bool HasContextData(AlertSummary item) { return(item.ContextData != null); }
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"); }
public override void Alert(AlertSummary alertSummary) { _client.PostMessage(GetAlertOpenMessage(alertSummary)); }
public void SetAlert(AlertSummary alert) { Alert = alert; }
public abstract void Alert(AlertSummary alertSummary);
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))}```"); }
public override void Alert(AlertSummary alertSummary) { Console.WriteLine(GetAlertOpenMessage(alertSummary)); }
public override void Alert(AlertSummary alertSummary) { SendEmail($"Error rate alert for policy '{alertSummary.PolicyName}'", GetAlertOpenMessage(alertSummary)); }
public override void Alert(AlertSummary alertSummary) { Summary = alertSummary; AlertCount++; }