예제 #1
0
        // [START monitoring_uptime_check_create]
        public static object CreateUptimeCheck(string projectId, string hostName,
                                               string displayName)
        {
            // Define a new config.
            var config = new UptimeCheckConfig()
            {
                DisplayName       = displayName,
                MonitoredResource = new MonitoredResource()
                {
                    Type   = "uptime_url",
                    Labels = { { "host", hostName } }
                },
                HttpCheck = new UptimeCheckConfig.Types.HttpCheck()
                {
                    Path = "/",
                    Port = 80,
                },
                Timeout = TimeSpan.FromSeconds(10).ToDuration(),
                Period  = TimeSpan.FromMinutes(5).ToDuration()
            };
            // Create a client.
            var         client      = UptimeCheckServiceClient.Create();
            ProjectName projectName = new ProjectName(projectId);
            // Create the config.
            var newConfig = client.CreateUptimeCheckConfig(
                projectName,
                config,
                CallSettings.FromExpiration(
                    Expiration.FromTimeout(
                        TimeSpan.FromMinutes(2))));

            Console.WriteLine(newConfig.Name);
            return(0);
        }
예제 #2
0
        // [END monitoring_uptime_check_create]

        // [START monitoring_uptime_check_delete]
        public static object DeleteUptimeCheckConfig(string configName)
        {
            var client = UptimeCheckServiceClient.Create();

            client.DeleteUptimeCheckConfig(configName);
            Console.WriteLine($"Deleted {configName}");
            return(0);
        }
예제 #3
0
 /// <summary>Snippet for GetUptimeCheckConfig</summary>
 public void GetUptimeCheckConfig()
 {
     // Snippet: GetUptimeCheckConfig(string,CallSettings)
     // Create client
     UptimeCheckServiceClient uptimeCheckServiceClient = UptimeCheckServiceClient.Create();
     // Initialize request argument(s)
     string formattedName = new UptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]").ToString();
     // Make the request
     UptimeCheckConfig response = uptimeCheckServiceClient.GetUptimeCheckConfig(formattedName);
     // End snippet
 }
예제 #4
0
 /// <summary>Snippet for UpdateUptimeCheckConfig</summary>
 public void UpdateUptimeCheckConfig()
 {
     // Snippet: UpdateUptimeCheckConfig(UptimeCheckConfig,CallSettings)
     // Create client
     UptimeCheckServiceClient uptimeCheckServiceClient = UptimeCheckServiceClient.Create();
     // Initialize request argument(s)
     UptimeCheckConfig uptimeCheckConfig = new UptimeCheckConfig();
     // Make the request
     UptimeCheckConfig response = uptimeCheckServiceClient.UpdateUptimeCheckConfig(uptimeCheckConfig);
     // End snippet
 }
예제 #5
0
        // [END monitoring_uptime_check_list_configs]

        // [START monitoring_uptime_check_list_ips]
        public static object ListUptimeCheckIps()
        {
            var client = UptimeCheckServiceClient.Create();
            var ips    = client.ListUptimeCheckIps(new ListUptimeCheckIpsRequest());

            foreach (UptimeCheckIp ip in ips)
            {
                Console.WriteLine("{0,20} {1}", ip.IpAddress, ip.Location);
            }
            return(0);
        }
예제 #6
0
        // [END monitoring_uptime_check_delete]


        // [START monitoring_uptime_check_list_configs]
        public static object ListUptimeCheckConfigs(string projectId)
        {
            var client  = UptimeCheckServiceClient.Create();
            var configs = client.ListUptimeCheckConfigs(new ProjectName(projectId));

            foreach (UptimeCheckConfig config in configs)
            {
                Console.WriteLine(config.Name);
            }
            return(0);
        }
예제 #7
0
        /// <summary>Snippet for DeleteUptimeCheckConfig</summary>
        public void DeleteUptimeCheckConfig()
        {
            // Snippet: DeleteUptimeCheckConfig(UptimeCheckConfigName,CallSettings)
            // Create client
            UptimeCheckServiceClient uptimeCheckServiceClient = UptimeCheckServiceClient.Create();
            // Initialize request argument(s)
            UptimeCheckConfigName name = new UptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]");

            // Make the request
            uptimeCheckServiceClient.DeleteUptimeCheckConfig(name);
            // End snippet
        }
