Exemplo n.º 1
0
        public static string GetSlaViolationHistoryItem(RestCommand command, int slaViolationHistoryID)
        {
            SlaViolationHistoryItem slaViolationHistoryItem = SlaViolationHistory.GetSlaViolationHistoryItem(command.LoginUser, slaViolationHistoryID);

            if (slaViolationHistoryItem.OrganizationID != command.Organization.OrganizationID)
            {
                throw new RestException(HttpStatusCode.Unauthorized);
            }
            return(slaViolationHistoryItem.GetXml("SlaViolationHistoryItem", true));
        }
Exemplo n.º 2
0
        private void NotifyViolation(int ticketID, bool useUser, bool useGroup, bool isWarning, SlaViolationType slaViolationType, SlaNotification notification, int?triggerId)
        {
            Users users = new Users(LoginUser);
            User  user  = null;

            Logs.WriteLine();
            Logs.WriteEvent("***** Processing TicketID: " + ticketID.ToString());
            TicketsViewItem ticket = TicketsView.GetTicketsViewItem(LoginUser, ticketID);

            if (ticket == null)
            {
                Logs.WriteEvent("Ticket is NULL, exiting");
                return;
            }

            //Since we are already re-loading the Ticket information we will check again if the SLAs still apply at this point
            string violationType      = "";
            bool   slaNotApplyAnymore = false;

            switch (slaViolationType)
            {
            case SlaViolationType.InitialResponse:
                violationType      = "Initial Response";
                slaNotApplyAnymore = ticket.SlaWarningInitialResponse == null;
                break;

            case SlaViolationType.LastAction:
                violationType      = "Last Action";
                slaNotApplyAnymore = ticket.SlaViolationLastAction == null;
                break;

            case SlaViolationType.TimeClosed:
                violationType      = "Time to Close";
                slaNotApplyAnymore = ticket.SlaViolationTimeClosed == null;
                break;

            default: break;
            }

            if (slaNotApplyAnymore)
            {
                Logs.WriteEvent($"The {((isWarning) ? "warning" : "violation")} for {violationType} does not apply anymore because the Ticket has been updated to satisfy this SLA while it was in process for the notification.");
            }
            else
            {
                if (!isWarning)
                {
                    SlaViolationHistoryItem history = (new SlaViolationHistory(LoginUser)).AddNewSlaViolationHistoryItem();
                    history.DateViolated  = DateTime.UtcNow;
                    history.GroupID       = ticket.GroupID;
                    history.UserID        = ticket.UserID;
                    history.ViolationType = slaViolationType;
                    history.TicketID      = ticket.TicketID;
                    history.SlaTriggerId  = triggerId;
                    history.Collection.Save();
                }

                Actions actions = new Actions(LoginUser);
                actions.LoadLatestByTicket(ticket.TicketID, false);

                ActionLogs.AddActionLog(LoginUser, ActionLogType.Update, ReferenceType.Tickets, ticket.TicketID, violationType + " SLA " + (isWarning ? "warning" : "violation") + " occurred");

                MailMessage message = EmailTemplates.GetSlaEmail(LoginUser, ticket, violationType, isWarning);


                if (ticket.GroupID != null && useGroup)
                {
                    users.LoadByGroupID((int)ticket.GroupID);
                }

                if (ticket.UserID != null && useUser && users.FindByUserID((int)ticket.UserID) == null)
                {
                    user = Users.GetUser(LoginUser, (int)ticket.UserID);
                }

                foreach (User item in users)
                {
                    if (Emails.IsEmailDisabled(LoginUser, item.UserID, "SLA"))
                    {
                        continue;
                    }
                    message.To.Add(new MailAddress(item.Email, item.FirstLastName));
                }

                if (user != null)
                {
                    if (!Emails.IsEmailDisabled(LoginUser, user.UserID, "SLA"))
                    {
                        message.To.Add(new MailAddress(user.Email, user.FirstLastName));
                        Logs.WriteEvent(string.Format("Adding Main User, Name:{0}  Email:{1}  UserID:{2}", user.FirstLastName, user.Email, user.UserID.ToString()));
                    }
                }

                if (message.To.Count > 0)
                {
                    Email email = Emails.AddEmail(LoginUser, ticket.OrganizationID, null, "Sla Message", message);
                    Logs.WriteEvent("Email Added (EmailID: " + email.EmailID.ToString() + ")", true);
                }

                try
                {
                    TimeZoneInfo tz  = null;
                    Organization org = Organizations.GetOrganization(LoginUser, ticket.OrganizationID);
                    if (org.TimeZoneID != null)
                    {
                        tz = System.TimeZoneInfo.FindSystemTimeZoneById(org.TimeZoneID);
                    }
                    if (tz == null)
                    {
                        Logs.WriteEvent("Timezone is null, using system's");
                        tz = System.TimeZoneInfo.Local;
                    }
                    Logs.WriteEvent(tz.DisplayName);
                    Logs.WriteEvent("Supports DLS: " + tz.SupportsDaylightSavingTime.ToString());
                    Logs.WriteEvent("Is DLS: " + tz.IsDaylightSavingTime(DateTime.UtcNow).ToString());
                    Logs.WriteEvent("UTC: " + DateTime.UtcNow.ToString());
                    Logs.WriteEvent(string.Format("NOTIFYING TicketID:{0}  TicketNumber:{1}  OrganizationID:{2} ", ticket.TicketID.ToString(), ticket.TicketNumber.ToString(), ticket.OrganizationID.ToString()));
                    Logs.WriteEvent(string.Format("User:{1}  Group:{2}  IsWarning:{3}  NoficationType:{4}", ticketID.ToString(), useUser.ToString(), useGroup.ToString(), isWarning.ToString(), slaViolationType));
                    Logs.WriteEvent("Ticket Data:");
                    Logs.WriteData(ticket.Row);
                    Logs.WriteEvent("Notification Data:");
                    Logs.WriteData(notification.Row);
                    Logs.WriteEvent("Organization Data:");
                    Logs.WriteData(org.Row);
                    Organizations customers = new Organizations(LoginUser);
                    customers.LoadByTicketID(ticket.TicketID);

                    foreach (Organization customer in customers)
                    {
                        Logs.WriteEvent("-- Customer: " + customer.Name);
                        if (customer.SlaLevelID != null)
                        {
                            SlaLevel level = SlaLevels.GetSlaLevel(LoginUser, (int)customer.SlaLevelID);
                            Logs.WriteEvent("SLA Level: " + level.Name);
                            SlaTriggers triggers = new SlaTriggers(LoginUser);
                            triggers.LoadByTicketTypeAndSeverity(level.SlaLevelID, ticket.TicketTypeID, ticket.TicketSeverityID);

                            foreach (SlaTrigger trigger in triggers)
                            {
                                Logs.WriteData(trigger.Row);
                            }
                        }
                        else
                        {
                            Logs.WriteEvent("No SLA Level Assigned to " + customer.Name);
                        }
                    }

                    if (org.InternalSlaLevelID != null)
                    {
                        Logs.WriteEvent("Internal SLA:");

                        SlaTriggers triggers = new SlaTriggers(LoginUser);
                        triggers.LoadByTicketTypeAndSeverity((int)org.InternalSlaLevelID, ticket.TicketTypeID, ticket.TicketSeverityID);
                        foreach (SlaTrigger trigger in triggers)
                        {
                            Logs.WriteData(trigger.Row);
                        }
                    }
                    else
                    {
                        Logs.WriteEvent("No Internal SLA");
                    }
                }
                catch (Exception ex)
                {
                    Logs.WriteEvent("Logging Exception:");
                    Logs.WriteException(ex);
                }
            }
        }