Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Do i need a cloud function to send fail logs of Dataform or Workflow to MS Teams?

Hi there,

I'm a newbie in GCP. I'm trying to send log notification to MS Teams via Google alert Webhooks notification channel. The Email channel is working but not Webhooks channel. Am i missing something? Maybe permissions?? I have the following settings:

- a log sink to collect the fail logs in Dataform & Workflows
- pub/sub topic&subscription
- alert: Email channel+ pub/sub channel + Webhooks channel (MS Teams); log query: resource.type="dataform.googleapis.com/Repository"
severity=ERROR
- Workflows, Dataform
- permission: Pub/Sub Publisher to monitoring service account xxxx@gcp-sa-monitoring-notification.iam.gserviceaccount.com

Not sure any other permissions should be given and to which service accounts?
- Cloud function:
created in the console. trigger with pub/sub subscription. Runtime NodeJS 18. pass in the WEBHOOK_URL in Runtime environment variables

const request = require('request');
const webhookURL = process.env.WEBHOOK_URL;
exports.subscriber = (pubSubEvent, context) => {


const age = Date.now() - Date.parse(context.timestamp);
if (age > 60*60*1000) {
return;
}

let body = Buffer.from(pubSubEvent.data, 'base64').toString('utf-8');
const options = {

url: webhookURL,
headers: {
'Content-Type': 'application/json; charset=utf-8'
//'Authorization': 'Basic ' + Buffer.from('username:password').toString('base64')
},
body: body,
};

req = request.post(options, (err, res, body) => {
if (err) {
console.error(err);
throw new Error(err);
}
if (res.statusCode != 200) {
console.error(body);
throw new Error(res.StatusMessage);
}
});
};

In the logs, it shows

Summary or Text is required.

and

Exception from a finished function: Error

I'm not sure what these mean?
Thanks in advance

Or any better solution? thanks in advance

Solved Solved
0 3 1,073
1 ACCEPTED SOLUTION

Hi @sysph,

You can check this helpful link, a Google Cloud Function in Go to transform / proxy Google Cloud Platform (GCP) Monitoring pubsub incident notifications to Microsoft Teams.

Make sure the user invoking the function has the required authentication permission. For more information, see Authenticating function to function calls and Enabling access to a function.

Here's another reference from stack overflow which can help with what you want to accomplish.
Hope this helps. You can also get in touch with Google Cloud Support if the above didn't work or if you need further help.

 

View solution in original post

3 REPLIES 3

Hi @sysph,

You can check this helpful link, a Google Cloud Function in Go to transform / proxy Google Cloud Platform (GCP) Monitoring pubsub incident notifications to Microsoft Teams.

Make sure the user invoking the function has the required authentication permission. For more information, see Authenticating function to function calls and Enabling access to a function.

Here's another reference from stack overflow which can help with what you want to accomplish.
Hope this helps. You can also get in touch with Google Cloud Support if the above didn't work or if you need further help.

 

Hi @anjelisa 

Thank you for replying.  I'll give it a try.  i'm not familiar with GCP and GP.  So far, i've cloned the git locally but not sure how to create cloud function (1 gen or 2 gen)?  I think giving the correct permissions are tricky too.  Which permissions i should give to which service accounts?  Fingers crossed!  I'm appreciated

It's working now! Finally! Thank you so much.