Skip to content

matheusmartns/gcp-alerts-on-teams

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gcp-alerts-on-teams

Cloud Function to send GCP alerts to MS Teams

image

image

Medium Article: https://medium.com/@mathmartns/gcp-alerts-on-microsoft-teams-309f7bd8bd0a

Getting Started

Prerequisites

  • Webhook for the MS Teams channel, for that, visit this well-covered guide by Microsoft;
  • Pub/Sub Topic and subscription to receive the Alert;
  • The Policy that will trigger the alert;
  • Create the Cloud Function using the provided files, you NEED to create a runtime environment variable named webhookURL that contains the webhook URL that the MS Teams generated for you (or you can hardcode it, use a variable inside your code, here it's your choice).

Files

main.py

As the name says, this is the main file of our function, Our main function receives event and context, both come from the pub/sub and are mandatory, but the info that we need is inside the event on its data section.

json_operations.py

Here is where the magic happens, we get the required info from the Pub/Sub original Alert and insert them on the fields of the JSON alert that will be sent to the MS Teams.

A lot of transformation is going on there and I won’t be able to cover it here, but the strategy is basically the same, We assign to a variable the value we want from the original alert message (if necessary perform modifications, for example, the Timestamp we need to adjust it to a human-readable format) and “paste” it on the respective field of the new alert JSON template.

template.json

This is the template file that will be filled with the information that will come from the Pub/Sub and this format is readable by the MS Teams, you can find more about it here.

About

Cloud Function to send GCP alerts to MS Teams

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages