public void Execute()
        {
            try
            {
                var host = Settings.GetSetting("SenseNodeStatusMonitor.HostName", "localhost");
                if ((_senseApiSupport == null) || (_senseApiSupport.Host != host))
                {
                    _senseApiSupport = Settings.GetBool("SenseNodeStatusMonitor.UseHttp", false) ?
                                       SenseApiSupport.CreateHttp(host) : SenseApiSupport.Create(host);
                }

                SenseEnums senseEnums = new SenseEnums(_senseApiSupport);

                var serviceStatuses = GetServiceStatusFull(senseEnums);
                foreach (ServiceStatusFullDto dto in serviceStatuses)
                {
                    var key = dto.ServerNodeHostName + "_" + dto.ServiceTypeId;
                    _groupedNotifyer.AddIfMissing(key, $"Node down {dto.ServiceTypeName} on {dto.ServerNodeHostName}", "");
                    _groupedNotifyer.Analyze(key, dto.ServiceStateId);
                }
                _groupedNotifyer.AnalyzeRoundFinished();
            }
            catch (Exception ex)
            {
                _senseApiSupport = null;
                Log.To.Main.AddException($"Failed executing {MonitorName}", ex);
            }
        }
Exemple #2
0
        public void PerformMonitoringForMachine()
        {
            HashSet <string> observedKeys = new HashSet <string>();
            //_hasTriggerdState = false;

            //IEnumerable<PeformanceCounterSetting> peformanceCounterSettings = GetPeformanceCounterSettings(_machineName);
            var keys = Settings.GetSetting($"PerformanceMonitor.{_machineName}.PerfCounters").Split(',').ToList();

            keys.ForEach(p =>
            {
                var setting = GetPeformanceCounterSettings(_machineName, p);
                var key     = $"PerformanceMonitor.{_machineName}.{p}";
                _groupedNotifyer.AddIfMissing(key, $"Performance monitor detected that {setting.Name} on {_machineName} is looking bad for {setting.Duration} sec.", key);
                _groupedNotifyer.Analyze(key, CheckPerformanceCounter(setting));
                observedKeys.Add(GetCounterKey(setting));
            });
            _groupedNotifyer.AnalyzeRoundFinished();
            //foreach (var setting in peformanceCounterSettings)
            //{
            //    var key = $"PerformanceMonitor.{_machineName}";
            //    _groupedNotifyer.AddIfMissing(key, $"Performance monitor detected that {setting.Name} on {_machineName} is looking bad for {setting.Duration} sec.");
            //    _groupedNotifyer.Analyze(key, CheckPerformanceCounter(setting));
            //    observedKeys.Add(GetCounterKey(setting));
            //}

            //cleanup
            RemoveUnusedPerformanceCounters(observedKeys);
            //if (!_hasTriggerdState && _hasFiredState)
            //{
            //    _hasFiredState = false;
            //    _resetNotification(null);
            //}
        }
        private void Analyze(QMS_API.AgentsQmsApiService qmsAgentsQmsApi)
        {
            List <Guid> serviceIDs = qmsAgentsQmsApi.GetServices().Select(t => t.ID).ToList();

            if (serviceIDs.Count == 0)
            {
                return;
            }
            //List<ServiceInfo> qvsServices = qmsAgentsQmsApi.GetServices(ServiceTypes.QlikViewServer);
            //var abb = qmsAgentsQmsApi.GetQdsSettings(serviceIDs[2], QDSSettingsScope.General);
            List <ServiceStatus> serviceStatuses = qmsAgentsQmsApi.GetServiceStatuses(serviceIDs);


            serviceStatuses.ForEach(svc => svc.MemberStatusDetails.ForEach(msd =>
            {
                try
                {
                    //var a = qmsAgentsQmsApi.GetQdsSettings(svc.ID, QDSSettingsScope.General);
                    //if (!a.General.ShowAlerts)
                    //    return;
                    var key = $"{svc.Name}_{msd.Host}_{msd.ID}";
                    _groupedNotifyer.AddIfMissing(key, $"{svc.Name} service down on {msd.Host}", "");
                    _groupedNotifyer.Analyze(key, (int)msd.Status);
                }
                catch (Exception ex)
                {
                    Log.To.Main.AddException("Failed QmsMonitor analyze", ex);
                }
            }));
            _groupedNotifyer.AnalyzeRoundFinished();
        }
        public void Execute()
        {
            try
            {
                var host = Settings.GetSetting($"{MonitorName}.HostName", "localhost");
                if ((_senseApiSupport == null) || (_senseApiSupport.Host != host))
                {
                    _senseApiSupport = SenseApiSupport.Create(host);
                }

                SenseEnums senseEnums     = new SenseEnums(_senseApiSupport);
                var        taskHelper     = new TaskHelper();
                var        tasks          = taskHelper.GetAllTasksFullDto(_senseApiSupport, senseEnums);
                var        filter         = new Regex(Settings.GetSetting($"{MonitorName}.Filter").Trim(), RegexOptions.IgnoreCase);
                var        negativeFilter = new Regex(Settings.GetSetting($"{MonitorName}.NegativeFilter").Trim(), RegexOptions.IgnoreCase);

                foreach (var dto in tasks)
                {
                    if (filter.ToString() == string.Empty || filter.IsMatch(dto.Name) || filter.IsMatch(dto.Taskid.ToString()))
                    {
                        if (negativeFilter.ToString() != string.Empty && (negativeFilter.IsMatch(dto.Name) || negativeFilter.IsMatch(dto.Taskid.ToString())))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                    var key = dto.Taskid.ToString();
                    if (dto.Enabled.GetValueOrDefault(false))
                    {
                        //what bucket
                        var      bucket       = GetScheduledTimeBucket(dto);
                        TimeSpan?ruleDuration = null;
                        switch (bucket)
                        {
                        case IncrementOptionEnum.Hourly:
                            ruleDuration = TimeSpan.FromSeconds(Settings.GetInt32($"{MonitorName}.HourlyDurationInSeconds", 0));
                            break;

                        case IncrementOptionEnum.Daily:
                            ruleDuration = TimeSpan.FromSeconds(Settings.GetInt32($"{MonitorName}.DailyDurationInSeconds", 0));
                            break;

                        case IncrementOptionEnum.Weekly:
                            ruleDuration = TimeSpan.FromSeconds(Settings.GetInt32($"{MonitorName}.WeeklyDurationInSeconds", 0));
                            break;

                        case IncrementOptionEnum.Monthly:
                            ruleDuration = TimeSpan.FromSeconds(Settings.GetInt32($"{MonitorName}.MonthlyDurationInSeconds", 0));
                            break;
                        }

                        if (ruleDuration.GetValueOrDefault(TimeSpan.FromSeconds(0)) < TimeSpan.FromSeconds(1))
                        {
                            continue; // ignore buckets with no defined minimum execution duration
                        }
                        _groupedNotifyer.AddIfMissing(key, dto.Name);

                        //check if the schedule has changed bucket.
                        if (_groupedNotifyer.GetSettings(key).Duration != ruleDuration)
                        {
                            _groupedNotifyer.GetSettings(key).Duration = ruleDuration.GetValueOrDefault(TimeSpan.FromSeconds(0));
                            continue; // don't analyze this time around. Material change rule duration.
                        }
                        _groupedNotifyer.Analyze(key, dto.Operational?.LastExecutionResult?.Status ?? -1);
                    }
                }
                _groupedNotifyer.AnalyzeRoundFinished();
            }
            catch (Exception ex)
            {
                _senseApiSupport = null;
                Log.To.Main.AddException($"Failed executing {MonitorName}", ex);
            }
        }