public static string GetSlaTriggersViewItem(RestCommand command, int slaTriggerID)
        {
            SlaTriggersViewItem slaTriggersViewItem = SlaTriggersView.GetSlaTriggersViewItem(command.LoginUser, slaTriggerID);

            if (slaTriggersViewItem.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(slaTriggersViewItem.GetXml("SlaTriggersViewItem", true));
        }
        public static string GetSlaTriggersView(RestCommand command)
        {
            SlaTriggersView slaTriggersView = new SlaTriggersView(command.LoginUser);

            slaTriggersView.LoadByOrganizationID(command.Organization.OrganizationID);

            if (command.Format == RestFormat.XML)
            {
                return(slaTriggersView.GetXml("SlaTriggersView", "SlaTriggersViewItem", true, command.Filters));
            }
            else
            {
                throw new RestException(HttpStatusCode.BadRequest, "Invalid data format");
            }
        }
Ejemplo n.º 3
0
    public static string GetTriggerTable(int slaLevelID, int ticketTypeID)
    {
        SlaTriggersView triggers = new SlaTriggersView(UserSession.LoginUser);

        triggers.LoadByTicketType(UserSession.LoginUser.OrganizationID, slaLevelID, ticketTypeID);

        StringBuilder builder = new StringBuilder();

        builder.Append("<table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\"><thead><tr><th /><th /><th>Severity</th><th>Initial Response</th><th>Last Action</th><th>To Closed</th><th>Warning Time</th><th>Pause on Company Holidays</th><th>Business Hours</th><th>Days of Week</th><th>Start Time</th><th>End Time</th><th>Time Zone</th></tr></thead><tbody>");

        foreach (SlaTriggersViewItem item in triggers)
        {
            string s      = "<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td><td>{6}</td><td>{7}</td><td>{8}</td><td>{9}</td><td>{10}</td><td>{11}</td><td>{12}</td></tr>";
            string edit   = "<img src=\"../images/icons/Edit.png\" alt=\"Edit\" onclick=\"EditTrigger(" + item.SlaTriggerID + ");\" />";
            string delete = "<img src=\"../images/icons/Trash.png\" alt=\"Delete\" onclick=\"DeleteTrigger(" + item.SlaTriggerID + ");\" />";
            builder.Append(string.Format(s,
                                         UserSession.CurrentUser.IsSystemAdmin ? edit : "",
                                         UserSession.CurrentUser.IsSystemAdmin ? delete : "",
                                         item.Severity,
                                         DataUtils.MinutesToDisplayTime(item.TimeInitialResponse, "0"),
                                         DataUtils.MinutesToDisplayTime(item.TimeLastAction, "0"),
                                         DataUtils.MinutesToDisplayTime(item.TimeToClose, "0"),
                                         DataUtils.MinutesToDisplayTime(item.WarningTime, "0"),
                                         item.PauseOnHoliday.ToString(),
                                         (item.NoBusinessHours) ? "No" : (item.UseBusinessHours) ? "Account" : "Custom",
                                         (!item.NoBusinessHours && !item.UseBusinessHours) ? GetDays(item.Weekdays) : "",
                                         (!item.NoBusinessHours && !item.UseBusinessHours) ? (item.DayStart != null ? TimeZoneInfo.ConvertTimeFromUtc(item.DayStartUtc.Value, TimeZoneInfo.FindSystemTimeZoneById(item.TimeZone)).ToString("hh:mm tt") : "") : "",
                                         (!item.NoBusinessHours && !item.UseBusinessHours) ? (item.DayEnd != null ? TimeZoneInfo.ConvertTimeFromUtc(item.DayEndUtc.Value, TimeZoneInfo.FindSystemTimeZoneById(item.TimeZone)).ToString("hh:mm tt") : "") : "",
                                         (!item.NoBusinessHours && !item.UseBusinessHours) ? item.TimeZone : ""
                                         ));
        }

        if (triggers.Count < 1)
        {
            builder.Append("<tr><td colspan=\"13\" >There are no triggers to display.</td></tr>");
        }

        builder.Append("</tbody></table>");
        return(builder.ToString());
    }
Ejemplo n.º 4
0
        private void ProcessTicket(TicketSlaInfo ticket)
        {
            UpdateHealth();

            bool isPaused     = false;
            bool isPending    = false;
            int? slaTriggerId = null;

            Logs.WriteEvent("Getting SlaTicket record");
            SlaTicket slaTicket = SlaTickets.GetSlaTicket(LoginUser, ticket.TicketId);

            if (slaTicket != null)
            {
                isPaused     = ticket.IsSlaPaused(slaTicket.SlaTriggerId, ticket.OrganizationId);
                isPending    = slaTicket.IsPending;
                slaTriggerId = slaTicket.SlaTriggerId;
            }

            Logs.WriteEventFormat("IsPaused: {0}; IsPending: {1}", isPaused.ToString(), isPending.ToString());

            if (!isPaused && !isPending)
            {
                SlaTriggersView triggers = new SlaTriggersView(LoginUser);
                triggers.LoadByTicketId(ticket.TicketId);
                bool warnGroup = false;
                bool warnUser  = false;
                bool vioGroup  = false;
                bool vioUser   = false;

                foreach (SlaTriggersViewItem item in triggers)
                {
                    warnGroup = item.NotifyGroupOnWarning || warnGroup;
                    warnUser  = item.NotifyUserOnWarning || warnUser;
                    vioGroup  = item.NotifyGroupOnViolation || vioGroup;
                    vioUser   = item.NotifyUserOnViolation || vioUser;
                }

                SlaNotification notification = SlaNotifications.GetSlaNotification(LoginUser, ticket.TicketId);
                if (notification == null)
                {
                    notification          = (new SlaNotifications(LoginUser)).AddNewSlaNotification();
                    notification.TicketID = ticket.TicketId;
                }

                DateTime notifyTime;

                if (ticket.SlaViolationInitialResponse != null && ticket.SlaViolationInitialResponse <= DateTime.UtcNow)
                {
                    notifyTime = (DateTime)ticket.SlaViolationInitialResponse;
                    if (!IsTooOld(notifyTime))
                    {
                        if (notification.InitialResponseViolationDate == null || Math.Abs(((DateTime)notification.InitialResponseViolationDateUtc - notifyTime).TotalMinutes) > 5)
                        {
                            NotifyViolation(ticket.TicketId, vioUser, vioGroup, false, SlaViolationType.InitialResponse, notification, slaTriggerId);
                            notification.InitialResponseViolationDate = notifyTime;
                        }
                    }
                }
                else if (ticket.SlaWarningInitialResponse != null && ticket.SlaWarningInitialResponse <= DateTime.UtcNow)
                {
                    notifyTime = (DateTime)ticket.SlaWarningInitialResponse;

                    if (!IsTooOld(notifyTime))
                    {
                        if (notification.InitialResponseWarningDate == null || Math.Abs(((DateTime)notification.InitialResponseWarningDateUtc - notifyTime).TotalMinutes) > 5)
                        {
                            NotifyViolation(ticket.TicketId, warnUser, warnGroup, true, SlaViolationType.InitialResponse, notification, slaTriggerId);
                            notification.InitialResponseWarningDate = notifyTime;
                        }
                    }
                }


                if (ticket.SlaViolationLastAction != null && ticket.SlaViolationLastAction <= DateTime.UtcNow)
                {
                    notifyTime = (DateTime)ticket.SlaViolationLastAction;

                    if (!IsTooOld(notifyTime))
                    {
                        if (notification.LastActionViolationDate == null || Math.Abs(((DateTime)notification.LastActionViolationDateUtc - notifyTime).TotalMinutes) > 5)
                        {
                            NotifyViolation(ticket.TicketId, vioUser, vioGroup, false, SlaViolationType.LastAction, notification, slaTriggerId);
                            notification.LastActionViolationDate = notifyTime;
                        }
                    }
                }
                else if (ticket.SlaWarningLastAction != null && ticket.SlaWarningLastAction <= DateTime.UtcNow)
                {
                    notifyTime = (DateTime)ticket.SlaWarningLastAction;

                    if (!IsTooOld(notifyTime))
                    {
                        if (notification.LastActionWarningDate == null || Math.Abs(((DateTime)notification.LastActionWarningDateUtc - notifyTime).TotalMinutes) > 5)
                        {
                            NotifyViolation(ticket.TicketId, warnUser, warnGroup, true, SlaViolationType.LastAction, notification, slaTriggerId);
                            notification.LastActionWarningDate = notifyTime;
                        }
                    }
                }


                if (ticket.SlaViolationTimeClosed != null && ticket.SlaViolationTimeClosed <= DateTime.UtcNow)
                {
                    notifyTime = (DateTime)ticket.SlaViolationTimeClosed;

                    if (!IsTooOld(notifyTime))
                    {
                        if (notification.TimeClosedViolationDate == null || Math.Abs(((DateTime)notification.TimeClosedViolationDateUtc - notifyTime).TotalMinutes) > 5)
                        {
                            NotifyViolation(ticket.TicketId, vioUser, vioGroup, false, SlaViolationType.TimeClosed, notification, slaTriggerId);
                            notification.TimeClosedViolationDate = notifyTime;
                        }
                    }
                }
                else if (ticket.SlaWarningTimeClosed != null && ticket.SlaWarningTimeClosed <= DateTime.UtcNow)
                {
                    notifyTime = (DateTime)ticket.SlaWarningTimeClosed;

                    if (!IsTooOld(notifyTime))
                    {
                        if (notification.TimeClosedWarningDate == null || Math.Abs(((DateTime)notification.TimeClosedWarningDateUtc - notifyTime).TotalMinutes) > 5)
                        {
                            NotifyViolation(ticket.TicketId, warnUser, warnGroup, true, SlaViolationType.TimeClosed, notification, slaTriggerId);
                            notification.TimeClosedWarningDate = notifyTime;
                        }
                    }
                }

                notification.Collection.Save();
            }
        }