예제 #8
0
 /// <summary>Snippet for CreateUptimeCheckConfig</summary>
 public void CreateUptimeCheckConfig()
 {
     // Snippet: CreateUptimeCheckConfig(string,UptimeCheckConfig,CallSettings)
     // Create client
     UptimeCheckServiceClient uptimeCheckServiceClient = UptimeCheckServiceClient.Create();
     // Initialize request argument(s)
     string            formattedParent   = new ProjectName("[PROJECT]").ToString();
     UptimeCheckConfig uptimeCheckConfig = new UptimeCheckConfig();
     // Make the request
     UptimeCheckConfig response = uptimeCheckServiceClient.CreateUptimeCheckConfig(formattedParent, uptimeCheckConfig);
     // End snippet
 }
예제 #9
0
        /// <summary>Snippet for UpdateUptimeCheckConfigAsync</summary>
        public async Task UpdateUptimeCheckConfigAsync()
        {
            // Snippet: UpdateUptimeCheckConfigAsync(UptimeCheckConfig,CallSettings)
            // Additional: UpdateUptimeCheckConfigAsync(UptimeCheckConfig,CancellationToken)
            // Create client
            UptimeCheckServiceClient uptimeCheckServiceClient = await UptimeCheckServiceClient.CreateAsync();

            // Initialize request argument(s)
            UptimeCheckConfig uptimeCheckConfig = new UptimeCheckConfig();
            // Make the request
            UptimeCheckConfig response = await uptimeCheckServiceClient.UpdateUptimeCheckConfigAsync(uptimeCheckConfig);

            // End snippet
        }
예제 #10
0
 /// <summary>Snippet for GetUptimeCheckConfig</summary>
 public void GetUptimeCheckConfig_RequestObject()
 {
     // Snippet: GetUptimeCheckConfig(GetUptimeCheckConfigRequest,CallSettings)
     // Create client
     UptimeCheckServiceClient uptimeCheckServiceClient = UptimeCheckServiceClient.Create();
     // Initialize request argument(s)
     GetUptimeCheckConfigRequest request = new GetUptimeCheckConfigRequest
     {
         Name = new UptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]").ToString(),
     };
     // Make the request
     UptimeCheckConfig response = uptimeCheckServiceClient.GetUptimeCheckConfig(request);
     // End snippet
 }
예제 #11
0
        /// <summary>Snippet for GetUptimeCheckConfigAsync</summary>
        public async Task GetUptimeCheckConfigAsync()
        {
            // Snippet: GetUptimeCheckConfigAsync(UptimeCheckConfigName,CallSettings)
            // Additional: GetUptimeCheckConfigAsync(UptimeCheckConfigName,CancellationToken)
            // Create client
            UptimeCheckServiceClient uptimeCheckServiceClient = await UptimeCheckServiceClient.CreateAsync();

            // Initialize request argument(s)
            UptimeCheckConfigName name = new UptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]");
            // Make the request
            UptimeCheckConfig response = await uptimeCheckServiceClient.GetUptimeCheckConfigAsync(name);

            // End snippet
        }
예제 #12
0
        /// <summary>Snippet for DeleteUptimeCheckConfigAsync</summary>
        public async Task DeleteUptimeCheckConfigAsync()
        {
            // Snippet: DeleteUptimeCheckConfigAsync(string,CallSettings)
            // Additional: DeleteUptimeCheckConfigAsync(string,CancellationToken)
            // Create client
            UptimeCheckServiceClient uptimeCheckServiceClient = await UptimeCheckServiceClient.CreateAsync();

            // Initialize request argument(s)
            string formattedName = new UptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]").ToString();
            // Make the request
            await uptimeCheckServiceClient.DeleteUptimeCheckConfigAsync(formattedName);

            // End snippet
        }
예제 #13
0
        /// <summary>Snippet for CreateUptimeCheckConfigAsync</summary>
        public async Task CreateUptimeCheckConfigAsync()
        {
            // Snippet: CreateUptimeCheckConfigAsync(string,UptimeCheckConfig,CallSettings)
            // Additional: CreateUptimeCheckConfigAsync(string,UptimeCheckConfig,CancellationToken)
            // Create client
            UptimeCheckServiceClient uptimeCheckServiceClient = await UptimeCheckServiceClient.CreateAsync();

            // Initialize request argument(s)
            string            formattedParent   = new ProjectName("[PROJECT]").ToString();
            UptimeCheckConfig uptimeCheckConfig = new UptimeCheckConfig();
            // Make the request
            UptimeCheckConfig response = await uptimeCheckServiceClient.CreateUptimeCheckConfigAsync(formattedParent, uptimeCheckConfig);

            // End snippet
        }
