Exemplo n.º 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());
        }
Exemplo n.º 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());
        }
Exemplo n.º 3
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());
        }