Exemplo n.º 1
0
        private static async Task DisplayAudit(
            AuditClientAsync client, IdentityClient identityClinet,
            Compartment compartment, string startDate, string endDate,
            string requestId = "", string pageId = "")
        {
            // get Audit Events
            var listEventsRequest = new ListEventsRequest()
            {
                CompartmentId = compartment.Id,
                StartTime     = startDate,
                EndTime       = endDate,
                Page          = pageId
            };

            var events = await client.ListEvents(listEventsRequest);

            if (!string.IsNullOrEmpty(events.OpcNextPage))
            {
                await DisplayAudit(client, identityClinet, compartment, startDate, endDate, events.OpcRequestId, events.OpcNextPage);
            }

            if (events.Items.Count > 0)
            {
                Count += events.Items.Count;
                Console.WriteLine($"enventset: com={compartment.Name}, start={startDate}, end={endDate}, events.Items:{events.Items.Count}");
            }
        }
        private static async void DisplayAudit(ClientConfig config, AuditClientAsync client, IdentityClient identityClinet, string compartmentId, string startDate, string endDate, string requestId, string pageId)
        {
            // get Audit Events
            var listEventsRequest = new ListEventsRequest()
            {
                CompartmentId = compartmentId,
                StartTime     = startDate,
                EndTime       = endDate,
                //Page = pageId
                //CompartmentId = "ocid1.compartment.oc1..aaaaaaaarj2edeedyk4o7rvcpdh6fckmeevwyog3k7zd4wjlyzcejib53yuq",
                //StartTime = "2019-10-29T09:33:57Z",
                //EndTime = "2019-10-29T11:33:57Z",
                OpcRequestId = requestId,
                Page         = pageId
            };

            var events = await client.ListEvents(listEventsRequest);

            if (!string.IsNullOrEmpty(events.OpcNextPage))
            {
                DisplayAudit(config, client, identityClinet, compartmentId, startDate, endDate, events.OpcRequestId, events.OpcNextPage);
            }

            if (events.Items.Count > 0)
            {
                events.Items.ForEach(e => {
                    Console.WriteLine($"* eventName:{e.Data.EventName}");
                    Console.WriteLine($"\t id:{e.EventId}");
                    Console.WriteLine($"\t type:{e.EventType}");
                    Console.WriteLine($"\t source:{e.Source}");
                    Console.WriteLine($"\t time:{e.EventTime}");
                    Console.WriteLine($"\t resourceName:{e.Data.ResourceName}");
                    if (e.Data.Identity != null)
                    {
                        Console.WriteLine($"\t principal:{e.Data.Identity.PrincipalId}");

                        try
                        {
                            var getUserRequest = new GetUserRequest()
                            {
                                UserId = e.Data.Identity.PrincipalId
                            };
                            var user = identityClinet.GetUser(getUserRequest);
                            Console.WriteLine($"\t user:{user.User.Name}");
                        }
                        catch (WebException we)
                        {
                            if (we.Status.Equals(WebExceptionStatus.ProtocolError))
                            {
                                var code = ((HttpWebResponse)we.Response).StatusCode;
                                if (code == HttpStatusCode.NotFound)
                                {
                                    // エラーだけ残す
                                    Console.WriteLine($"\t user not found");
                                    return;
                                }
                            }
                        }
                    }
                });
            }
        }