/** * * * <pre> * A short name or phrase used to identify the policy in dashboards, * notifications, and incidents. To avoid confusion, don't use the same * display name for multiple policies in the same project. The name is * limited to 512 Unicode characters. * </pre> * * <code>string display_name = 2;</code> */ public Builder clearDisplayName() { displayName_ = getDefaultInstance().getDisplayName(); onChanged(); return this; } /**
onChanged(); if (!other.getDisplayName().isEmpty()) { displayName_ = other.displayName_; onChanged();
hash = (53 * hash) + getName().hashCode(); hash = (37 * hash) + DISPLAY_NAME_FIELD_NUMBER; hash = (53 * hash) + getDisplayName().hashCode(); if (hasDocumentation()) { hash = (37 * hash) + DOCUMENTATION_FIELD_NUMBER;
result = result && getDisplayName().equals(other.getDisplayName()); result = result && (hasDocumentation() == other.hasDocumentation()); if (hasDocumentation()) {
private static void listAlertPolicies(String projectId) throws IOException { try (AlertPolicyServiceClient client = AlertPolicyServiceClient.create()) { ListAlertPoliciesPagedResponse response = client.listAlertPolicies(ProjectName.of(projectId)); System.out.println("Alert Policies:"); for (AlertPolicy policy : response.iterateAll()) { System.out.println( String.format("\nPolicy %s\nalert-id: %s", policy.getDisplayName(), policy.getName())); int channels = policy.getNotificationChannelsCount(); if (channels > 0) { System.out.println("notification-channels:"); for (int i = 0; i < channels; i++) { System.out.println("\t" + policy.getNotificationChannels(i)); } } if (policy.hasDocumentation() && policy.getDocumentation().getContent() != null) { System.out.println(policy.getDocumentation().getContent()); } } } } // [END monitoring_alert_list_policies]
private static void enablePolicies(String projectId, String filter, boolean enable) throws IOException { try (AlertPolicyServiceClient client = AlertPolicyServiceClient.create()) { ListAlertPoliciesPagedResponse response = client .listAlertPolicies(ListAlertPoliciesRequest.newBuilder() .setName(ProjectName.of(projectId).toString()) .setFilter(filter) .build()); for (AlertPolicy policy : response.iterateAll()) { if (policy.getEnabled().getValue() == enable) { System.out.println(String.format( "Policy %s is already %b.", policy.getName(), enable ? "enabled" : "disabled")); continue; } AlertPolicy updatedPolicy = AlertPolicy .newBuilder() .setName(policy.getName()) .setEnabled(BoolValue.newBuilder().setValue(enable)) .build(); AlertPolicy result = client.updateAlertPolicy( FieldMask.newBuilder().addPaths("enabled").build(), updatedPolicy); System.out.println(String.format( "%s %s", result.getDisplayName(), result.getEnabled().getValue() ? "enabled" : "disabled")); } } } // [END monitoring_alert_enable_policies]