public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonCloudTrailConfig config = new AmazonCloudTrailConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonCloudTrailClient client = new AmazonCloudTrailClient(creds, config);

            LookupEventsResponse resp = new LookupEventsResponse();

            do
            {
                LookupEventsRequest req = new LookupEventsRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.LookupEvents(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Events)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
예제 #2
0
        internal LookupEventsResponse LookupEvents(LookupEventsRequest request)
        {
            var marshaller   = new LookupEventsRequestMarshaller();
            var unmarshaller = LookupEventsResponseUnmarshaller.Instance;

            return(Invoke <LookupEventsRequest, LookupEventsResponse>(request, marshaller, unmarshaller));
        }
예제 #3
0
        /// <summary>
        /// Initiates the asynchronous execution of the LookupEvents operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the LookupEvents operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task <LookupEventsResponse> LookupEventsAsync(LookupEventsRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new LookupEventsRequestMarshaller();
            var unmarshaller = LookupEventsResponseUnmarshaller.Instance;

            return(InvokeAsync <LookupEventsRequest, LookupEventsResponse>(request, marshaller,
                                                                           unmarshaller, cancellationToken));
        }
        /// <summary>
        /// Initiates the asynchronous execution of the LookupEvents operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the LookupEvents operation on AmazonCloudTrailClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        ///
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndLookupEvents
        ///         operation.</returns>
        public IAsyncResult BeginLookupEvents(LookupEventsRequest request, AsyncCallback callback, object state)
        {
            var marshaller   = new LookupEventsRequestMarshaller();
            var unmarshaller = LookupEventsResponseUnmarshaller.Instance;

            return(BeginInvoke <LookupEventsRequest>(request, marshaller, unmarshaller,
                                                     callback, state));
        }
        /// <summary>
        /// Initiates the asynchronous execution of the LookupEvents operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the LookupEvents operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/cloudtrail-2013-11-01/LookupEvents">REST API Reference for LookupEvents Operation</seealso>
        public virtual Task <LookupEventsResponse> LookupEventsAsync(LookupEventsRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = LookupEventsRequestMarshaller.Instance;
            options.ResponseUnmarshaller = LookupEventsResponseUnmarshaller.Instance;

            return(InvokeAsync <LookupEventsResponse>(request, options, cancellationToken));
        }
        internal virtual LookupEventsResponse LookupEvents(LookupEventsRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = LookupEventsRequestMarshaller.Instance;
            options.ResponseUnmarshaller = LookupEventsResponseUnmarshaller.Instance;

            return(Invoke <LookupEventsResponse>(request, options));
        }
예제 #7
0
        private IEnumerable <Event> LookupAllEvents(LookupEventsRequest request = null)
        {
            if (request == null)
            {
                request = new LookupEventsRequest();
            }
            do
            {
                var result = Client.LookupEventsAsync(request).Result;
                request.NextToken = result.NextToken;

                var events = result.Events;
                foreach (var e in events)
                {
                    yield return(e);
                }
            } while (!string.IsNullOrEmpty(request.NextToken));
        }
예제 #8
0
        public void CloudTrailIntegrationTest()
        {
            var trailsCount = Client.DescribeTrailsAsync().Result.TrailList.Count;

            // Cloud Trail is already setup for this account so skip the test to not disturb
            // the settings.
            if (trailsCount != 0)
            {
                return;
            }

            var trailName = "dotnet-integ-test-trail-" + DateTime.Now.Ticks;
            var trail     = Client.CreateTrailAsync(new CreateTrailRequest
            {
                Name = trailName,
                IncludeGlobalServiceEvents = true,
                S3BucketName = _trailStorageBucketName,
                S3KeyPrefix  = S3_PREFIX
            }).Result;

            Assert.AreEqual(trail.Name, trailName);
            Assert.AreEqual(trail.IncludeGlobalServiceEvents, true);
            Assert.AreEqual(trail.S3BucketName, _trailStorageBucketName);
            Assert.AreEqual(trail.S3KeyPrefix, S3_PREFIX);
            Assert.AreEqual(trail.SnsTopicName, null);
            UtilityMethods.Sleep(TimeSpan.FromSeconds(5));

            var trails = Client.DescribeTrailsAsync().Result.TrailList;

            Assert.AreEqual(trails.Count, trailsCount + 1);

            var trailStatus = Client.GetTrailStatusAsync(new GetTrailStatusRequest
            {
                Name = trailName
            }).Result;

            Assert.AreEqual(trailStatus.IsLogging, false);

            Client.StartLoggingAsync(new StartLoggingRequest
            {
                Name = trailName
            }).Wait();
            UtilityMethods.Sleep(TimeSpan.FromSeconds(5));

            trailStatus = Client.GetTrailStatusAsync(new GetTrailStatusRequest
            {
                Name = trailName
            }).Result;
            Assert.AreEqual(trailStatus.IsLogging, true);

            var endTime   = DateTime.UtcNow;
            var startTime = endTime.AddMinutes(-30);

            var request = new LookupEventsRequest
            {
                StartTime = startTime,
                EndTime   = endTime,
            };
            var allEvents = LookupAllEvents(request).ToList();

            if (allEvents.Count > 0)
            {
                var resourceNamesMap = new Dictionary <string, int>();
                foreach (var e in allEvents)
                {
                    var resources = e.Resources;
                    foreach (var r in resources)
                    {
                        if (!resourceNamesMap.ContainsKey(r.ResourceName))
                        {
                            resourceNamesMap[r.ResourceName] = 0;
                        }
                        resourceNamesMap[r.ResourceName]++;
                    }
                }

                var firstResourceNameKVP = resourceNamesMap.First();
                request.LookupAttributes = new List <LookupAttribute>
                {
                    new LookupAttribute
                    {
                        AttributeKey   = LookupAttributeKey.ResourceName,
                        AttributeValue = firstResourceNameKVP.Key
                    }
                };
                var filteredEvents = LookupAllEvents(request).ToList();
                Assert.AreEqual(firstResourceNameKVP.Value, filteredEvents.Count);
            }

            Client.StopLoggingAsync(new StopLoggingRequest
            {
                Name = trailName
            }).Wait();
            UtilityMethods.Sleep(TimeSpan.FromSeconds(2));

            Client.DeleteTrailAsync(new DeleteTrailRequest
            {
                Name = trailName
            }).Wait();
        }