예제 #14
0
        /// <summary>Snippet for DeleteUptimeCheckConfig</summary>
        public void DeleteUptimeCheckConfig_RequestObject()
        {
            // Snippet: DeleteUptimeCheckConfig(DeleteUptimeCheckConfigRequest,CallSettings)
            // Create client
            UptimeCheckServiceClient uptimeCheckServiceClient = UptimeCheckServiceClient.Create();
            // Initialize request argument(s)
            DeleteUptimeCheckConfigRequest request = new DeleteUptimeCheckConfigRequest
            {
                UptimeCheckConfigName = new UptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]"),
            };

            // Make the request
            uptimeCheckServiceClient.DeleteUptimeCheckConfig(request);
            // End snippet
        }
예제 #15
0
 /// <summary>Snippet for CreateUptimeCheckConfig</summary>
 public void CreateUptimeCheckConfig_RequestObject()
 {
     // Snippet: CreateUptimeCheckConfig(CreateUptimeCheckConfigRequest,CallSettings)
     // Create client
     UptimeCheckServiceClient uptimeCheckServiceClient = UptimeCheckServiceClient.Create();
     // Initialize request argument(s)
     CreateUptimeCheckConfigRequest request = new CreateUptimeCheckConfigRequest
     {
         Parent            = new ProjectName("[PROJECT]").ToString(),
         UptimeCheckConfig = new UptimeCheckConfig(),
     };
     // Make the request
     UptimeCheckConfig response = uptimeCheckServiceClient.CreateUptimeCheckConfig(request);
     // End snippet
 }
예제 #16
0
        // [END monitoring_uptime_check_update]

        // [START monitoring_uptime_check_get]
        public static object GetUptimeCheckConfig(string configName)
        {
            var client = UptimeCheckServiceClient.Create();
            UptimeCheckConfig config = client.GetUptimeCheckConfig(configName);

            if (config == null)
            {
                Console.Error.WriteLine(
                    "No configuration found with the name {0}", configName);
                return(-1);
            }
            Console.WriteLine("Name: {0}", config.Name);
            Console.WriteLine("Display Name: {0}", config.DisplayName);
            Console.WriteLine("Http Path: {0}", config.HttpCheck.Path);
            return(0);
        }
        /// <summary>Snippet for UpdateUptimeCheckConfigAsync</summary>
        public async Task UpdateUptimeCheckConfigAsync_RequestObject()
        {
            // Snippet: UpdateUptimeCheckConfigAsync(UpdateUptimeCheckConfigRequest,CallSettings)
            // Create client
            UptimeCheckServiceClient uptimeCheckServiceClient = await UptimeCheckServiceClient.CreateAsync();

            // Initialize request argument(s)
            UpdateUptimeCheckConfigRequest request = new UpdateUptimeCheckConfigRequest
            {
                UptimeCheckConfig = new UptimeCheckConfig(),
            };
            // Make the request
            UptimeCheckConfig response = await uptimeCheckServiceClient.UpdateUptimeCheckConfigAsync(request);

            // End snippet
        }
        /// <summary>Snippet for DeleteUptimeCheckConfigAsync</summary>
        public async Task DeleteUptimeCheckConfigAsync_RequestObject()
        {
            // Snippet: DeleteUptimeCheckConfigAsync(DeleteUptimeCheckConfigRequest,CallSettings)
            // Create client
            UptimeCheckServiceClient uptimeCheckServiceClient = await UptimeCheckServiceClient.CreateAsync();

            // Initialize request argument(s)
            DeleteUptimeCheckConfigRequest request = new DeleteUptimeCheckConfigRequest
            {
                Name = new UptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]").ToString(),
            };
            // Make the request
            await uptimeCheckServiceClient.DeleteUptimeCheckConfigAsync(request);

            // End snippet
        }
