示例#1
0
        /// <summary>
        /// Gets the alerts for all servers in the account that subscribe to an alert policy.
        /// </summary>
        /// <returns>All alerts</returns>
        public async Task <IEnumerable <Alert> > GetAllServerAlerts(CancellationToken cancellationToken)
        {
            var alerts = new List <Alert>();

            var alertPolicies = await GetAlertPoliciesByLink(cancellationToken).ConfigureAwait(false);

            //TODO: fetch concurrently
            foreach (var alertPolicy in alertPolicies.Items)
            {
                var servers = await alertPolicy.GetServers().ConfigureAwait(false);

                foreach (var server in servers)
                {
                    var statistics = await server.GetStatistics().ConfigureAwait(false);

                    if (statistics != null)
                    {
                        var statistic = statistics.Stats.FirstOrDefault();

                        if (statistic != null)
                        {
                            foreach (var trigger in alertPolicy.Triggers)
                            {
                                try
                                {
                                    var alert = GetServerAlert(alertPolicy, trigger, statistic, server.Id);

                                    if (alert != null)
                                    {
                                        alerts.Add(alert);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    var exception = new CenturyLinkCloudServiceException(Constants.ExceptionMessages.AlertGenerationExceptionMessage, ex);
                                    throw exception;
                                }
                            }
                        }
                    }
                }
            }

            return(alerts);
        }
示例#2
0
        /// <summary>
        /// Gets the alerts for all servers in the account that subscribe to an alert policy.
        /// </summary>        
        /// <returns>All alerts</returns>
        public async Task<IEnumerable<Alert>> GetAllServerAlerts(CancellationToken cancellationToken)
        {
            var alerts = new List<Alert>();

            var alertPolicies = await GetAlertPoliciesByLink(cancellationToken).ConfigureAwait(false);

            //TODO: fetch concurrently
            foreach (var alertPolicy in alertPolicies.Items)
            {
                var servers = await alertPolicy.GetServers().ConfigureAwait(false);

                foreach (var server in servers)
                {                    
                    var statistics = await server.GetStatistics().ConfigureAwait(false);
                    if (statistics != null)
                    {
                        var statistic = statistics.Stats.FirstOrDefault();

                        if (statistic != null)
                        {
                            foreach (var trigger in alertPolicy.Triggers)
                            {
                                try
                                {
                                    var alert = GetServerAlert(alertPolicy, trigger, statistic, server.Id);

                                    if (alert != null)
                                    {
                                        alerts.Add(alert);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    var exception = new CenturyLinkCloudServiceException(Constants.ExceptionMessages.AlertGenerationExceptionMessage, ex);
                                    throw exception;
                                }
                            }
                        }
                    }
                }
            }

            return alerts;
        }
示例#3
0
        /// <summary>
        /// Loops through alert policies to determine if a server needs to be alerted.
        /// </summary>
        /// <param name="serverId"></param>
        /// <param name="alertPolicies"></param>
        /// <param name="statistics"></param>
        /// <returns></returns>
        private List <Alert> ScanAlertPoliciesForAlerts(Server server, IEnumerable <AlertPolicy> alertPolicies, Statistics statistics)
        {
            var alerts = new List <Alert>();

            foreach (var alertPolicy in alertPolicies)
            {
                var statistic = statistics.Stats.FirstOrDefault();

                if (statistic != null)
                {
                    var triggers = alertPolicy.Triggers;
                    if (triggers != null)
                    {
                        foreach (var trigger in triggers)
                        {
                            try
                            {
                                var alert = GetServerAlert(alertPolicy, trigger, statistic, server.Id);

                                if (alert != null)
                                {
                                    alerts.Add(alert);
                                }
                            }
                            catch (Exception ex)
                            {
                                var exception = new CenturyLinkCloudServiceException(Constants.ExceptionMessages.AlertGenerationExceptionMessage, ex);
                                throw exception;
                            }
                        }
                    }
                }
            }

            return(alerts);
        }
示例#4
0
        /// <summary>
        /// Loops through alert policies to determine if a server needs to be alerted.
        /// </summary>
        /// <param name="serverId"></param>
        /// <param name="alertPolicies"></param>
        /// <param name="statistics"></param>
        /// <returns></returns>
        private List<Alert> ScanAlertPoliciesForAlerts(Server server, IEnumerable<AlertPolicy> alertPolicies, Statistics statistics)
        {
            var alerts = new List<Alert>();

            foreach (var alertPolicy in alertPolicies)
            {
                var statistic = statistics.Stats.FirstOrDefault();

                if (statistic != null)
                {
                    var triggers = alertPolicy.Triggers;
                    if (triggers != null)
                    {
                        foreach (var trigger in triggers)
                        {
                            try
                            {
                                var alert = GetServerAlert(alertPolicy, trigger, statistic, server.Id);

                                if (alert != null)
                                {
                                    alerts.Add(alert);
                                }
                            }
                            catch (Exception ex)
                            {
                                var exception = new CenturyLinkCloudServiceException(Constants.ExceptionMessages.AlertGenerationExceptionMessage, ex);
                                throw exception;
                            }
                        }
                    }
                }
            }

            return alerts;
        }