public void TestUpdateSink()
            {
                string sinkId   = "sinkForTestUpdateSink";
                string logId    = "logForTestUpdateSink";
                string newLogId = "newlogForTestUpdateSink";
                string sinkName = $"projects/{_projectId}/sinks/{sinkId}";
                string message  = "Example log entry.";

                _sinksToDelete.Add(sinkId);
                _logsToDelete.Add(logId);
                _logsToDelete.Add(newLogId);
                // Try creating logs with log entries.
                var created1 = Run("create-log-entry", logId, message);

                AssertSucceeded(created1);
                var created2 = Run("create-log-entry", newLogId, message);

                AssertSucceeded(created2);
                // Try creating sink.
                var created3 = Run("create-sink", sinkId, logId);

                AssertSucceeded(created3);
                // Try updating sink.
                var updated = Run("update-sink", sinkId, newLogId);

                AssertSucceeded(updated);
                // Get sink to confirm that log has been updated.
                var sinkClient = ConfigServiceV2Client.Create();
                var results    = sinkClient.GetSink(sinkName);
                var currentLog = results.Filter;

                Assert.Contains(newLogId, currentLog);
            }
        public void ListSinks()
        {
            // Snippet: ListSinks(string,string,int?,CallSettings)
            // Create client
            ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
            // Initialize request argument(s)
            string formattedParent = ConfigServiceV2Client.FormatParentName("[PROJECT]");
            // Make the request
            IPagedEnumerable <ListSinksResponse, LogSink> response =
                configServiceV2Client.ListSinks(formattedParent);

            // Iterate over all response items, lazily performing RPCs as required
            foreach (LogSink item in response)
            {
                // Do something with each item
                Console.WriteLine(item);
            }

            // Or iterate over fixed-sized pages, lazily performing RPCs as required
            int pageSize = 10;

            foreach (FixedSizePage <LogSink> page in response.AsPages().WithFixedSize(pageSize))
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (LogSink item in page)
                {
                    Console.WriteLine(item);
                }
            }
            // End snippet
        }
        // [END logging_list_log_entries]

        // [START logging_create_sink]
        private void CreateSink(string sinkId, string logId)
        {
            var sinkClient = ConfigServiceV2Client.Create();
            CreateSinkRequest sinkRequest = new CreateSinkRequest();
            LogSink           myLogSink   = new LogSink();

            myLogSink.Name = sinkId;

            // This creates a sink using a Google Cloud Storage bucket
            // named the same as the projectId.
            // This requires editing the bucket's permissions to add the Entity Group
            // named '*****@*****.**' with 'Owner' access for the bucket.
            // If this is being run with a Google Cloud service account,
            // that account will need to be granted 'Owner' access to the Project.
            // In Powershell, use this command:
            // PS > Add-GcsBucketAcl <your-bucket-name> -Role OWNER -Group [email protected]
            myLogSink.Destination = "storage.googleapis.com/" + s_projectId;
            LogName logName = new LogName(s_projectId, logId);

            myLogSink.Filter = $"logName={logName.ToString()}AND severity<=ERROR";
            ProjectName projectName = new ProjectName(s_projectId);

            sinkRequest.Sink = myLogSink;
            sinkClient.CreateSink(projectName, myLogSink, _retryAWhile);
            Console.WriteLine($"Created sink: {sinkId}.");
        }
        // [END delete_log]

        // [START delete_log_sink]
        private void DeleteSink(string sinkId)
        {
            var    sinkClient = ConfigServiceV2Client.Create();
            string sinkName   = $"projects/{s_projectId}/sinks/{sinkId}";

            sinkClient.DeleteSink(sinkName);
            Console.WriteLine($"Deleted {sinkId}.");
        }
        // [END logging_delete_log]

        // [START logging_delete_sink]
        private void DeleteSink(string sinkId)
        {
            var         sinkClient = ConfigServiceV2Client.Create();
            LogSinkName sinkName   = new LogSinkName(s_projectId, sinkId);

            sinkClient.DeleteSink(sinkName, _retryAWhile);
            Console.WriteLine($"Deleted {sinkId}.");
        }
        // [END create_log_sink]

        // [START list_log_sinks]
        private void ListSinks()
        {
            var sinkClient  = ConfigServiceV2Client.Create();
            var listOfSinks = sinkClient.ListSinks($"projects/{s_projectId}");

            foreach (var sink in listOfSinks)
            {
                Console.WriteLine($"{sink.Name} {sink.ToString()}");
            }
        }
 public void GetSink()
 {
     // Snippet: GetSink(string,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     string formattedSinkName = ConfigServiceV2Client.FormatSinkName("[PROJECT]", "[SINK]");
     // Make the request
     LogSink response = configServiceV2Client.GetSink(formattedSinkName);
     // End snippet
 }
        // [END list_log_sinks]

        // [START update_log_sink]
        private void UpdateSinkLog(string sinkId, string logId)
        {
            var    sinkClient = ConfigServiceV2Client.Create();
            string logName    = $"projects/{s_projectId}/logs/{logId}";
            string sinkName   = $"projects/{s_projectId}/sinks/{sinkId}";
            var    sink       = sinkClient.GetSink(sinkName);

            sink.Filter = $"logName={logName}AND severity<=ERROR";
            sinkClient.UpdateSink(sinkName, sink);
            Console.WriteLine($"Updated {sinkId} to export logs from {logId}.");
        }
        // [END logging_create_sink]

        // [START logging_list_sinks]
        private void ListSinks()
        {
            var         sinkClient  = ConfigServiceV2Client.Create();
            ProjectName projectName = new ProjectName(s_projectId);
            var         listOfSinks = sinkClient.ListSinks(projectName, callSettings: _retryAWhile);

            foreach (var sink in listOfSinks)
            {
                Console.WriteLine($"{sink.Name} {sink.ToString()}");
            }
        }
        // [END logging_list_sinks]

        // [START logging_update_sink]
        private void UpdateSinkLog(string sinkId, string logId)
        {
            var         sinkClient = ConfigServiceV2Client.Create();
            LogName     logName    = new LogName(s_projectId, logId);
            LogSinkName sinkName   = new LogSinkName(s_projectId, sinkId);
            var         sink       = sinkClient.GetSink(sinkName, _retryAWhile);

            sink.Filter = $"logName={logName.ToString()}AND severity<=ERROR";
            sinkClient.UpdateSink(sinkName, sink, _retryAWhile);
            Console.WriteLine($"Updated {sinkId} to export logs from {logId}.");
        }
 /// <summary>Snippet for GetCmekSettings</summary>
 public void GetCmekSettings_RequestObject()
 {
     // Snippet: GetCmekSettings(GetCmekSettingsRequest,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     GetCmekSettingsRequest request = new GetCmekSettingsRequest();
     // Make the request
     CmekSettings response = configServiceV2Client.GetCmekSettings(request);
     // End snippet
 }
 /// <summary>Snippet for GetExclusion</summary>
 public void GetExclusion()
 {
     // Snippet: GetExclusion(ExclusionNameOneof,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     ExclusionNameOneof name = ExclusionNameOneof.From(new ExclusionName("[PROJECT]", "[EXCLUSION]"));
     // Make the request
     LogExclusion response = configServiceV2Client.GetExclusion(name);
     // End snippet
 }
 /// <summary>Snippet for GetSink</summary>
 public void GetSink()
 {
     // Snippet: GetSink(SinkNameOneof,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     SinkNameOneof sinkName = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]"));
     // Make the request
     LogSink response = configServiceV2Client.GetSink(sinkName);
     // End snippet
 }
 /// <summary>Snippet for CreateSink</summary>
 public void CreateSink()
 {
     // Snippet: CreateSink(ParentNameOneof,LogSink,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     ParentNameOneof parent = ParentNameOneof.From(new ProjectName("[PROJECT]"));
     LogSink         sink   = new LogSink();
     // Make the request
     LogSink response = configServiceV2Client.CreateSink(parent, sink);
     // End snippet
 }
 /// <summary>Snippet for CreateExclusion</summary>
 public void CreateExclusion()
 {
     // Snippet: CreateExclusion(ParentNameOneof,LogExclusion,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     ParentNameOneof parent    = ParentNameOneof.From(new ProjectName("[PROJECT]"));
     LogExclusion    exclusion = new LogExclusion();
     // Make the request
     LogExclusion response = configServiceV2Client.CreateExclusion(parent, exclusion);
     // End snippet
 }
 public void CreateSink()
 {
     // Snippet: CreateSink(string,LogSink,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     string  formattedParent = ConfigServiceV2Client.FormatParentName("[PROJECT]");
     LogSink sink            = new LogSink();
     // Make the request
     LogSink response = configServiceV2Client.CreateSink(formattedParent, sink);
     // End snippet
 }
 /// <summary>Snippet for UpdateSink</summary>
 public void UpdateSink1()
 {
     // Snippet: UpdateSink(SinkNameOneof,LogSink,FieldMask,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     SinkNameOneof sinkName   = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]"));
     LogSink       sink       = new LogSink();
     FieldMask     updateMask = new FieldMask();
     // Make the request
     LogSink response = configServiceV2Client.UpdateSink(sinkName, sink, updateMask);
     // End snippet
 }
 /// <summary>Snippet for UpdateExclusion</summary>
 public void UpdateExclusion()
 {
     // Snippet: UpdateExclusion(ExclusionNameOneof,LogExclusion,FieldMask,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     ExclusionNameOneof name       = ExclusionNameOneof.From(new ExclusionName("[PROJECT]", "[EXCLUSION]"));
     LogExclusion       exclusion  = new LogExclusion();
     FieldMask          updateMask = new FieldMask();
     // Make the request
     LogExclusion response = configServiceV2Client.UpdateExclusion(name, exclusion, updateMask);
     // End snippet
 }
        public async Task DeleteSinkAsync()
        {
            // Snippet: DeleteSinkAsync(string,CallSettings)
            // Additional: DeleteSinkAsync(string,CancellationToken)
            // Create client
            ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
            // Initialize request argument(s)
            string formattedSinkName = ConfigServiceV2Client.FormatSinkName("[PROJECT]", "[SINK]");
            // Make the request
            await configServiceV2Client.DeleteSinkAsync(formattedSinkName);

            // End snippet
        }
 /// <summary>Snippet for GetExclusion</summary>
 public void GetExclusion_RequestObject()
 {
     // Snippet: GetExclusion(GetExclusionRequest,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     GetExclusionRequest request = new GetExclusionRequest
     {
         ExclusionNameOneof = ExclusionNameOneof.From(new ExclusionName("[PROJECT]", "[EXCLUSION]")),
     };
     // Make the request
     LogExclusion response = configServiceV2Client.GetExclusion(request);
     // End snippet
 }
 /// <summary>Snippet for GetSink</summary>
 public void GetSink_RequestObject()
 {
     // Snippet: GetSink(GetSinkRequest,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     GetSinkRequest request = new GetSinkRequest
     {
         SinkNameAsSinkNameOneof = SinkNameOneof.From(new SinkName("[PROJECT]", "[SINK]")),
     };
     // Make the request
     LogSink response = configServiceV2Client.GetSink(request);
     // End snippet
 }
        public async Task UpdateSinkAsync()
        {
            // Snippet: UpdateSinkAsync(string,LogSink,CallSettings)
            // Additional: UpdateSinkAsync(string,LogSink,CancellationToken)
            // Create client
            ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
            // Initialize request argument(s)
            string  formattedSinkName = ConfigServiceV2Client.FormatSinkName("[PROJECT]", "[SINK]");
            LogSink sink = new LogSink();
            // Make the request
            LogSink response = await configServiceV2Client.UpdateSinkAsync(formattedSinkName, sink);

            // End snippet
        }
 /// <summary>Snippet for CreateExclusion</summary>
 public void CreateExclusion_RequestObject()
 {
     // Snippet: CreateExclusion(CreateExclusionRequest,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     CreateExclusionRequest request = new CreateExclusionRequest
     {
         ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")),
         Exclusion = new LogExclusion(),
     };
     // Make the request
     LogExclusion response = configServiceV2Client.CreateExclusion(request);
     // End snippet
 }
 /// <summary>Snippet for UpdateExclusion</summary>
 public void UpdateExclusion_RequestObject()
 {
     // Snippet: UpdateExclusion(UpdateExclusionRequest,CallSettings)
     // Create client
     ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
     // Initialize request argument(s)
     UpdateExclusionRequest request = new UpdateExclusionRequest
     {
         ExclusionNameOneof = ExclusionNameOneof.From(new ExclusionName("[PROJECT]", "[EXCLUSION]")),
         Exclusion          = new LogExclusion(),
         UpdateMask         = new FieldMask(),
     };
     // Make the request
     LogExclusion response = configServiceV2Client.UpdateExclusion(request);
     // End snippet
 }
        /// <summary>Snippet for ListExclusions</summary>
        public void ListExclusions_RequestObject()
        {
            // Snippet: ListExclusions(ListExclusionsRequest,CallSettings)
            // Create client
            ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create();
            // Initialize request argument(s)
            ListExclusionsRequest request = new ListExclusionsRequest
            {
                ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")),
            };
            // Make the request
            PagedEnumerable <ListExclusionsResponse, LogExclusion> response =
                configServiceV2Client.ListExclusions(request);

            // Iterate over all response items, lazily performing RPCs as required
            foreach (LogExclusion item in response)
            {
                // Do something with each item
                Console.WriteLine(item);
            }

            // Or iterate over pages (of server-defined size), performing one RPC per page
            foreach (ListExclusionsResponse page in response.AsRawResponses())
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (LogExclusion item in page)
                {
                    Console.WriteLine(item);
                }
            }

            // Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
            int pageSize = 10;
            Page <LogExclusion> singlePage = response.ReadPage(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (LogExclusion item in singlePage)
            {
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
            public void TestDeleteSink()
            {
                string sinkId   = "sinkForTestDeleteSink";
                string logId    = "logForTestDeleteSink";
                string sinkName = $"projects/{_projectId}/sinks/{sinkId}";
                string message  = "Example log entry.";

                _logsToDelete.Add(logId);
                // Try creating log with log entry.
                Run("create-log-entry", logId, message).AssertSucceeded();
                // Try creating sink.
                Run("create-sink", sinkId, logId).AssertSucceeded();
                // Try deleting sink.
                Run("delete-sink", sinkId);
                // Get sink to confirm it has been deleted.
                var       sinkClient = ConfigServiceV2Client.Create();
                Exception ex         = Assert.Throws <Grpc.Core.RpcException>(() =>
                                                                              sinkClient.GetSink(sinkName));
            }
            public void TestCreateSink()
            {
                string sinkId   = "sinkForTestCreateSink";
                string logId    = "logForTestCreateSink";
                string sinkName = $"projects/{_projectId}/sinks/{sinkId}";
                string message  = "Example log entry.";

                _sinksToDelete.Add(sinkId);
                _logsToDelete.Add(logId);
                // Try creating log with log entry.
                var created1 = Run("create-log-entry", logId, message);

                created1.AssertSucceeded();
                // Try creating sink.
                var created2 = Run("create-sink", sinkId, logId);

                created2.AssertSucceeded();
                var sinkClient = ConfigServiceV2Client.Create();
                var results    = sinkClient.GetSink(sinkName);

                // Confirm newly created sink is returned.
                Assert.NotNull(results);
            }
Exemple #28
0
        // [END list_log_entries]

        // [START create_log_sink]
        private void CreateSink(string sinkId, string logId)
        {
            var sinkClient = ConfigServiceV2Client.Create();
            CreateSinkRequest sinkRequest = new CreateSinkRequest();
            LogSink           myLogSink   = new LogSink();
            string            sinkName    = $"projects/{s_projectId}/sinks/{sinkId}";

            myLogSink.Name = sinkId;

            // This creates a sink using a Google Cloud Storage bucket
            // named the same as the projectId.
            // This requires editing the bucket's permissions to add the Entity Group
            // named '*****@*****.**' with 'Owner' access for the bucket.
            // If this is being run with a Google Cloud service account,
            // that account will need to be granted 'Owner' access to the Project.
            myLogSink.Destination = "storage.googleapis.com/" + s_projectId;
            string logName = $"projects/{s_projectId}/logs/{logId}";

            myLogSink.Filter   = $"logName={logName}AND severity<=ERROR";
            sinkRequest.Parent = $"projects/{s_projectId}";
            sinkRequest.Sink   = myLogSink;
            sinkClient.CreateSink(sinkRequest.Parent, myLogSink);
            _out.WriteLine($"Created sink: {sinkId}.");
        }
Exemple #29
0
            public void TestUpdateSink()
            {
                string   sinkId   = "sinkForTestUpdateSink";
                string   logId    = "logForTestUpdateSink";
                string   newLogId = "newlogForTestUpdateSink";
                SinkName sinkName = new SinkName(_projectId, sinkId);
                string   message  = "Example log entry.";

                _sinksToDelete.Add(sinkId);
                _logsToDelete.Add(logId);
                _logsToDelete.Add(newLogId);
                // Try creating logs with log entries.
                Run("create-log-entry", logId, message).AssertSucceeded();
                Run("create-log-entry", newLogId, message).AssertSucceeded();
                Run("create-sink", sinkId, logId).AssertSucceeded();
                // Try updating sink.
                Run("update-sink", sinkId, newLogId).AssertSucceeded();
                // Get sink to confirm that log has been updated.
                var sinkClient = ConfigServiceV2Client.Create();
                var results    = sinkClient.GetSink(SinkNameOneof.From(sinkName));
                var currentLog = results.Filter;

                Assert.Contains(newLogId, currentLog);
            }