コード例 #1
0
        /// <summary>
        /// Детализация по компоненту - общее состояние
        /// </summary>
        public ActionResult ComponentDetailsState(Guid id)
        {
            var repository = CurrentAccountDbContext.GetComponentRepository();
            var component  = repository.GetById(id);

            var eventsMiniStatus    = ComponentsController.GetEventsMiniStatusModel(id, CurrentAccountDbContext);
            var unittestsMiniStatus = ComponentsController.GetUnittestsMiniStatusModel(CurrentUser.AccountId, id, CurrentAccountDbContext);
            var metricsMiniStatus   = ComponentsController.GetMetricsMiniStatusModel(CurrentUser.AccountId, id, CurrentAccountDbContext);
            var childsMiniStatus    = ComponentsController.GetChildsMiniStatusModel(CurrentUser.AccountId, id, CurrentAccountDbContext);

            var model = new ComponentDetailsStateModel()
            {
                Id                  = id,
                SystemName          = component.SystemName,
                Status              = component.ExternalStatus.Status,
                StatusEventId       = component.ExternalStatus.StatusEventId,
                StatusDuration      = component.ExternalStatus.GetDuration(MvcApplication.GetServerDateTime()),
                CanEdit             = CurrentUser.CanEditCommonData() && !component.IsRoot,
                IsEnabled           = component.Enable,
                EventsMiniStatus    = eventsMiniStatus,
                UnittestsMiniStatus = unittestsMiniStatus,
                MetricsMiniStatus   = metricsMiniStatus,
                ChildsMiniStatus    = childsMiniStatus
            };

            return(PartialView(model));
        }
コード例 #2
0
        public ActionResult ForEventTypeAnyComponentsByInterval(Guid eventTypeId, TimelineInterval interval)
        {
            var toDate   = MvcApplication.GetServerDateTime();
            var fromDate = TimelineHelper.IntervalToStartDate(toDate, interval);

            return(ForEventTypeAnyComponents(eventTypeId, fromDate, toDate));
        }
コード例 #3
0
        public ActionResult ForMetricByInterval(Guid id, EventCategory category, TimelineInterval interval)
        {
            var toDate   = MvcApplication.GetServerDateTime();
            var fromDate = TimelineHelper.IntervalToStartDate(toDate, interval);

            return(ForMetric(id, category, fromDate, toDate));
        }
コード例 #4
0
        /// <summary>
        /// Детализация по проверке - история
        /// </summary>
        public ActionResult UnittestDetailsHistory(Guid id)
        {
            var unitTestRepository = CurrentAccountDbContext.GetUnitTestRepository();
            var unittest           = unitTestRepository.GetById(id);

            var model = new UnittestDetailsHistoryModel()
            {
                Id = unittest.Id
            };

            var eventRepository = CurrentAccountDbContext.GetEventRepository();
            var statusEvents    = eventRepository.QueryAll(unittest.Id).Where(t => t.Category == EventCategory.UnitTestStatus).OrderByDescending(t => t.StartDate).Take(10).ToArray();

            var now = MvcApplication.GetServerDateTime();

            model.Statuses = statusEvents.Select(t => new UnittestDetailsHistoryModel.StatusModel()
            {
                EventId    = t.Id,
                StartDate  = t.StartDate,
                Duration   = t.GetDuration(now),
                Message    = t.GetUnitTestMessage(),
                Importance = t.Importance,
                Count      = t.Count
            }).ToArray();

            return(PartialView(model));
        }
コード例 #5
0
        /// <summary>
        /// Детализация по компоненту - проверки
        /// </summary>
        public ActionResult ComponentDetailsUnittests(Guid id)
        {
            var repository = CurrentAccountDbContext.GetUnitTestRepository();

            var unittests = repository.QueryAll()
                            .Where(t => t.ComponentId == id)
                            .Include("Type")
                            .Include("Bulb")
                            .ToArray();

            var now = MvcApplication.GetServerDateTime();

            var systemUnittests = unittests
                                  .Where(t => t.Type.IsSystem)
                                  .Select(t => new ComponentDetailsUnittestsModel.SystemUnittest()
            {
                Id             = t.Id,
                Status         = t.Bulb.Status,
                StatusDuration = t.Bulb.GetDuration(now),
                Name           = t.DisplayName,
                TypeName       = t.Type.DisplayName,
                LastResultDate = t.Bulb.EndDate,
                LastResult     = t.Bulb.GetUnitTestMessage(),
                Interval       = TimeSpan.FromSeconds(t.PeriodSeconds ?? 0),
                IsEnabled      = t.Enable
            })
                                  .OrderByDescending(t => t.Status)
                                  .ThenBy(t => t.Name)
                                  .ToArray();

            var userUnittests = unittests
                                .Where(t => !t.Type.IsSystem)
                                .Select(t => new ComponentDetailsUnittestsModel.UserUnittest()
            {
                Id             = t.Id,
                Status         = t.Bulb.Status,
                StatusDuration = t.Bulb.GetDuration(now),
                Name           = t.DisplayName,
                LastResultDate = t.Bulb.EndDate,
                LastResult     = t.Bulb.GetUnitTestMessage(),
                ActualDate     = t.Bulb.ActualDate,
                ActualInterval = t.Bulb.ActualDate - now,
                IsEnabled      = t.Enable
            })
                                .OrderByDescending(t => t.Status)
                                .ThenBy(t => t.Name)
                                .ToArray();

            var model = new ComponentDetailsUnittestsModel()
            {
                Id              = id,
                CanEdit         = CurrentUser.CanEditCommonData(),
                SystemUnittests = systemUnittests,
                UserUnittests   = userUnittests
            };

            return(PartialView(model));
        }
