Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function deleteChannels(projectId, filter) {
// [START monitoring_alert_delete_channel]
// [START monitoring_alert_list_channels]
// Imports the Google Cloud client library
const monitoring = require('@google-cloud/monitoring');
// Creates a client
const client = new monitoring.NotificationChannelServiceClient();
/**
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const filter = 'A filter for selecting policies, e.g. description:"cloud"';
const request = {name: client.projectPath(projectId), filter};
const channels = await client.listNotificationChannels(request);
console.log(channels);
for (const channel of channels[0]) {
console.log(`Deleting channel ${channel.displayName}`);
try {
await client.deleteNotificationChannel({
name: channel.name,
});
async function replaceChannels(projectId, alertPolicyId, channelIds) {
// [START monitoring_alert_replace_channels]
// [START monitoring_alert_enable_channel]
// [START monitoring_alert_update_channel]
// [START monitoring_alert_create_channel]
// Imports the Google Cloud client library
const monitoring = require('@google-cloud/monitoring');
// Creates clients
const alertClient = new monitoring.AlertPolicyServiceClient();
const notificationClient = new monitoring.NotificationChannelServiceClient();
/**
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = 'YOUR_PROJECT_ID';
// const alertPolicyId = '123456789012314';
// const channelIds = [
// 'channel-1',
// 'channel-2',
// 'channel-3',
// ];
const notificationChannels = channelIds.map(id =>
notificationClient.notificationChannelPath(projectId, id)
);