예제 #19
0
        /// <summary>Snippet for ListUptimeCheckConfigsAsync</summary>
        public async Task ListUptimeCheckConfigsAsync_RequestObject()
        {
            // Snippet: ListUptimeCheckConfigsAsync(ListUptimeCheckConfigsRequest,CallSettings)
            // Create client
            UptimeCheckServiceClient uptimeCheckServiceClient = await UptimeCheckServiceClient.CreateAsync();

            // Initialize request argument(s)
            ListUptimeCheckConfigsRequest request = new ListUptimeCheckConfigsRequest
            {
                Parent = new ProjectName("[PROJECT]").ToString(),
            };
            // Make the request
            PagedAsyncEnumerable <ListUptimeCheckConfigsResponse, UptimeCheckConfig> response =
                uptimeCheckServiceClient.ListUptimeCheckConfigsAsync(request);

            // Iterate over all response items, lazily performing RPCs as required
            await response.ForEachAsync((UptimeCheckConfig item) =>
            {
                // Do something with each item
                Console.WriteLine(item);
            });

            // Or iterate over pages (of server-defined size), performing one RPC per page
            await response.AsRawResponses().ForEachAsync((ListUptimeCheckConfigsResponse page) =>
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (UptimeCheckConfig 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 <UptimeCheckConfig> singlePage = await response.ReadPageAsync(pageSize);

            // Do something with the page of items
            Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
            foreach (UptimeCheckConfig item in singlePage)
            {
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
예제 #20
0
        /// <summary>Snippet for GetUptimeCheckConfigAsync</summary>
        public async Task GetUptimeCheckConfigAsync_RequestObject()
        {
            // Snippet: GetUptimeCheckConfigAsync(GetUptimeCheckConfigRequest,CallSettings)
            // Additional: GetUptimeCheckConfigAsync(GetUptimeCheckConfigRequest,CancellationToken)
            // Create client
            UptimeCheckServiceClient uptimeCheckServiceClient = await UptimeCheckServiceClient.CreateAsync();

            // Initialize request argument(s)
            GetUptimeCheckConfigRequest request = new GetUptimeCheckConfigRequest
            {
                Name = new UptimeCheckConfigName("[PROJECT]", "[UPTIME_CHECK_CONFIG]").ToString(),
            };
            // Make the request
            UptimeCheckConfig response = await uptimeCheckServiceClient.GetUptimeCheckConfigAsync(request);

            // End snippet
        }
예제 #21
0
        /// <summary>Snippet for CreateUptimeCheckConfigAsync</summary>
        public async Task CreateUptimeCheckConfigAsync_RequestObject()
        {
            // Snippet: CreateUptimeCheckConfigAsync(CreateUptimeCheckConfigRequest,CallSettings)
            // Additional: CreateUptimeCheckConfigAsync(CreateUptimeCheckConfigRequest,CancellationToken)
            // Create client
            UptimeCheckServiceClient uptimeCheckServiceClient = await UptimeCheckServiceClient.CreateAsync();

            // Initialize request argument(s)
            CreateUptimeCheckConfigRequest request = new CreateUptimeCheckConfigRequest
            {
                Parent            = new ProjectName("[PROJECT]").ToString(),
                UptimeCheckConfig = new UptimeCheckConfig(),
            };
            // Make the request
            UptimeCheckConfig response = await uptimeCheckServiceClient.CreateUptimeCheckConfigAsync(request);

            // End snippet
        }
예제 #22
0
        /// <summary>Snippet for ListUptimeCheckConfigs</summary>
        public void ListUptimeCheckConfigs()
        {
            // Snippet: ListUptimeCheckConfigs(string,string,int?,CallSettings)
            // Create client
            UptimeCheckServiceClient uptimeCheckServiceClient = UptimeCheckServiceClient.Create();
            // Initialize request argument(s)
            string formattedParent = new ProjectName("[PROJECT]").ToString();
            // Make the request
            PagedEnumerable <ListUptimeCheckConfigsResponse, UptimeCheckConfig> response =
                uptimeCheckServiceClient.ListUptimeCheckConfigs(formattedParent);

            // Iterate over all response items, lazily performing RPCs as required
            foreach (UptimeCheckConfig 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 (ListUptimeCheckConfigsResponse page in response.AsRawResponses())
            {
                // Do something with each page of items
                Console.WriteLine("A page of results:");
                foreach (UptimeCheckConfig 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 <UptimeCheckConfig> 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 (UptimeCheckConfig item in singlePage)
            {
                Console.WriteLine(item);
            }
            // Store the pageToken, for when the next page is required.
            string nextPageToken = singlePage.NextPageToken;
            // End snippet
        }
예제 #23
0
        // [END monitoring_uptime_check_list_ips]

        // [START monitoring_uptime_check_update]
        public static object UpdateUptimeCheck(string configName,
                                               string newHttpPath, string newDisplayName)
        {
            var client    = UptimeCheckServiceClient.Create();
            var config    = client.GetUptimeCheckConfig(configName);
            var fieldMask = new FieldMask();

            if (newDisplayName != null)
            {
                config.DisplayName = newDisplayName;
                fieldMask.Paths.Add("display_name");
            }
            if (newHttpPath != null)
            {
                config.HttpCheck.Path = newHttpPath;
                fieldMask.Paths.Add("http_check.path");
            }
            client.UpdateUptimeCheckConfig(config);
            return(0);
        }