コード例 #6
0
        public PartialViewResult GetComponentsTreeItemDetails(Guid id)
        {
            var expandedItems = GetExpandedItemsFromCookie();
            var now           = MvcApplication.GetServerDateTime();
            var components    = GetSimplifiedComponentList();
            var component     = components.Single(t => t.Id == id);

            var model = GetTreeItemDetailsModel(component, now, expandedItems);

            return(PartialView("ComponentsTreeElementDetails", model));
        }
コード例 #7
0
        public JsonResult RunNowAjax(Guid id)
        {
            var client = GetDispatcherClient();

            client.SetUnitTestNextTime(CurrentUser.AccountId, new SetUnitTestNextTimeRequestData()
            {
                UnitTestId = id,
                NextTime   = MvcApplication.GetServerDateTime()
            }).Check();
            return(GetSuccessJsonResponse());
        }
コード例 #8
0
        /// <summary>
        /// Детализация по проверке - общее состояние
        /// </summary>
        public ActionResult UnittestDetailsState(Guid id)
        {
            var unitTestRepository = CurrentAccountDbContext.GetUnitTestRepository();
            var unittest           = unitTestRepository.GetById(id);

            var model = new UnittestDetailsStateModel()
            {
                Id                  = id,
                Status              = unittest.Bulb.Status,
                StatusEventId       = unittest.Bulb.StatusEventId,
                StatusDuration      = unittest.Bulb.GetDuration(MvcApplication.GetServerDateTime()),
                CanRun              = unittest.IsSystemType,
                CanEdit             = CurrentUser.CanEditCommonData(),
                IsEnabled           = unittest.Enable,
                TypeId              = unittest.TypeId,
                LastExecutionDate   = unittest.Bulb.EndDate,
                LastExecutionResult = unittest.Bulb.GetUnitTestMessage()
            };

            if (model.TypeId == SystemUnitTestTypes.HttpUnitTestType.Id)
            {
                model.RuleData = unittest.HttpRequestUnitTest?.Rules.FirstOrDefault()?.Url;
            }
            else if (model.TypeId == SystemUnitTestTypes.PingTestType.Id)
            {
                model.RuleData = unittest.PingRule?.Host;
            }
            else if (model.TypeId == SystemUnitTestTypes.DomainNameTestType.Id)
            {
                model.RuleData = unittest.DomainNamePaymentPeriodRule?.Domain;
            }
            else if (model.TypeId == SystemUnitTestTypes.SslTestType.Id)
            {
                model.RuleData = unittest.SslCertificateExpirationDateRule?.Url;
            }
            else if (model.TypeId == SystemUnitTestTypes.SqlTestType.Id)
            {
                model.RuleData = unittest.SqlRule?.Query;
            }

            var eventRepository          = CurrentAccountDbContext.GetEventRepository();
            var lastExecutionResultEvent = eventRepository.QueryAll(unittest.Id).Where(t => t.Category == EventCategory.UnitTestResult).OrderByDescending(t => t.StartDate).FirstOrDefault();

            if (lastExecutionResultEvent != null && lastExecutionResultEvent.Properties.Count > 0)
            {
                model.LastExecutionResultProperties = ExtentionPropertiesModel.Create(lastExecutionResultEvent);
            }

            return(PartialView(model));
        }
コード例 #9
0
        public PartialViewResult GetComponentsTree(
            ColorStatusSelectorValue color,
            Guid?componentTypeId = null,
            string search        = null)
        {
            var expandedItems = GetExpandedItemsFromCookie();
            var now           = MvcApplication.GetServerDateTime();
            var statuses      = color.GetSelectedMonitoringStatuses();
            var components    = GetSimplifiedComponentList();
            var root          = components.Single(t => t.Parent == null);

            var model = GetTreeItemModel(statuses, componentTypeId, search, root, now, expandedItems);

            return(PartialView("ComponentsTreeElement", model));
        }
