I have a Discord channel. I want Google Cloud Monitoring to send notifications to this channel via webhook.
Help me please T.T
I have a Discord channel. I want Google Cloud Monitoring to send notifications to this channel via webhook.
Help me please T.T
You can use the notification channel of webhook to send the notification to your discord.
https://cloud.google.com/monitoring/support/notification-options#webhooks
Option 2
If Stackdriver not sending the webhook directly you can simply leverage the pub/sub with a cloud function that would be an easy option and cost-efficient.
Cloud monitoring alert will push the payload to pub/sub and write a simple cloud function which will consume the pub/sub's payload and send webhook to discord.
So flow will be something like : Stackdriver monitoring > Pub/Sub > CloudFunction (webhook hit to discord) > Discord
Cloud function code
const fetch = require('node-fetch');
exports.helloPubSub = (message, context) => {
const name = message.data
? Buffer.from(message.data, 'base64').toString()
: 'World';
console.log(`Hello, ${name}!`);
var URL = "Discord URL";
fetch(URL, {
'method': 'POST',
'body': <DARA>,
headers: data.getHeaders()
})
.then(res=> console.log(res))
.catch(err => console.error(err));
};
I just tried.
I entered a webhook url. Then clicked test connection button. It's not working: nothing hasn't recieved.
Also checked with postman with a positive result on a discord channel.
and finally found the solution in comments here: