Search in sources :

Example 1 with NotificationChannelServiceClient

use of com.google.cloud.monitoring.v3.NotificationChannelServiceClient in project java-monitoring by googleapis.

the class DeleteNotificationChannelIT method setupClass.

@BeforeClass
public static void setupClass() throws IOException {
    try (NotificationChannelServiceClient client = NotificationChannelServiceClient.create()) {
        String projectId = getProjectId();
        NOTIFICATION_CHANNEL = NotificationChannel.newBuilder().setType("email").putLabels("email_address", "java-docs-samples-testing@google.com").build();
        NotificationChannel channel = client.createNotificationChannel(ProjectName.of(projectId), NOTIFICATION_CHANNEL);
        NOTIFICATION_CHANNEL_NAME = channel.getName();
    }
}
Also used : NotificationChannel(com.google.monitoring.v3.NotificationChannel) NotificationChannelServiceClient(com.google.cloud.monitoring.v3.NotificationChannelServiceClient) BeforeClass(org.junit.BeforeClass)

Example 2 with NotificationChannelServiceClient

use of com.google.cloud.monitoring.v3.NotificationChannelServiceClient in project java-monitoring by googleapis.

the class DeleteNotificationChannel method deleteNotificationChannel.

/**
 * Demonstrates deleting a notification channel by name.
 *
 * @param channelName Name of the notification channel to delete.
 */
// [START monitoring_alert_delete_channel]
static void deleteNotificationChannel(String channelName) throws IOException {
    String projectId = System.getProperty("projectId");
    try (NotificationChannelServiceClient client = NotificationChannelServiceClient.create()) {
        NotificationChannelName name = NotificationChannelName.of(projectId, channelName);
        client.deleteNotificationChannel(channelName, false);
        System.out.println("Deleted notification channel " + channelName);
    }
}
Also used : NotificationChannelServiceClient(com.google.cloud.monitoring.v3.NotificationChannelServiceClient) NotificationChannelName(com.google.monitoring.v3.NotificationChannelName)

Example 3 with NotificationChannelServiceClient

use of com.google.cloud.monitoring.v3.NotificationChannelServiceClient in project java-docs-samples by GoogleCloudPlatform.

the class AlertSample method restoreNotificationChannels.

// [START monitoring_alert_create_channel]
// [START monitoring_alert_update_channel]
private static Map<String, String> restoreNotificationChannels(String projectId, List<NotificationChannel> channels, boolean isSameProject) throws IOException {
    Map<String, String> newChannelNames = Maps.newHashMap();
    try (NotificationChannelServiceClient client = NotificationChannelServiceClient.create()) {
        for (NotificationChannel channel : channels) {
            // Update channel name if project ID is different.
            boolean channelUpdated = false;
            if (isSameProject) {
                try {
                    NotificationChannel updatedChannel = client.updateNotificationChannel(NOTIFICATION_CHANNEL_UPDATE_MASK, channel);
                    newChannelNames.put(channel.getName(), updatedChannel.getName());
                    channelUpdated = true;
                } catch (Exception e) {
                    channelUpdated = false;
                }
            }
            if (!channelUpdated) {
                NotificationChannel newChannel = client.createNotificationChannel(ProjectName.of(projectId), channel.toBuilder().clearName().clearVerificationStatus().build());
                newChannelNames.put(channel.getName(), newChannel.getName());
            }
        }
    }
    return newChannelNames;
}
Also used : NotificationChannel(com.google.monitoring.v3.NotificationChannel) NotificationChannelServiceClient(com.google.cloud.monitoring.v3.NotificationChannelServiceClient) JsonSyntaxException(com.google.gson.JsonSyntaxException) IOException(java.io.IOException) ParseException(org.apache.commons.cli.ParseException)

Example 4 with NotificationChannelServiceClient

use of com.google.cloud.monitoring.v3.NotificationChannelServiceClient in project java-docs-samples by GoogleCloudPlatform.

the class DeleteNotificationChannel method deleteNotificationChannel.

/**
 * Demonstrates deleting a notification channel by name.
 *
 * @param channelName Name of the notification channel to delete.
 */
// [START monitoring_alert_delete_channel]
static void deleteNotificationChannel(String channelName) throws IOException {
    String projectId = System.getProperty("projectId");
    try (NotificationChannelServiceClient client = NotificationChannelServiceClient.create()) {
        NotificationChannelName name = NotificationChannelName.of(projectId, channelName);
        client.deleteNotificationChannel(channelName, false);
        System.out.println("Deleted notification channel " + channelName);
    }
}
Also used : NotificationChannelServiceClient(com.google.cloud.monitoring.v3.NotificationChannelServiceClient) NotificationChannelName(com.google.monitoring.v3.NotificationChannelName)

Example 5 with NotificationChannelServiceClient

use of com.google.cloud.monitoring.v3.NotificationChannelServiceClient in project java-docs-samples by GoogleCloudPlatform.

the class DeleteNotificationChannelIT method setupClass.

@BeforeClass
public static void setupClass() throws IOException {
    try (NotificationChannelServiceClient client = NotificationChannelServiceClient.create()) {
        String projectId = getProjectId();
        NOTIFICATION_CHANNEL = NotificationChannel.newBuilder().setType("email").putLabels("email_address", "java-docs-samples-testing@google.com").build();
        NotificationChannel channel = client.createNotificationChannel(ProjectName.of(projectId), NOTIFICATION_CHANNEL);
        NOTIFICATION_CHANNEL_NAME = channel.getName();
    }
}
Also used : NotificationChannel(com.google.monitoring.v3.NotificationChannel) NotificationChannelServiceClient(com.google.cloud.monitoring.v3.NotificationChannelServiceClient) BeforeClass(org.junit.BeforeClass)

Aggregations

NotificationChannelServiceClient (com.google.cloud.monitoring.v3.NotificationChannelServiceClient)6 NotificationChannel (com.google.monitoring.v3.NotificationChannel)4 NotificationChannelName (com.google.monitoring.v3.NotificationChannelName)2 BeforeClass (org.junit.BeforeClass)2 AlertPolicyServiceClient (com.google.cloud.monitoring.v3.AlertPolicyServiceClient)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 AlertPolicy (com.google.monitoring.v3.AlertPolicy)1 IOException (java.io.IOException)1 ParseException (org.apache.commons.cli.ParseException)1