コード例 #10
0
        public ActionResult GraphByInterval(Guid id, TimelineInterval interval)
        {
            var toDate   = MvcApplication.GetServerDateTime();
            var fromDate = TimelineHelper.IntervalToStartDate(toDate, interval);

            var metricRepository = CurrentAccountDbContext.GetMetricRepository();
            var metric           = metricRepository.GetById(id);

            var metricHistoryRepository = CurrentAccountDbContext.GetMetricHistoryRepository();
            var rows = metricHistoryRepository
                       .GetByPeriod(metric.ComponentId, fromDate, toDate, new[] { metric.MetricTypeId })
                       .OrderBy(t => t.BeginDate)
                       .ToArray();

            var model = GetCounterGraphDataModel(metric.MetricType, rows);

            return(PartialView("GraphPartial", model));
        }
コード例 #11
0
        public ActionResult DisableAjax(DisableDialogAjaxModel model)
        {
            if (model.Interval == DisableDialogAjaxModel.DisableInterval.Custom && !model.Date.HasValue)
            {
                ModelState.AddModelError("Date", "Пожалуйста, укажите дату");
            }

            if (!ModelState.IsValid)
            {
                return(PartialView("Dialogs/DisableDialogAjaxNew", model));
            }

            DateTime?date;

            if (model.Interval == DisableDialogAjaxModel.DisableInterval.Hour)
            {
                date = MvcApplication.GetServerDateTime().AddHours(1);
            }
            else if (model.Interval == DisableDialogAjaxModel.DisableInterval.Day)
            {
                date = MvcApplication.GetServerDateTime().AddDays(1);
            }
            else if (model.Interval == DisableDialogAjaxModel.DisableInterval.Week)
            {
                date = MvcApplication.GetServerDateTime().AddDays(7);
            }
            else
            {
                date = model.Date;
            }

            var client = GetDispatcherClient();
            var data   = new SetMetricDisableRequestData()
            {
                Comment  = model.Comment,
                ToDate   = date,
                MetricId = model.Id
            };

            client.SetMetricDisable(CurrentUser.AccountId, data).Check();

            return(GetSuccessJsonResponse());
        }
コード例 #12
0
        public ActionResult Index(TimelineInterval?interval)
        {
            var userSettingService = CurrentAccountDbContext.GetUserSettingService();
            var savedInterval      = (TimelineInterval?)userSettingService.ComponentHistoryInterval(CurrentUser.Id) ?? TimelineInterval.Hour;

            if (interval != null)
            {
                userSettingService.ComponentHistoryInterval(CurrentUser.Id, (int)interval.Value);
                DbContext.SaveChanges();
            }

            var model = new IndexModel()
            {
                Interval = interval ?? savedInterval
            };

            model.ToDate   = MvcApplication.GetServerDateTime();
            model.FromDate = TimelineHelper.IntervalToStartDate(model.ToDate, model.Interval);

            return(View(model));
        }
コード例 #13
0
        /// <summary>
        /// Детализация по компоненту - метрики
        /// </summary>
        public ActionResult ComponentDetailsMetrics(Guid id)
        {
            var repository = CurrentAccountDbContext.GetMetricRepository();

            var metrics = repository.QueryAll()
                          .Where(t => t.ComponentId == id)
                          .Include("MetricType")
                          .Include("Bulb")
                          .ToArray();

            var now = MvcApplication.GetServerDateTime();

            var metricInfos = metrics
                              .Select(t => new ComponentDetailsMetricsModel.MetricInfo()
            {
                Id             = t.Id,
                Status         = t.Bulb.Status,
                StatusDuration = t.Bulb.GetDuration(now),
                Name           = t.MetricType.DisplayName,
                LastResultDate = t.Bulb.EndDate,
                LastResult     = t.Value,
                ActualDate     = t.Bulb.ActualDate,
                ActualInterval = t.Bulb.ActualDate - now,
                IsEnabled      = t.Enable,
                HasSignal      = t.Bulb.HasSignal
            })
                              .OrderByDescending(t => t.Status)
                              .ThenBy(t => t.Name)
                              .ToArray();

            var model = new ComponentDetailsMetricsModel()
            {
                Id      = id,
                CanEdit = CurrentUser.CanEditCommonData(),
                Metrics = metricInfos
            };

            return(PartialView(model));
        }
