@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
result = result && getName().equals(other.getName()); result = result && getDisplayName().equals(other.getDisplayName()); result = result && (hasDocumentation() == other.hasDocumentation()); if (hasDocumentation()) { result = result && getDocumentation().equals(other.getDocumentation()); result = result && internalGetUserLabels().equals(other.internalGetUserLabels()); result = result && getConditionsList().equals(other.getConditionsList()); result = result && combiner_ == other.combiner_; result = result && (hasEnabled() == other.hasEnabled()); if (hasEnabled()) { result = result && getEnabled().equals(other.getEnabled()); result = result && getNotificationChannelsList().equals(other.getNotificationChannelsList()); result = result && (hasCreationRecord() == other.hasCreationRecord()); if (hasCreationRecord()) { result = result && getCreationRecord().equals(other.getCreationRecord()); result = result && (hasMutationRecord() == other.hasMutationRecord()); if (hasMutationRecord()) { result = result && getMutationRecord().equals(other.getMutationRecord());
@java.lang.Override public com.google.monitoring.v3.AlertPolicy getDefaultInstanceForType() { return com.google.monitoring.v3.AlertPolicy.getDefaultInstance(); }
/** * * * <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; } /**
/** * * * <pre> * Required if the policy exists. The resource name for this policy. The * syntax is: * projects/[PROJECT_ID]/alertPolicies/[ALERT_POLICY_ID] * `[ALERT_POLICY_ID]` is assigned by Stackdriver Monitoring when the policy * is created. When calling the * [alertPolicies.create][google.monitoring.v3.AlertPolicyService.CreateAlertPolicy] * method, do not include the `name` field in the alerting policy passed as * part of the request. * </pre> * * <code>string name = 1;</code> */ public Builder clearName() { name_ = getDefaultInstance().getName(); onChanged(); return this; } /**
public Builder mergeFrom(com.google.monitoring.v3.AlertPolicy other) { if (other == com.google.monitoring.v3.AlertPolicy.getDefaultInstance()) return this; if (!other.getName().isEmpty()) { name_ = other.name_; onChanged(); if (!other.getDisplayName().isEmpty()) { displayName_ = other.displayName_; onChanged(); if (other.hasDocumentation()) { mergeDocumentation(other.getDocumentation()); setCombinerValue(other.getCombinerValue()); if (other.hasEnabled()) { mergeEnabled(other.getEnabled()); if (other.hasCreationRecord()) { mergeCreationRecord(other.getCreationRecord()); if (other.hasMutationRecord()) { mergeMutationRecord(other.getMutationRecord());
if (!getNameBytes().isEmpty()) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(1, name_); if (!getDisplayNameBytes().isEmpty()) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, displayName_); size += com.google.protobuf.CodedOutputStream.computeMessageSize(10, getCreationRecord()); size += com.google.protobuf.CodedOutputStream.computeMessageSize(11, getMutationRecord()); size += com.google.protobuf.CodedOutputStream.computeMessageSize(13, getDocumentation()); dataSize += computeStringSizeNoTag(notificationChannels_.getRaw(i)); size += 1 * getNotificationChannelsList().size(); internalGetUserLabels().getMap().entrySet()) { com.google.protobuf.MapEntry<java.lang.String, java.lang.String> userLabels__ = UserLabelsDefaultEntryHolder.defaultEntry size += com.google.protobuf.CodedOutputStream.computeMessageSize(17, getEnabled());
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]
@java.lang.Override public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException { if (!getNameBytes().isEmpty()) { com.google.protobuf.GeneratedMessageV3.writeString(output, 1, name_); if (!getDisplayNameBytes().isEmpty()) { com.google.protobuf.GeneratedMessageV3.writeString(output, 2, displayName_); output.writeMessage(10, getCreationRecord()); output.writeMessage(11, getMutationRecord()); output.writeMessage(13, getDocumentation()); output, internalGetUserLabels(), UserLabelsDefaultEntryHolder.defaultEntry, 16); if (enabled_ != null) { output.writeMessage(17, getEnabled());
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]
private static List<AlertPolicy> reviseRestoredPolicies( AlertPolicy[] policies, boolean isSameProject, Map<String, String> restoredChannelIds) { List<AlertPolicy> newPolicies = Lists.newArrayListWithCapacity(policies.length); for (AlertPolicy policy : policies) { AlertPolicy.Builder policyBuilder = policy .toBuilder() .clearNotificationChannels() .clearMutationRecord() .clearCreationRecord(); // Update restored notification channel names. for (String channelName : policy.getNotificationChannelsList()) { String newChannelName = restoredChannelIds.get(channelName); if (!Strings.isNullOrEmpty(newChannelName)) { policyBuilder.addNotificationChannels(newChannelName); } } if (!isSameProject) { policyBuilder.clearName(); policyBuilder.clearConditions(); for (AlertPolicy.Condition condition : policy.getConditionsList()) { policyBuilder.addConditions(condition.toBuilder().clearName()); } } newPolicies.add(policyBuilder.build()); } return newPolicies; }
private static void replaceChannels(String projectId, String alertPolicyId, String[] channelIds) throws IOException { AlertPolicy.Builder policyBuilder = AlertPolicy .newBuilder() .setName(AlertPolicyName.of(projectId, alertPolicyId).toString()); for (String channelId : channelIds) { policyBuilder.addNotificationChannels( NotificationChannelName.of(projectId, channelId).toString()); } try (AlertPolicyServiceClient client = AlertPolicyServiceClient.create()) { AlertPolicy result = client.updateAlertPolicy( FieldMask.newBuilder().addPaths("notification_channels").build(), policyBuilder.build()); System.out.println(String.format("Updated %s", result.getName())); } } // [END monitoring_alert_replace_channels]
private static void restoreRevisedPolicies( String projectId, boolean isSameProject, List<AlertPolicy> policies) throws IOException { try (AlertPolicyServiceClient client = AlertPolicyServiceClient.create()) { for (AlertPolicy policy : policies) { if (!isSameProject) { policy = client.createAlertPolicy(ProjectName.of(projectId), policy); } else { try { client.updateAlertPolicy(null, policy); } catch (Exception e) { policy = client.createAlertPolicy( ProjectName.of(projectId), policy.toBuilder().clearName().build()); } } System.out.println(String.format("Restored %s", policy.getName())); } } } // [END monitoring_alert_create_policy]
/** * * * <pre> * Documentation that is included with notifications and incidents related to * this policy. Best practice is for the documentation to include information * to help responders understand, mitigate, escalate, and correct the * underlying problems detected by the alerting policy. Notification channels * that have limited capacity might not show this documentation. * </pre> * * <code>.google.monitoring.v3.AlertPolicy.Documentation documentation = 13;</code> */ public com.google.monitoring.v3.AlertPolicy.DocumentationOrBuilder getDocumentationOrBuilder() { return getDocumentation(); }
/** * * * <pre> * Whether or not the policy is enabled. On write, the default interpretation * if unset is that the policy is enabled. On read, clients should not make * any assumption about the state if it has not been populated. The * field should always be populated on List and Get operations, unless * a field projection has been specified that strips it out. * </pre> * * <code>.google.protobuf.BoolValue enabled = 17;</code> */ public com.google.protobuf.BoolValueOrBuilder getEnabledOrBuilder() { return getEnabled(); }
hash = (19 * hash) + getDescriptor().hashCode(); hash = (37 * hash) + NAME_FIELD_NUMBER; 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; hash = (53 * hash) + getDocumentation().hashCode(); if (!internalGetUserLabels().getMap().isEmpty()) { hash = (37 * hash) + USER_LABELS_FIELD_NUMBER; hash = (53 * hash) + internalGetUserLabels().hashCode(); if (getConditionsCount() > 0) { hash = (37 * hash) + CONDITIONS_FIELD_NUMBER; hash = (53 * hash) + getConditionsList().hashCode(); if (hasEnabled()) { hash = (37 * hash) + ENABLED_FIELD_NUMBER; hash = (53 * hash) + getEnabled().hashCode(); if (getNotificationChannelsCount() > 0) { hash = (37 * hash) + NOTIFICATION_CHANNELS_FIELD_NUMBER; hash = (53 * hash) + getNotificationChannelsList().hashCode(); if (hasCreationRecord()) { hash = (37 * hash) + CREATION_RECORD_FIELD_NUMBER; hash = (53 * hash) + getCreationRecord().hashCode();
/** * * * <pre> * The requested alerting policy. You should omit the `name` field in this * policy. The name will be returned in the new policy, including * a new [ALERT_POLICY_ID] value. * </pre> * * <code>.google.monitoring.v3.AlertPolicy alert_policy = 2;</code> */ public Builder mergeAlertPolicy(com.google.monitoring.v3.AlertPolicy value) { if (alertPolicyBuilder_ == null) { if (alertPolicy_ != null) { alertPolicy_ = com.google.monitoring.v3.AlertPolicy.newBuilder(alertPolicy_) .mergeFrom(value) .buildPartial(); } else { alertPolicy_ = value; } onChanged(); } else { alertPolicyBuilder_.mergeFrom(value); } return this; } /**
/** * * * <pre> * The requested alerting policy. You should omit the `name` field in this * policy. The name will be returned in the new policy, including * a new [ALERT_POLICY_ID] value. * </pre> * * <code>.google.monitoring.v3.AlertPolicy alert_policy = 2;</code> */ public com.google.monitoring.v3.AlertPolicy getAlertPolicy() { return alertPolicy_ == null ? com.google.monitoring.v3.AlertPolicy.getDefaultInstance() : alertPolicy_; } /**
/** * * * <pre> * Required. The updated alerting policy or the updated values for the * fields listed in `update_mask`. * If `update_mask` is not empty, any fields in this policy that are * not in `update_mask` are ignored. * </pre> * * <code>.google.monitoring.v3.AlertPolicy alert_policy = 3;</code> */ public Builder mergeAlertPolicy(com.google.monitoring.v3.AlertPolicy value) { if (alertPolicyBuilder_ == null) { if (alertPolicy_ != null) { alertPolicy_ = com.google.monitoring.v3.AlertPolicy.newBuilder(alertPolicy_) .mergeFrom(value) .buildPartial(); } else { alertPolicy_ = value; } onChanged(); } else { alertPolicyBuilder_.mergeFrom(value); } return this; } /**
/** * * * <pre> * Required. The updated alerting policy or the updated values for the * fields listed in `update_mask`. * If `update_mask` is not empty, any fields in this policy that are * not in `update_mask` are ignored. * </pre> * * <code>.google.monitoring.v3.AlertPolicy alert_policy = 3;</code> */ public com.google.monitoring.v3.AlertPolicy getAlertPolicy() { return alertPolicy_ == null ? com.google.monitoring.v3.AlertPolicy.getDefaultInstance() : alertPolicy_; } /**