const https = require('https'); const url = require('url'); const slackWebhookURL = 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX'; // CHANGE ME PLZ! exports.gceAudit = (event, callback) => { const msg = JSON.parse(Buffer.from(event.data.data, 'base64').toString()); const slackRequest = https.request({ hostname: url.parse(slackWebhookURL).hostname, method: 'POST', path: url.parse(slackWebhookURL).path, headers: { 'Content-Type': 'application/json', } }); slackRequest.write(JSON.stringify({ 'text': `*Project :* ${msg.resource.labels.project_id} *Zone :* ${msg.resource.labels.zone} *Name :* ${msg.protoPayload.resourceName.split('/').pop()} *Method :* ${msg.protoPayload.methodName.split('.').pop()} *Status :* ${msg.operation.first ? 'Started' : 'Finished'}`, 'mrkdwn': true })); slackRequest.end(); callback(); };