/// <summary>
        /// Gets a collection of monitoring audits.
        /// </summary>
        /// <param name="service">The monitoring service instance.</param>
        /// <param name="marker">A marker identifying the next page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>, and is obtained from <see cref="ReadOnlyCollectionPage{T, TMarker}.NextMarker"/>. If the value is <see langword="null"/>, the list starts at the beginning.</param>
        /// <param name="limit">The maximum number of items to include in a single page of results. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">pagination</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param>
        /// <param name="from">The beginning timestamp of the items to include in the collection. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-time-series-collections.html">time series collections</see>. If the value is <see langword="null"/>, a provider-specific default value is used.</param>
        /// <param name="to">The ending timestamp of the items to include in the collection. This parameter is used for <see href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-time-series-collections.html">time series collections</see>. If the value is <see langword="null"/>, the current time is used.</param>
        /// <returns>
        /// A <see cref="ReadOnlyCollectionPage{T, TMarker}"/> object containing the page
        /// of results and its associated pagination metadata.
        /// </returns>
        /// <exception cref="ArgumentNullException">If <paramref name="service"/> is <see langword="null"/>.</exception>
        /// <exception cref="ArgumentException">If <paramref name="to"/> occurs before <paramref name="from"/>.</exception>
        /// <exception cref="ArgumentOutOfRangeException">
        /// If <paramref name="limit"/> is less than or equal to 0.
        /// <para>-or-</para>
        /// <para>If <paramref name="from"/> represents a date before January 1, 1970 UTC.</para>
        /// <para>-or-</para>
        /// <para>If <paramref name="to"/> represents a date before January 1, 1970 UTC.</para>
        /// </exception>
        /// <exception cref="WebException">If the REST request does not return successfully.</exception>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/service-account.html#service-account-list-audits">List Audits (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-paginated-collections.html">Paginated Collections (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        /// <seealso href="http://docs.rackspace.com/cm/api/v1.0/cm-devguide/content/api-time-series-collections.html">Time Series Collections (Rackspace Cloud Monitoring Developer Guide - API v1.0)</seealso>
        public static ReadOnlyCollectionPage<Audit, AuditId> ListAudits(this IMonitoringService service, AuditId marker, int? limit, DateTimeOffset? from, DateTimeOffset? to)
        {
            if (service == null)
                throw new ArgumentNullException("service");

            try
            {
                return service.ListAuditsAsync(marker, limit, from, to, CancellationToken.None).Result;
            }
            catch (AggregateException ex)
            {
                ReadOnlyCollection<Exception> innerExceptions = ex.Flatten().InnerExceptions;
                if (innerExceptions.Count == 1)
                    throw innerExceptions[0];

                throw;
            }
        }
Beispiel #2
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            var  request          = actionContext.ActionArguments[RequestArgumentName];
            bool enableValidation = false;

            if (Utils.Configuration.HasSetting(Constants.ValidateWSDLocation))
            {
                enableValidation = Utils.Configuration[Constants.ValidateWSDLocation].ToBool();
            }

            if (request == null || !enableValidation)
            {
                return;
            }

            HttpRequestMessage httpRequest  = (HttpRequestMessage)request;
            Request            requestparam = new Request();

            this.PawsAuditor.UserId        = this.PawsLogger.UserId;
            this.PawsAuditor.TransactionId = this.PawsLogger.TransactionId;
            this.PawsAuditor.RegionCode    = Utils.Configuration.CurrentRegionId;

            try
            {
                requestparam = JsonSerialization.DeserializeString <Request>(httpRequest.Content.ReadAsStringAsync().Result);
                GeoLocation   geolocation  = requestparam.Params.Location;
                GeoLocation[] geolocations = requestparam.Params.Locations;

                List <RegionPolygonsCache> subregions = (List <RegionPolygonsCache>)DatabaseCache.ServiceCacheHelper.GetServiceCacheObjects(ServiceCacheObjectType.RegionPolygons, null);

                bool isValidRequest = false;
                bool isBatchRequest = false;

                if (geolocation != null)
                {
                    isValidRequest = ValidateRequestedLocation(geolocation, subregions);
                }
                else if (geolocations != null && geolocations.Length > 0)
                {
                    isBatchRequest = true;
                    isValidRequest = ValidateBatchRequestLocations(geolocations, subregions);
                }

                stopWatch.Stop();

                if (!isValidRequest)
                {
                    PawsResponse errorResponse = null;

                    if (isBatchRequest)
                    {
                        errorResponse = ErrorHelper.CreateErrorResponse(requestparam.Method, geolocations, Constants.ErrorMessageOutsideCoverage);
                    }
                    else
                    {
                        errorResponse = ErrorHelper.CreateErrorResponse(requestparam.Method, geolocation, Constants.ErrorMessageOutsideCoverage);
                    }

                    this.PawsLogger.Log(TraceEventType.Error, LoggingMessageId.PAWSGenericMessage, errorResponse.Error.Message);

                    string  auditMethod;
                    AuditId auditId = PawsUtil.GetAuditId(requestparam.Method, out auditMethod);

                    this.PawsAuditor.Audit(auditId, AuditStatus.Failure, stopWatch.ElapsedMilliseconds, auditMethod + " failed");

                    actionContext.Response = actionContext.Request.CreateResponse <PawsResponse>(errorResponse);
                }
            }
            catch (Exception ex)
            {
                stopWatch.Stop();

                this.PawsLogger.Log(TraceEventType.Error, LoggingMessageId.PAWSGenericMessage, ex.ToString());

                string  auditMethod;
                AuditId auditId = PawsUtil.GetAuditId(requestparam.Method, out auditMethod);

                this.PawsAuditor.Audit(auditId, AuditStatus.Failure, stopWatch.ElapsedMilliseconds, auditMethod + " failed");

                PawsResponse errorResponse = ErrorHelper.CreateExceptionResponse(requestparam.Method, ex.Message);

                actionContext.Response = actionContext.Request.CreateResponse <PawsResponse>(errorResponse);
            }
        }
