/// <summary>Snippet for ListAlertPoliciesAsync</summary> public async Task ListAlertPoliciesRequestObjectAsync() { // Snippet: ListAlertPoliciesAsync(ListAlertPoliciesRequest, CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = await AlertPolicyServiceClient.CreateAsync(); // Initialize request argument(s) ListAlertPoliciesRequest request = new ListAlertPoliciesRequest { ProjectName = ProjectName.FromProject("[PROJECT]"), Filter = "", OrderBy = "", }; // Make the request PagedAsyncEnumerable <ListAlertPoliciesResponse, AlertPolicy> response = alertPolicyServiceClient.ListAlertPoliciesAsync(request); // Iterate over all response items, lazily performing RPCs as required await response.ForEachAsync((AlertPolicy 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((ListAlertPoliciesResponse page) => { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (AlertPolicy item in page) { // Do something with each item 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 <AlertPolicy> 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 (AlertPolicy item in singlePage) { // Do something with each item Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
/// <summary>Snippet for ListAlertPolicies</summary> public void ListAlertPolicies_RequestObject() { // Snippet: ListAlertPolicies(ListAlertPoliciesRequest,CallSettings) // Create client AlertPolicyServiceClient alertPolicyServiceClient = AlertPolicyServiceClient.Create(); // Initialize request argument(s) ListAlertPoliciesRequest request = new ListAlertPoliciesRequest { ProjectName = new ProjectName("[PROJECT]"), }; // Make the request PagedEnumerable <ListAlertPoliciesResponse, AlertPolicy> response = alertPolicyServiceClient.ListAlertPolicies(request); // Iterate over all response items, lazily performing RPCs as required foreach (AlertPolicy 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 (ListAlertPoliciesResponse page in response.AsRawResponses()) { // Do something with each page of items Console.WriteLine("A page of results:"); foreach (AlertPolicy 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 <AlertPolicy> 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 (AlertPolicy item in singlePage) { Console.WriteLine(item); } // Store the pageToken, for when the next page is required. string nextPageToken = singlePage.NextPageToken; // End snippet }
protected override void ProcessRecord() { base.ProcessRecord(); ListAlertPoliciesRequest request; try { request = new ListAlertPoliciesRequest { CompartmentId = CompartmentId, AlertPolicyId = AlertPolicyId, Type = Type, IsUserDefined = IsUserDefined, DisplayName = DisplayName, LifecycleState = LifecycleState, Limit = Limit, Page = Page, SortOrder = SortOrder, SortBy = SortBy, OpcRequestId = OpcRequestId, TimeCreatedGreaterThanOrEqualTo = TimeCreatedGreaterThanOrEqualTo, TimeCreatedLessThan = TimeCreatedLessThan, CompartmentIdInSubtree = CompartmentIdInSubtree, AccessLevel = AccessLevel }; IEnumerable <ListAlertPoliciesResponse> responses = GetRequestDelegate().Invoke(request); foreach (var item in responses) { response = item; WriteOutput(response, response.AlertPolicyCollection, true); } if (!ParameterSetName.Equals(AllPageSet) && !ParameterSetName.Equals(LimitSet) && response.OpcNextPage != null) { WriteWarning("This operation supports pagination and not all resources were returned. Re-run using the -All option to auto paginate and list all resources."); } FinishProcessing(response); } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
// [END monitoring_alert_replace_channels] // [START monitoring_alert_disable_policies] // [START monitoring_alert_enable_policies] static object EnablePolicies(string projectId, string filter, bool enable) { var client = AlertPolicyServiceClient.Create(); var request = new ListAlertPoliciesRequest() { ProjectName = new ProjectName(projectId), Filter = filter }; var response = client.ListAlertPolicies(request); int result = 0; foreach (AlertPolicy policy in response) { try { if (policy.Enabled == enable) { Console.WriteLine("Policy {0} is already {1}.", policy.Name, enable ? "enabled" : "disabled"); continue; } policy.Enabled = enable; var fieldMask = new FieldMask { Paths = { "enabled" } }; client.UpdateAlertPolicy(fieldMask, policy); Console.WriteLine("{0} {1}.", enable ? "Enabled" : "Disabled", policy.Name); } catch (Grpc.Core.RpcException e) when(e.Status.StatusCode == StatusCode.InvalidArgument) { Console.WriteLine(e.Message); result -= 1; } } // Return a negative count of how many enable operations failed. return(result); }