diff --git a/monitoring/snippets/alerts.js b/monitoring/snippets/alerts.js index fb6161def7..7af4d098b9 100644 --- a/monitoring/snippets/alerts.js +++ b/monitoring/snippets/alerts.js @@ -83,7 +83,9 @@ async function restorePolicies(projectId) { // Restore each policy one at a time let policy = policies[index]; if (await doesAlertPolicyExist(policy.name)) { - policy = await client.updateAlertPolicy({alertPolicy: policy}); + policy = await client.updateAlertPolicy({ + alertPolicy: policy, + }); } else { // Clear away output-only fields delete policy.name; @@ -101,7 +103,9 @@ async function restorePolicies(projectId) { } async function doesAlertPolicyExist(name) { try { - const [policy] = await client.getAlertPolicy({name}); + const [policy] = await client.getAlertPolicy({ + name, + }); return policy ? true : false; } catch (err) { if (err && err.code === 5) { @@ -131,7 +135,10 @@ async function deleteChannels(projectId, filter) { // const projectId = 'YOUR_PROJECT_ID'; // const filter = 'A filter for selecting policies, e.g. description:"cloud"'; - const request = {name: client.projectPath(projectId), filter}; + const request = { + name: client.projectPath(projectId), + filter, + }; const channels = await client.listNotificationChannels(request); console.log(channels); for (const channel of channels[0]) { @@ -173,15 +180,19 @@ async function replaceChannels(projectId, alertPolicyId, channelIds) { // ]; const notificationChannels = channelIds.map(id => - notificationClient.notificationChannelPath(projectId, id) + notificationClient.projectNotificationChannelPath(projectId, id) ); for (const channel of notificationChannels) { const updateChannelRequest = { - updateMask: {paths: ['enabled']}, + updateMask: { + paths: ['enabled'], + }, notificationChannel: { name: channel, - enabled: {value: true}, + enabled: { + value: true, + }, }, }; try { @@ -190,7 +201,9 @@ async function replaceChannels(projectId, alertPolicyId, channelIds) { const createChannelRequest = { notificationChannel: { name: channel, - notificationChannel: {type: 'email'}, + notificationChannel: { + type: 'email', + }, }, }; const newChannel = await notificationClient.createNotificationChannel( @@ -201,9 +214,11 @@ async function replaceChannels(projectId, alertPolicyId, channelIds) { } const updateAlertPolicyRequest = { - updateMask: {paths: ['notification_channels']}, + updateMask: { + paths: ['notification_channels'], + }, alertPolicy: { - name: alertClient.alertPolicyPath(projectId, alertPolicyId), + name: alertClient.projectAlertPolicyPath(projectId, alertPolicyId), notificationChannels: notificationChannels, }, }; @@ -243,10 +258,14 @@ async function enablePolicies(projectId, enabled, filter) { policies .map(policy => { return { - updateMask: {paths: ['enabled']}, + updateMask: { + paths: ['enabled'], + }, alertPolicy: { name: policy.name, - enabled: {value: enabled}, + enabled: { + value: enabled, + }, }, }; }) diff --git a/monitoring/snippets/metrics.js b/monitoring/snippets/metrics.js index 732da5b718..62cc28ad47 100644 --- a/monitoring/snippets/metrics.js +++ b/monitoring/snippets/metrics.js @@ -110,7 +110,7 @@ async function getMetricDescriptor(projectId, metricId) { // const metricId = 'custom.googleapis.com/your/id'; const request = { - name: client.metricDescriptorPath(projectId, metricId), + name: client.projectMetricDescriptorPath(projectId, metricId), }; // Retrieves a metric descriptor @@ -143,7 +143,7 @@ async function deleteMetricDescriptor(projectId, metricId) { // const metricId = 'custom.googleapis.com/stores/daily_sales'; const request = { - name: client.metricDescriptorPath(projectId, metricId), + name: client.projectMetricDescriptorPath(projectId, metricId), }; // Deletes a metric descriptor @@ -432,7 +432,10 @@ async function getMonitoredResourceDescriptor(projectId, resourceType) { // const resourceType = 'some_resource_type, e.g. cloudsql_database'; const request = { - name: client.monitoredResourceDescriptorPath(projectId, resourceType), + name: client.projectMonitoredResourceDescriptorPath( + projectId, + resourceType + ), }; // Lists monitored resource descriptors diff --git a/monitoring/snippets/uptime.js b/monitoring/snippets/uptime.js index 3fc434972e..e4d19eb58c 100644 --- a/monitoring/snippets/uptime.js +++ b/monitoring/snippets/uptime.js @@ -44,11 +44,20 @@ async function createUptimeCheckConfig(projectId, hostname) { monitoredResource: { // See the Uptime Check docs for supported MonitoredResource types type: 'uptime_url', - labels: {host: hostname}, + labels: { + host: hostname, + }, + }, + httpCheck: { + path: '/', + port: 80, + }, + timeout: { + seconds: 10, + }, + period: { + seconds: 300, }, - httpCheck: {path: '/', port: 80}, - timeout: {seconds: 10}, - period: {seconds: 300}, }, }; @@ -154,7 +163,7 @@ async function getUptimeCheckConfig(projectId, uptimeCheckConfigId) { const request = { // i.e. name: 'projects/my-project-id/uptimeCheckConfigs/My-Uptime-Check - name: client.uptimeCheckConfigPath(projectId, uptimeCheckConfigId), + name: client.projectUptimeCheckConfigPath(projectId, uptimeCheckConfigId), }; console.log(`Retrieving ${request.name}`); @@ -197,7 +206,7 @@ async function deleteUptimeCheckConfig(projectId, uptimeCheckConfigId) { const request = { // i.e. name: 'projects/my-project-id/uptimeCheckConfigs/My-Uptime-Check - name: client.uptimeCheckConfigPath(projectId, uptimeCheckConfigId), + name: client.projectUptimeCheckConfigPath(projectId, uptimeCheckConfigId), }; console.log(`Deleting ${request.name}`); @@ -232,7 +241,7 @@ async function updateUptimeCheckConfigDisplayName( const request = { // i.e. name: 'projects/my-project-id/uptimeCheckConfigs/My-Uptime-Check - name: client.uptimeCheckConfigPath(projectId, uptimeCheckConfigId), + name: client.projectUptimeCheckConfigPath(projectId, uptimeCheckConfigId), }; console.log(`Updating ${request.name} to ${displayName}`); @@ -241,10 +250,14 @@ async function updateUptimeCheckConfigDisplayName( request.uptimeCheckConfig = { name: request.name, displayName: displayName, - httpCheck: {path: path}, + httpCheck: { + path: path, + }, }; - request.updateMask = {paths: ['display_name', 'http_check.path']}; + request.updateMask = { + paths: ['display_name', 'http_check.path'], + }; const [response] = await client.updateUptimeCheckConfig(request); console.log(`${response.name} config updated.`);