Beispiel #3
0
 public override int GetHashCode()
 {
     return(AuditId.GetHashCode());
 }
Beispiel #4
0
        public PawsResponse Post(HttpRequestMessage httpRequest)
        {
            PawsResponse postResponse = new PawsResponse();
            string       methodId     = string.Empty;
            Request      requestparam = new Request();

            try
            {
                // Begin Log transaction
                this.PawsLogger.Log(TraceEventType.Information, LoggingMessageId.PAWSGenericMessage, "Enter " + this.methodName);

                // Begin elapsed time calculation
                this.stopWatch = new Stopwatch();
                this.stopWatch.Start();

                try
                {
                    requestparam = JsonSerialization.DeserializeString <Request>(httpRequest.Content.ReadAsStringAsync().Result);
                }
                catch (Exception)
                {
                    return(new PawsResponse
                    {
                        JsonRpc = "2.0",
                        Error = new Result
                        {
                            Code = "-201",
                            Message = Constants.InvalidRequest
                        }
                    });
                }

                postResponse = this.Router(requestparam);

                if (postResponse.Error != null)
                {
                    postResponse.Error.Version = requestparam.Params.Version;
                }

                // Populate audit id based on method in the request
                string auditMethod;

                this.auditId         = PawsUtil.GetAuditId(requestparam.Method, out auditMethod);
                this.auditMethodName = auditMethod;

                // End Audit transaction
                this.PawsAuditor.UserId        = this.PawsLogger.UserId;
                this.PawsAuditor.TransactionId = this.PawsLogger.TransactionId;
                this.PawsAuditor.RegionCode    = Utils.Configuration.CurrentRegionId;

                // End Elapsed Time Calculation
                this.stopWatch.Stop();
                this.elapsedTime = this.stopWatch.ElapsedMilliseconds;
                if (postResponse.Result == null && postResponse.Error.Code != null)
                {
                    this.PawsAuditor.Audit(this.auditId, AuditStatus.Failure, this.elapsedTime, this.auditMethodName + " failed");
                }
                else if (postResponse.Error == null && postResponse.Result.Type != null)
                {
                    this.PawsAuditor.Audit(this.auditId, AuditStatus.Success, this.elapsedTime, this.auditMethodName + " passed");
                }

                // End Log transaction
                this.PawsLogger.Log(TraceEventType.Information, LoggingMessageId.PAWSGenericMessage, "Exit " + this.methodName);
                return(postResponse);
            }
            catch (Exception exception)
            {
                // Log transaction Failure
                this.PawsLogger.Log(TraceEventType.Error, LoggingMessageId.PAWSGenericMessage, exception.ToString());

                // Audit transaction Failure
                this.PawsAuditor.UserId        = this.PawsLogger.UserId;
                this.PawsAuditor.TransactionId = this.PawsLogger.TransactionId;
                this.PawsAuditor.RegionCode    = Utils.Configuration.CurrentRegionId;

                string auditMethod;

                this.auditId         = PawsUtil.GetAuditId(requestparam.Method, out auditMethod);
                this.auditMethodName = auditMethod;

                // End Elapsed Time Calculation
                this.stopWatch.Stop();
                this.elapsedTime = this.stopWatch.ElapsedMilliseconds;
                this.PawsAuditor.Audit(this.auditId, AuditStatus.Failure, this.elapsedTime, this.auditMethodName + " failed");
                return(new PawsResponse
                {
                    JsonRpc = "2.0",
                    Error = new Result
                    {
                        Code = "-201",
                        Message = exception.Message
                    }
                });
            }
        }