Esempio n. 1
0
 void SetInternalServerProperties(Server server)
 {
     server.ServerService = this;
 }
Esempio n. 2
0
        /// <summary>
        /// Gets the alerts for a particular server.
        /// </summary>
        /// <param name="server">The server</param>
        /// <returns>The alerts for the indicated server</returns>
        public async Task<List<Alert>> GetServerAlerts(Server server, CancellationToken cancellationToken)
        {
            var statisticsTask = server.GetStatistics(cancellationToken);
            var alertPoliciesTasks =
                server
                    .Details
                    .AlertPolicies
                    .Select(
                        a =>
                            GetAlertPolicyByLink(string.Format("{0}{1}", Configuration.BaseUri, a.selfLink.Value.Href), cancellationToken));
            await Task.WhenAll(alertPoliciesTasks).ConfigureAwait(false);
            var statistics = await statisticsTask.ConfigureAwait(false);
            var alertPolicies = alertPoliciesTasks.Select(a => a.Result);

            return ScanAlertPoliciesForAlerts(server, alertPolicies, statistics);            
        }
Esempio n. 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;
        }        
Esempio n. 4
0
 /// <summary>
 /// Gets the alerts for a particular server.
 /// </summary>
 /// <param name="server">The server</param>
 /// <returns>The alerts for the indicated server</returns>
 public Task<List<Alert>> GetServerAlerts(Server server)
 {
     return GetServerAlerts(server, CancellationToken.None);
 }
Esempio n. 5
0
 /// <summary>
 /// Returns the recent activity for the indicated server
 /// </summary>
 /// <param name="s">The server</param>
 /// <param name="recordLimit">The maximum number of records to return</param>
 /// <returns>The server recent activity</returns>
 public Task<IEnumerable<Activity>> GetRecentActivityFor(Server s, int recordLimit, CancellationToken cancellationToken)
 {
     return GetRecentActivity(new[] { s.Id }, recordLimit, cancellationToken);
 }
Esempio n. 6
0
 /// <summary>
 /// Returns the recent activity for the indicated server
 /// </summary>
 /// <param name="s">The server</param>
 /// <returns>The server recent activity</returns>
 public Task<IEnumerable<Activity>> GetRecentActivityFor(Server s, CancellationToken cancellationToken)
 {
     return GetRecentActivityFor(s, 10, cancellationToken);
 }
Esempio n. 7
0
 /// <summary>
 /// Returns the recent activity for the indicated server
 /// </summary>
 /// <param name="s">The server</param>
 /// <param name="recordLimit">The maximum number of records to return</param>
 /// <returns>The server recent activity</returns>
 public Task<IEnumerable<Activity>> GetRecentActivityFor(Server s, int recordLimit)
 {
     return GetRecentActivityFor(s, recordLimit, CancellationToken.None);
 }
Esempio n. 8
0
 /// <summary>
 /// Returns the recent activity for the indicated server
 /// </summary>
 /// <param name="s">The server</param>
 /// <returns>The server recent activity</returns>
 public Task<IEnumerable<Activity>> GetRecentActivityFor(Server s)
 {
     return GetRecentActivityFor(s, CancellationToken.None);
 }