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();
}
}
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);
}
}
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;
}
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);
}
}
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();
}
}
Aggregations