-
Notifications
You must be signed in to change notification settings - Fork 3
/
WebexTeams_index.js
27 lines (23 loc) · 1.2 KB
/
WebexTeams_index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const request = require(`request`);
// Translate JSON message into Text
exports.notifyWebexTeams = async (pubsubEvent, context) => {
const pubsubData = Buffer.from(pubsubEvent.data, 'base64').toString();
const alert = JSON.parse(pubsubData);
// Check to see if the budget has been exceeded. (without this, budget updates will be sent every 30 minutes)
if (alert.costAmount >= alert.budgetAmount) {
// Post message to the room
request({
uri: "<insert webhook ulr>",
method: "POST",
json: {
markdown: "**GCP Billing Alert**: One of your GCP Projects has exceeded its monthly budget. \n**- Budget Exceeded:** " + alert.budgetDisplayName + " \n**- Budget Start Date:** " + alert.costIntervalStart + " \n**- Budget Amount:** " + alert.budgetAmount + " \n**- Alert Threshold:** " + alert.alertThresholdExceeded + " \n**- Current Spend:** " + alert.costAmount + " \n**- Currency Type:** " + alert.currencyCode + " \n**[OPEN THE GCP BILLING CONSOLE](http://console.cloud.google.com/billing)**"
},
}, function(error, response, body){
if(error) {
console.log(error);
} else {
console.log(response.statusCode, body);
}
});
}
};