// [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); }
// [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); }
/// <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 }
/// <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 }
// [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); }
// [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); }
/// <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 }
/// <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 }
/// <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 }
/// <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 }
/// <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 }
// [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 ListUptimeCheckConfigs</summary> public void ListUptimeCheckConfigs_RequestObject() { // Snippet: ListUptimeCheckConfigs(ListUptimeCheckConfigsRequest,CallSettings) // Create client UptimeCheckServiceClient uptimeCheckServiceClient = UptimeCheckServiceClient.Create(); // Initialize request argument(s) ListUptimeCheckConfigsRequest request = new ListUptimeCheckConfigsRequest { Parent = new ProjectName("[PROJECT]").ToString(), }; // Make the request PagedEnumerable <ListUptimeCheckConfigsResponse, UptimeCheckConfig> response = uptimeCheckServiceClient.ListUptimeCheckConfigs(request); // 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 }
// [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); }