Skip to content

future-architect/gbilling2slack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gbilling2slack

Slack notifications tools for Google Cloud Platform Billing.

Overview

This package notifies gcp billing to your slack channel.

  • Cloud Scheduler sends message to Cloud Pub/Sub and Cloud Pub/Sub triggers Cloud Functions.
  • Cloud Functions gets billing from BigQuery table and sends it to your Slack channel.
  • You can see billing on Slack channel.

Requirements

Notify GCP Billing to Slack requires the following to run:

Variables

Notify GCP Billing to Slack requires only 3 variables to run:

# variables Note
1 TABLE_NAME Table name of billing on BigQuery
2 SLACK_API_TOKEN Slack api token
3 SLACK_CHANNEL Slack channel name

Usage

This package uses below services.

  • Google Cloud Billing(BigQuery)
  • Google Cloud Functions
  • Google Cloud Pub/Sub
  • Google Cloud Scheduler
  • Slack API

Steps

  1. Get Slack API Token
  2. Export your GCP billing to BigQuery (reference)
  3. Set Cloud Scheduler
gcloud beta scheduler jobs create pubsub notify-billing-to-slack --project <YOUR GCP PROJECT> \
  --schedule "55 23 * * *" \
  --topic topic-billing \
  --message-body="execute" \
  --time-zone "Asia/Tokyo" \
  --description "This job invokes cloud function via cloud pubsub and send GCP billing to slack"
  1. Deploy to Cloud Functions
gcloud functions deploy notifyBilling --project <YOUR GCP PROJECT> \
  --entry-point NotifyBilling \
  --trigger-resource topic-billing \
  --trigger-event google.pubsub.topic.publish \
  --runtime go111 \
  --set-env-vars TABLE_NAME=<billing table-name> \
  --set-env-vars SLACK_API_TOKEN=<slack-api-token> \
  --set-env-vars SLACK_CHANNEL=<slack-channel-name>
  1. Go to the Cloud Scheduler page and click the run now button of notify-billing-to-slack

Example

You can get below output on slack when it comes to the set time.

This automatically notify you of charges for all services charged on GCP.

example.png

License

This project is licensed under the Apache License 2.0 License - see the LICENSE file for details

Releases

No releases published

Packages

No packages published

Languages