示例#1
0
        private IEnumerable <Message> Probe(TaskTimerElapsed arg)
        {
            if (!Enabled)
            {
                return(JanelObserver.Success());
            }

            try {
                var failureMessage = "Alert !\n";

                using (var client = new HttpClient()) {
                    client.Timeout = TimeSpan.FromSeconds(TimeOutInSeconds);
                    client.DefaultRequestHeaders.Add("x-probing", "janel");

                    using (var request = client.GetAsync(WebSite).Result) {
                        switch (ProbeType)
                        {
                        case WebProbeType.HttpCode200:

                            if (request.StatusCode != HttpStatusCode.OK)
                            {
                                Retries++;
                            }
                            else
                            {
                                Retries = 0;
                            }
                            break;

                        case WebProbeType.ContentInPage:
                            var content = request.Content.ReadAsStringAsync().Result;

                            if (!content.Contains(PageContent))
                            {
                                Retries++;
                            }
                            else
                            {
                                Retries = 0;
                            }

                            break;
                        }
                    }
                }

                if (Enabled && Retries >= RetriesBeforeFailure)
                {
                    _alertManager.LogAlert(failureMessage, WebSite, Enum.GetName(typeof(WebProbeType), ProbeType), "", SeverityType.Moderate);
                }
            }
            catch (Exception e) {
                _alertManager.LogAlert($"Unable to probe {WebSite}. {e.Message}", WebSite, Enum.GetName(typeof(WebProbeType), ProbeType), "", SeverityType.Moderate);
            }

            return(JanelObserver.Success());
        }
示例#2
0
        private IEnumerable <Message> Probe(TaskTimerElapsed arg)
        {
            if (!Enabled)
            {
                return(JanelObserver.Success());
            }

            try {
                using (var authentication = new WindowsLogin(UserName, Domain, Password)) {
                    var failedServices = new List <string>();

                    WindowsIdentity.RunImpersonated(authentication.Identity.AccessToken, () => {
                        foreach (var service in Services)
                        {
                            var windowsService = new ServiceController(service, MachineName);

                            if (windowsService.Status != ServiceControllerStatus.Running)
                            {
                                failedServices.Add(service);
                            }
                        }
                    });

                    if (Enabled && failedServices.Any() && Retries++ >= RetriesBeforeFailure)
                    {
                        _alertManager.LogAlert($"Alert !\n\nServices not running : \n{string.Join("\n- ", failedServices)}", "Windows Services", MachineName, "", SeverityType.Critical);
                    }
                    else if (!Enabled || !failedServices.Any())
                    {
                        Retries = 0;
                    }
                }
            }
            catch (Exception exc) {
                _alertManager.LogAlert($"Unable to probe services of {MachineName}. {exc.Message}", MachineName, "", "", SeverityType.Moderate);
            }

            return(JanelObserver.Success());
        }
示例#3
0
        private IEnumerable <Message> ValidateSentNotifications(TaskTimerElapsed arg)
        {
            var notificationsToRemove = new List <Notification>();

            foreach (var notification in _ongoingNotifications)
            {
                if (notification.MessagesSent.Last().SentOn.AddMinutes(3) >= _dateTimeManager.GetNow())
                {
                    //3 minutes elapsed. Need to do something
                    if (notification.MessagesSent.Count >= 3)
                    {
                        //Responsible never responded
                        notificationsToRemove.Add(notification);
                        JanelObserver.EventManager.Dispatch(new NotificationNotResponded(notification));
                    }
                    else
                    {
                        //Retry sending a message
                        var sendItTo = notification.MessagesSent.Last().SentTo;
                        var nbMessageSentToThisGuy = notification.MessagesSent.Where(m => m.SentTo == sendItTo).Count();

                        var communicationType = nbMessageSentToThisGuy <= sendItTo.PreferedCommunications.Count ?
                                                sendItTo.PreferedCommunications.ElementAt(nbMessageSentToThisGuy) :
                                                sendItTo.PreferedCommunications.Last();

                        SendNotificationWithAcknowledge(_dateTimeManager.GetNow(), sendItTo, communicationType, notification.Message, notification, null);

                        _janelUnitOfWork.NotificationRepository.Update(notification);
                    }
                }
            }

            if (notificationsToRemove.Any())
            {
                notificationsToRemove.ForEach(n => _ongoingNotifications.Remove(n));
            }

            return(JanelObserver.Success());
        }
示例#4
0
        private IEnumerable <Message> ValidatePendingAlerts(TaskTimerElapsed arg)
        {
            foreach (var alert in _ongoingAlerts)
            {
                switch (alert.Status)
                {
                case StatusType.Acknowledge:
                case StatusType.Fixed:
                case StatusType.Transferring:
                    if (alert.UpdatedAt.AddMinutes(60) >= _dateTimeManager.GetNow())
                    {
                        EscalateAlert(alert);
                    }
                    break;

                case StatusType.Escalated:
                    if (alert.UpdatedAt.AddMinutes(60) >= _dateTimeManager.GetNow())
                    {
                        //In Deep shit !
                        var newResponsible = _scheduleManager.GetNextPersonInCharge(alert.Responsible);

                        alert.Status       = StatusType.Transferring;
                        alert.Description += $"\n\nAlert were escalated but was still not responded.";
                        alert.UpdatedAt    = _dateTimeManager.GetNow();

                        _unitOfWork.AlertRepository.Update(alert);

                        JanelObserver.EventManager.Dispatch(new AlertChanged(alert, StatusType.Transferring.ToString()));
                        JanelObserver.EventManager.Dispatch(new AlertReceived(alert, newResponsible));
                    }
                    break;
                }
            }

            return(JanelObserver.Success());
        }
示例#5
0
        private IEnumerable <Message> Probe(TaskTimerElapsed arg)
        {
            _alertManager.LogAlert("Timeout from Monitis", "www.robotshop.com", "EC2BLABLA", "127.0.0.1", SeverityType.Critical);

            return(JanelObserver.Success());
        }