コード例 #14
0
        /// <summary>
        /// Детализация по метрике - общее состояние
        /// </summary>
        public ActionResult MetricDetailsState(Guid id)
        {
            var repository = CurrentAccountDbContext.GetMetricRepository();
            var metric     = repository.GetById(id);
            var now        = MvcApplication.GetServerDateTime();

            var model = new MetricDetailsStateModel()
            {
                Id             = metric.Id,
                Status         = metric.Bulb.Status,
                StatusEventId  = metric.Bulb.StatusEventId,
                StatusDuration = metric.Bulb.GetDuration(now),
                LastResultDate = metric.Bulb.EndDate,
                Value          = metric.Value,
                ActualDate     = metric.Bulb.ActualDate,
                ActualInterval = metric.Bulb.ActualDate - now,
                IsEnabled      = metric.Enable,
                HasSignal      = metric.Bulb.HasSignal,
                CanEdit        = CurrentUser.CanEditCommonData()
            };

            return(PartialView(model));
        }
コード例 #15
0
        public ActionResult QuickSetMobilePhone(QuickSetMobilePhoneModel model)
        {
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            var userRepository = CurrentAccountDbContext.GetUserRepository();
            var user           = userRepository.GetById(CurrentUser.Id);

            userRepository.AddContactToUser(user.Id, UserContactType.MobilePhone, model.Phone, MvcApplication.GetServerDateTime());

            var client = GetDispatcherClient();

            var response = client.CreateSubscription(CurrentUser.AccountId, new CreateSubscriptionRequestData()
            {
                UserId    = CurrentUser.Id,
                Channel   = SubscriptionChannel.Sms,
                Object    = SubscriptionObject.Default,
                IsEnabled = true
            });

            response.Check();

            this.SetTempMessage(TempMessageType.Success, "Мобильный телефон успешно добавлен. Теперь вы будете получать уведомления по SMS!");

            return(Redirect(model.ReturnUrl ?? Url.Action("Start")));
        }
コード例 #16
0
        public ActionResult AddContact(UserContactModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var repository = CurrentAccountDbContext.GetUserRepository();
            var userId     = model.UserId;
            var user       = repository.GetById(userId);

            if (!CurrentUser.CanManageAccount() && user.Id != CurrentUser.Id)
            {
                throw new NoAccessToPageException();
            }

            var contact = repository.AddContactToUser(user.Id, model.Type, model.Value, MvcApplication.GetServerDateTime());

            if (model.ModalMode)
            {
                return(PartialView("UserContactRow", contact));
            }

            return(Redirect(model.ReturnUrl));
        }
コード例 #17
0
        public PartialViewResult ShowTimelinesEventsPartial(Guid id, TimelineInterval interval, bool all = false)
        {
            var toDate   = MvcApplication.GetServerDateTime();
            var fromDate = TimelineHelper.IntervalToStartDate(toDate, interval);

            var eventTypeRepository = CurrentAccountDbContext.GetEventTypeRepository();
            var eventTypes          = eventTypeRepository.QueryAll().Select(t => new { t.Id, t.DisplayName }).ToDictionary(t => t.Id, t => t);
            var eventRepository     = CurrentAccountDbContext.GetEventRepository();

            var query = eventRepository.QueryAllByAccount()
                        .Where(t => t.OwnerId == id && t.StartDate <= toDate && t.ActualDate >= fromDate);

            if (all)
            {
                query = query.Where(t => t.Category == EventCategory.ApplicationError || t.Category == EventCategory.ComponentEvent);
            }
            else
            {
                query = query.Where(t => t.Category == EventCategory.ApplicationError);
            }

            var events = query
                         .GroupBy(t => t.EventTypeId)
                         .Select(t => new
            {
                Id          = t.Key,
                Importance  = t.Max(z => z.Importance),
                Count       = t.Sum(z => z.Count),
                LastMessage = t.OrderByDescending(z => z.StartDate).FirstOrDefault().Message
            })
                         .ToArray();

            var model = new ComponentShowTimelinesGroupModel()
            {
                FromDate   = fromDate,
                ToDate     = toDate,
                HideUptime = true,
                Items      = events
                             .Select(t => new
                {
                    Id          = t.Id,
                    Importance  = t.Importance,
                    Count       = t.Count,
                    Name        = eventTypes[t.Id].DisplayName,
                    LastMessage = t.LastMessage
                })
                             .OrderByDescending(t => t.Importance)
                             .ThenByDescending(t => t.Count)
                             .ThenBy(t => t.Name)
                             .Take(MaxEventTimelineCount)
                             .Select(t => new ComponentShowTimelinesGroupItemModel()
                {
                    Action      = "ForEventType",
                    Category    = null,
                    OwnerId     = id,
                    EventTypeId = t.Id,
                    Importance  = t.Importance,
                    Name        = t.Name,
                    Count       = t.Count,
                    Comment     = t.LastMessage,
                    Url         = Url.Action("Show", "EventTypes", new { Id = t.Id })
                })
                             .ToArray()
            };

            return(PartialView("~/Views/Components/ShowTimelinesPartialGroup.cshtml", model));
        }